Skip to content

Commit

Permalink
test: unit test for chained set/delete on MutableRequestCookiesAdapter
Browse files Browse the repository at this point in the history
  • Loading branch information
lubieowoce committed Oct 11, 2024
1 parent 11d33c7 commit 5ac1664
Showing 1 changed file with 48 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ import { RequestCookies } from '../cookies'
import {
ReadonlyRequestCookiesError,
RequestCookiesAdapter,
MutableRequestCookiesAdapter,
} from './request-cookies'

describe('RequestCookiesAdapter', () => {
Expand Down Expand Up @@ -52,3 +53,50 @@ describe('RequestCookiesAdapter', () => {
expect(sealed.get('bar')).toEqual(undefined)
})
})

describe('MutableRequestCookiesAdapter', () => {
it('supports chained set calls and preserves wrapping', () => {
const headers = new Headers({})
const underlyingCookies = new RequestCookies(headers)
const onUpdateCookies = jest.fn<void, [string[]]>()

const wrappedCookies = MutableRequestCookiesAdapter.wrap(
underlyingCookies,
onUpdateCookies
)

const returned = wrappedCookies.set('foo', '1').set('bar', '2')

expect(returned).toBe(wrappedCookies)
expect(onUpdateCookies).toHaveBeenCalledWith([
expect.stringContaining('foo=1'),
])
expect(onUpdateCookies).toHaveBeenCalledWith([
expect.stringContaining('foo=1'),
expect.stringContaining('bar=2'),
])
})

it('supports chained delete calls and preserves wrapping', () => {
const headers = new Headers({})
const underlyingCookies = new RequestCookies(headers)
underlyingCookies.set('foo', '1').set('bar', '2')

const onUpdateCookies = jest.fn<void, [string[]]>()
const wrappedCookies = MutableRequestCookiesAdapter.wrap(
underlyingCookies,
onUpdateCookies
)

const returned = wrappedCookies.delete('foo').delete('bar')

expect(returned).toBe(wrappedCookies)
expect(onUpdateCookies).toHaveBeenCalledWith([
expect.stringContaining('foo=;'),
])
expect(onUpdateCookies).toHaveBeenCalledWith([
expect.stringContaining('foo=;'),
expect.stringContaining('bar=;'),
])
})
})

0 comments on commit 5ac1664

Please sign in to comment.