forked from canada-ca/tracker
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathfind-me.test.js
More file actions
102 lines (91 loc) · 2.67 KB
/
find-me.test.js
File metadata and controls
102 lines (91 loc) · 2.67 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
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
import { ensure, dbNameFromFile } from 'arango-tools'
import { graphql, GraphQLSchema } from 'graphql'
import { toGlobalId } from 'graphql-relay'
import { databaseOptions } from '../../../../database-options'
import { userRequired } from '../../../auth'
import { createQuerySchema } from '../../../query'
import { createMutationSchema } from '../../../mutation'
import { loadAffiliationConnectionsByUserId } from '../../../affiliation/loaders'
import { loadUserByKey } from '../../loaders'
import { cleanseInput } from '../../../validators'
const { DB_PASS: rootPass, DB_URL: url } = process.env
describe('given the findMe query', () => {
let query, drop, truncate, schema, collections, user
beforeAll(async () => {
// Create GQL Schema
schema = new GraphQLSchema({
query: createQuerySchema(),
mutation: createMutationSchema(),
})
// Generate DB Items
;({ query, drop, truncate, collections } = await ensure({
type: 'database',
name: dbNameFromFile(__filename),
url,
rootPassword: rootPass,
options: databaseOptions({ rootPass }),
}))
})
let consoleOutput = []
const mockedInfo = (output) => consoleOutput.push(output)
const mockedWarn = (output) => consoleOutput.push(output)
const mockedError = (output) => consoleOutput.push(output)
beforeEach(async () => {
console.info = mockedInfo
console.warn = mockedWarn
console.error = mockedError
user = await collections.users.save({
userName: 'test.account@istio.actually.exists',
displayName: 'Test Account',
preferredLang: 'french',
tfaValidated: false,
emailValidated: false,
})
})
afterEach(async () => {
await truncate()
consoleOutput = []
})
afterAll(async () => {
await drop()
})
describe('users successfully performs query', () => {
it('will return specified user', async () => {
const response = await graphql(
schema,
`
query {
findMe {
id
}
}
`,
null,
{
auth: {
userRequired: userRequired({
userKey: user._key,
loadUserByKey: loadUserByKey({ query }),
}),
},
loaders: {
loadAffiliationConnectionsByUserId:
loadAffiliationConnectionsByUserId({
query,
userKey: user._key,
cleanseInput,
}),
},
},
)
const expectedResponse = {
data: {
findMe: {
id: toGlobalId('user', user._key),
},
},
}
expect(response).toEqual(expectedResponse)
})
})
})