-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathredisWrapper.test.js
More file actions
60 lines (52 loc) · 1.86 KB
/
redisWrapper.test.js
File metadata and controls
60 lines (52 loc) · 1.86 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
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
const { createRedisWrapper } = require('./redisWrapper')
describe('createRedisWrapper', () => {
test('Returns a wrapper for kth-node-redis@3', async () => {
const config = { data: 'my v3 config' }
const v3client = {
set: jest.fn(),
setAsync: jest.fn(),
}
const getClient = jest.fn(() => v3client)
const validRedisDependency = getClient
validRedisDependency.getClient = getClient
const result = await createRedisWrapper('apiName', validRedisDependency, config)
expect(getClient).toHaveBeenCalledWith('apiName', config)
expect(result).toEqual(
expect.objectContaining({
detectedVersion: 'kth-node-redis@3',
get: expect.any(Function),
set: expect.any(Function),
expire: expect.any(Function),
})
)
})
test('Returns a wrapper for kth-node-redis@4', async () => {
const config = { data: 'my v4 config' }
const v4client = {
set: jest.fn(),
}
const getClient = jest.fn(() => v4client)
const validRedisDependency = getClient
validRedisDependency.getClient = getClient
validRedisDependency.version = 'kth-node-redis-4'
const result = await createRedisWrapper('apiName', validRedisDependency, config)
expect(getClient).toHaveBeenCalledWith('apiName', config)
expect(result).toEqual(
expect.objectContaining({
detectedVersion: 'kth-node-redis@4',
get: expect.any(Function),
set: expect.any(Function),
expire: expect.any(Function),
})
)
})
test('throws error for library that dont have an exported "getClient" function', async () => {
const invalidRedisDependency = () => ({
set: jest.fn(),
setAsync: jest.fn(),
})
await expect(createRedisWrapper('apiName', invalidRedisDependency, {})).rejects.toThrow(
'@kth/api-call was configured with an unsupported Redis version'
)
})
})