-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindex.test.js
56 lines (50 loc) · 1.22 KB
/
index.test.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
jest.mock('redis', () => ({
createClient: jest.fn().mockImplementation(() => ({
on: jest.fn(),
})),
}))
describe(`Session`, () => {
afterAll(() => jest.resetAllMocks())
let createSession
beforeEach(() => {
jest.resetModules()
createSession = require('./index')
})
afterEach(() => {})
test('should not allow a session without secret', () => {
try {
const options = {
key: 'MY_REDIS',
}
const session = createSession(options)
expect(session).toBeUndefined()
} catch (err) {
expect(err).not.toBeUndefined()
}
})
test('should not allow a session without a redis key', () => {
try {
const options = {
sessionOptions: {
secret: '1234',
},
}
const session = createSession(options)
expect(session).toBeUndefined()
} catch (err) {
expect(err).not.toBeUndefined()
}
})
test('should return a session middleware', () => {
const options = {
key: 'MY_REDIS',
sessionOptions: {
secret: '1234',
},
useRedis: true,
}
const session = createSession(options)
expect(session).not.toBeUndefined()
expect(session.constructor.name).toBe('Function')
})
})