fix: name and expirationDate should be optional when setting cookie (#21454)
* fix: correctly set cookie date * fix: name is not required for setting cookie * test: clear cookie after each cookie test * test: should test session property * chore: style fixes
This commit is contained in:
parent
cbe1e3a1d0
commit
d5192853f9
3 changed files with 53 additions and 29 deletions
|
@ -58,6 +58,15 @@ describe('session module', () => {
|
|||
const value = '0'
|
||||
afterEach(closeAllWindows)
|
||||
|
||||
// Clear cookie of defaultSession after each test.
|
||||
afterEach(async () => {
|
||||
const { cookies } = session.defaultSession
|
||||
const cs = await cookies.get({ url })
|
||||
for (const c of cs) {
|
||||
await cookies.remove(url, c.name)
|
||||
}
|
||||
})
|
||||
|
||||
it('should get cookies', async () => {
|
||||
const server = http.createServer((req, res) => {
|
||||
res.setHeader('Set-Cookie', [`${name}=${value}`])
|
||||
|
@ -79,8 +88,32 @@ describe('session module', () => {
|
|||
const value = '1'
|
||||
|
||||
await cookies.set({ url, name, value, expirationDate: (+new Date()) / 1000 + 120 })
|
||||
const cs = await cookies.get({ url })
|
||||
expect(cs.some(c => c.name === name && c.value === value)).to.equal(true)
|
||||
const c = (await cookies.get({ url }))[0]
|
||||
expect(c.name).to.equal(name)
|
||||
expect(c.value).to.equal(value)
|
||||
expect(c.session).to.equal(false)
|
||||
})
|
||||
|
||||
it('sets session cookies', async () => {
|
||||
const { cookies } = session.defaultSession
|
||||
const name = '2'
|
||||
const value = '1'
|
||||
|
||||
await cookies.set({ url, name, value })
|
||||
const c = (await cookies.get({ url }))[0]
|
||||
expect(c.name).to.equal(name)
|
||||
expect(c.value).to.equal(value)
|
||||
expect(c.session).to.equal(true)
|
||||
})
|
||||
|
||||
it('sets cookies without name', async () => {
|
||||
const { cookies } = session.defaultSession
|
||||
const value = '3'
|
||||
|
||||
await cookies.set({ url, value })
|
||||
const c = (await cookies.get({ url }))[0]
|
||||
expect(c.name).to.be.empty()
|
||||
expect(c.value).to.equal(value)
|
||||
})
|
||||
|
||||
it('gets cookies without url', async () => {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue