-
Notifications
You must be signed in to change notification settings - Fork 1
/
functions-without-context.test.js
52 lines (43 loc) · 1.18 KB
/
functions-without-context.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
/* global expect, test */
const { createUser, updateUsername } = require('./functions-without-context')
const { prismaMock } = require('./singleton')
test('should create new user ', async () => {
const user = {
id: 1,
name: 'Rich',
email: '[email protected]',
acceptTermsAndConditions: true
}
prismaMock.user.create.mockResolvedValue(user)
await expect(createUser(user)).resolves.toEqual({
id: 1,
name: 'Rich',
email: '[email protected]',
acceptTermsAndConditions: true
})
})
test('should update a users name ', async () => {
const user = {
id: 1,
name: 'Rich Haines',
email: '[email protected]'
}
prismaMock.user.update.mockResolvedValue(user)
await expect(updateUsername(user)).resolves.toEqual({
id: 1,
name: 'Rich Haines',
email: '[email protected]'
})
})
test('should fail if user does not accept terms', async () => {
const user = {
id: 1,
name: 'Rich Haines',
email: '[email protected]',
acceptTermsAndConditions: false
}
prismaMock.user.create.mockRejectedValue(new Error('User must accept terms!'))
await expect(createUser(user)).resolves.toEqual(
new Error('User must accept terms!')
)
})