forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathuser-shared.test.js
More file actions
58 lines (49 loc) · 1.82 KB
/
user-shared.test.js
File metadata and controls
58 lines (49 loc) · 1.82 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
import { GraphQLNonNull, GraphQLID, GraphQLString } from 'graphql'
import { toGlobalId } from 'graphql-relay'
import { GraphQLEmailAddress } from 'graphql-scalars'
import { userSharedType } from '../index'
describe('given the user object', () => {
describe('testing the field definitions', () => {
it('has an id field', () => {
const demoType = userSharedType.getFields()
expect(demoType).toHaveProperty('id')
expect(demoType.id.type).toMatchObject(GraphQLNonNull(GraphQLID))
})
it('has a displayName field', () => {
const demoType = userSharedType.getFields()
expect(demoType).toHaveProperty('displayName')
expect(demoType.displayName.type).toMatchObject(GraphQLString)
})
it('has a userName field', () => {
const demoType = userSharedType.getFields()
expect(demoType).toHaveProperty('userName')
expect(demoType.userName.type).toMatchObject(GraphQLEmailAddress)
})
})
describe('testing the field resolvers', () => {
describe('testing the id resolver', () => {
it('returns the resolved field', () => {
const demoType = userSharedType.getFields()
expect(demoType.id.resolve({ id: '1' })).toEqual(
toGlobalId('user', '1'),
)
})
})
describe('testing the displayName field', () => {
it('returns the resolved value', () => {
const demoType = userSharedType.getFields()
expect(
demoType.displayName.resolve({ displayName: 'Display Name' }),
).toEqual('Display Name')
})
})
describe('testing the userName field', () => {
it('returns the resolved value', () => {
const demoType = userSharedType.getFields()
expect(
demoType.userName.resolve({ userName: 'test@email.gc.ca' }),
).toEqual('test@email.gc.ca')
})
})
})
})