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:
Cheng Zhao 2019-12-11 16:44:49 +09:00 committed by GitHub
parent cbe1e3a1d0
commit d5192853f9
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 53 additions and 29 deletions

View file

@ -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 () => {