forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathgenerate-jwt.test.js
More file actions
37 lines (30 loc) · 1.02 KB
/
generate-jwt.test.js
File metadata and controls
37 lines (30 loc) · 1.02 KB
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
import jwt from 'jsonwebtoken'
import { tokenize } from '../index'
const { AUTHENTICATED_KEY } = process.env
describe('tokenize()', () => {
describe('when passed an object of parameters', () => {
it('encodes them into the token', () => {
const token = tokenize({ parameters: { userKey: 1 } })
const decoded = jwt.verify(token, String(AUTHENTICATED_KEY))
expect(decoded.parameters.userKey).toEqual(1)
})
})
})
describe('tokenize()', () => {
describe('when no iat/exp parameters are passed', () => {
it('expires in 1 hour (3600 seconds) by default', () => {
const token = tokenize({ secret: 'foo' })
const decoded = jwt.verify(token, 'foo')
expect(decoded.exp - decoded.iat).toEqual(3600)
})
})
})
describe('tokenize()', () => {
describe('given no parameters', () => {
it('returns a valid encoded token', () => {
const token = tokenize({})
const decoded = jwt.verify(token, String(AUTHENTICATED_KEY))
expect(decoded.parameters).toEqual({})
})
})
})