11const { ArangoTools, dbNameFromFile } = require ( 'arango-tools' )
2- const bcrypt = require ( 'bcrypt' )
32const { graphql, GraphQLSchema, GraphQLError } = require ( 'graphql' )
43const { toGlobalId } = require ( 'graphql-relay' )
54const { setupI18n } = require ( '@lingui/core' )
@@ -10,25 +9,30 @@ const { makeMigrations } = require('../../../../migrations')
109const { createQuerySchema } = require ( '../..' )
1110const { createMutationSchema } = require ( '../../../mutations' )
1211const { cleanseInput } = require ( '../../../validators' )
13- const { tokenize } = require ( '../../../auth' )
12+ const { userRequired } = require ( '../../../auth' )
1413const {
1514 domainLoaderConnectionsByUserId,
16- userLoaderByUserName ,
15+ userLoaderByKey ,
1716} = require ( '../../../loaders' )
1817const { DB_PASS : rootPass , DB_URL : url } = process . env
1918
2019describe ( 'given findMyDomainsQuery' , ( ) => {
21- let query , drop , truncate , migrate , schema , collections , org , i18n
20+ let query , drop , truncate , migrate , schema , collections , org , i18n , user
2221
2322 beforeAll ( async ( ) => {
2423 // Create GQL Schema
2524 schema = new GraphQLSchema ( {
2625 query : createQuerySchema ( ) ,
2726 mutation : createMutationSchema ( ) ,
2827 } )
28+ // Generate DB Items
29+ ; ( { migrate } = await ArangoTools ( { rootPass, url } ) )
30+ ; ( { query, drop, truncate, collections } = await migrate (
31+ makeMigrations ( { databaseName : dbNameFromFile ( __filename ) , rootPass } ) ,
32+ ) )
2933 } )
3034
31- let consoleOutput = [ ]
35+ const consoleOutput = [ ]
3236 const mockedInfo = ( output ) => consoleOutput . push ( output )
3337 const mockedWarn = ( output ) => consoleOutput . push ( output )
3438 const mockedError = ( output ) => consoleOutput . push ( output )
@@ -37,49 +41,13 @@ describe('given findMyDomainsQuery', () => {
3741 console . info = mockedInfo
3842 console . warn = mockedWarn
3943 console . error = mockedError
40- // Generate DB Items
41- ; ( { migrate } = await ArangoTools ( { rootPass, url } ) )
42- ; ( { query, drop, truncate, collections } = await migrate (
43- makeMigrations ( { databaseName : dbNameFromFile ( __filename ) , rootPass } ) ,
44- ) )
45- await truncate ( )
46- await graphql (
47- schema ,
48- `
49- mutation {
50- signUp(
51- input: {
52- displayName: "Test Account"
53- userName: "test.account@istio.actually.exists"
54- password: "testpassword123"
55- confirmPassword: "testpassword123"
56- preferredLang: FRENCH
57- }
58- ) {
59- authResult {
60- user {
61- id
62- }
63- }
64- }
65- }
66- ` ,
67- null ,
68- {
69- query,
70- auth : {
71- bcrypt,
72- tokenize,
73- } ,
74- validators : {
75- cleanseInput,
76- } ,
77- loaders : {
78- userLoaderByUserName : userLoaderByUserName ( query ) ,
79- } ,
80- } ,
81- )
82- consoleOutput = [ ]
44+ consoleOutput . length = 0
45+
46+ user = await collections . users . save ( {
47+ displayName : 'Test Account' ,
48+ userName : 'test.account@istio.actually.exists' ,
49+ preferredLang : 'french' ,
50+ } )
8351
8452 org = await collections . organizations . save ( {
8553 orgDetails : {
@@ -108,18 +76,16 @@ describe('given findMyDomainsQuery', () => {
10876 } )
10977
11078 afterEach ( async ( ) => {
79+ await truncate ( )
80+ } )
81+
82+ afterAll ( async ( ) => {
11183 await drop ( )
11284 } )
11385
11486 describe ( 'given successful retrieval of domains' , ( ) => {
115- let user , domainOne , domainTwo
87+ let domainOne , domainTwo
11688 beforeEach ( async ( ) => {
117- const userCursor = await query `
118- FOR user IN users
119- FILTER user.userName == "test.account@istio.actually.exists"
120- RETURN user
121- `
122- user = await userCursor . next ( )
12389 await collections . affiliations . save ( {
12490 _from : org . _id ,
12591 _to : user . _id ,
@@ -158,26 +124,6 @@ describe('given findMyDomainsQuery', () => {
158124 _from : org . _id ,
159125 } )
160126 } )
161- afterEach ( async ( ) => {
162- await query `
163- LET userEdges = (FOR v, e IN 1..1 ANY ${ org . _id } affiliations RETURN { edgeKey: e._key, userKey: e._to })
164- LET removeUserEdges = (FOR userEdge IN userEdges REMOVE userEdge.edgeKey IN affiliations)
165- RETURN true
166- `
167- await query `
168- FOR affiliation IN affiliations
169- REMOVE affiliation IN affiliations
170- `
171- await query `
172- LET domainEdges = (FOR v, e IN 1..1 ANY ${ org . _id } claims RETURN { edgeKey: e._key, userKey: e._to })
173- LET removeDomainEdges = (FOR domainEdge IN domainEdges REMOVE domainEdge.edgeKey IN claims)
174- RETURN true
175- `
176- await query `
177- FOR claim IN claims
178- REMOVE claim IN claims
179- `
180- } )
181127 describe ( 'user queries for their domains' , ( ) => {
182128 it ( 'returns domains' , async ( ) => {
183129 const response = await graphql (
@@ -208,6 +154,13 @@ describe('given findMyDomainsQuery', () => {
208154 {
209155 i18n,
210156 userKey : user . _key ,
157+ auth : {
158+ userRequired : userRequired ( {
159+ i18n,
160+ userKey : user . _key ,
161+ userLoaderByKey : userLoaderByKey ( query , user . _key , i18n ) ,
162+ } ) ,
163+ } ,
211164 loaders : {
212165 domainLoaderConnectionsByUserId : domainLoaderConnectionsByUserId (
213166 query ,
@@ -305,6 +258,9 @@ describe('given findMyDomainsQuery', () => {
305258 {
306259 i18n,
307260 userKey : 1 ,
261+ auth : {
262+ userRequired : jest . fn ( ) ,
263+ } ,
308264 loaders : {
309265 domainLoaderConnectionsByUserId : mockedLoader ,
310266 } ,
@@ -370,6 +326,9 @@ describe('given findMyDomainsQuery', () => {
370326 {
371327 i18n,
372328 userKey : 1 ,
329+ auth : {
330+ userRequired : jest . fn ( ) ,
331+ } ,
373332 loaders : {
374333 domainLoaderConnectionsByUserId : mockedLoader ,
375334 } ,
0 commit comments