18
18
*/
19
19
20
20
import { faker } from "@faker-js/faker" ;
21
- import { graphql } from "graphql" ;
22
- import type { Driver , Session } from "neo4j-driver" ;
23
21
import { generate } from "randomstring" ;
24
- import { Neo4jGraphQL } from "../../../src/classes" ;
25
- import { cleanNodesUsingSession } from "../../utils/clean-nodes" ;
26
- import { UniqueType } from "../../utils/graphql-types" ;
27
- import Neo4jHelper from "../neo4j" ;
22
+ import type { UniqueType } from "../../utils/graphql-types" ;
23
+ import { TestHelper } from "../utils/tests-helper" ;
28
24
29
25
describe ( "union relationships" , ( ) => {
30
- let driver : Driver ;
31
- let neo4j : Neo4jHelper ;
32
- let session : Session ;
33
- let neoSchema : Neo4jGraphQL ;
26
+ let testHelper : TestHelper ;
34
27
35
28
let typeMovie : UniqueType ;
36
29
let typeSeries : UniqueType ;
37
30
let typeActor : UniqueType ;
38
31
39
- beforeAll ( async ( ) => {
40
- neo4j = new Neo4jHelper ( ) ;
41
- driver = await neo4j . getDriver ( ) ;
42
- } ) ;
43
-
44
32
beforeEach ( async ( ) => {
45
- typeMovie = new UniqueType ( "Movie" ) ;
46
- typeSeries = new UniqueType ( "Series ") ;
47
- typeActor = new UniqueType ( "Actor ") ;
48
- session = await neo4j . getSession ( ) ;
33
+ testHelper = new TestHelper ( ) ;
34
+ typeMovie = testHelper . createUniqueType ( "Movie ") ;
35
+ typeSeries = testHelper . createUniqueType ( "Series ") ;
36
+ typeActor = testHelper . createUniqueType ( "Actor" ) ;
49
37
50
38
const typeDefs = /* GraphQL */ `
51
39
type ${ typeMovie } {
@@ -71,17 +59,13 @@ describe("union relationships", () => {
71
59
}
72
60
` ;
73
61
74
- neoSchema = new Neo4jGraphQL ( {
62
+ await testHelper . initNeo4jGraphQL ( {
75
63
typeDefs,
76
64
} ) ;
77
65
} ) ;
78
66
79
67
afterEach ( async ( ) => {
80
- await cleanNodesUsingSession ( session , [ typeActor , typeMovie , typeSeries ] ) ;
81
- } ) ;
82
-
83
- afterAll ( async ( ) => {
84
- await driver . close ( ) ;
68
+ await testHelper . close ( ) ;
85
69
} ) ;
86
70
87
71
test ( "should read and return union relationship fields with union relationship filter SOME" , async ( ) => {
@@ -130,7 +114,7 @@ describe("union relationships", () => {
130
114
}
131
115
` ;
132
116
133
- await session . run (
117
+ await testHelper . runCypher (
134
118
`
135
119
CREATE (a:${ typeActor } { name: $actorName })
136
120
CREATE (a)-[:ACTED_IN { screenTime: $movieScreenTime }]->(:${ typeMovie } { title: $movieTitle, runtime:$movieRuntime })
@@ -151,10 +135,7 @@ describe("union relationships", () => {
151
135
}
152
136
) ;
153
137
154
- const gqlResult = await graphql ( {
155
- schema : await neoSchema . getSchema ( ) ,
156
- source : query ,
157
- contextValue : neo4j . getContextValues ( ) ,
138
+ const gqlResult = await testHelper . runGraphQL ( query , {
158
139
variableValues : { title : movieTitle2 } ,
159
140
} ) ;
160
141
@@ -217,7 +198,7 @@ describe("union relationships", () => {
217
198
}
218
199
` ;
219
200
220
- await session . run (
201
+ await testHelper . runCypher (
221
202
`
222
203
CREATE (a:${ typeActor } { name: $actorName })
223
204
CREATE (m:${ typeMovie } { title: $movieTitle, runtime:$movieRuntime })
@@ -238,10 +219,7 @@ describe("union relationships", () => {
238
219
}
239
220
) ;
240
221
241
- const gqlResult = await graphql ( {
242
- schema : await neoSchema . getSchema ( ) ,
243
- source : query ,
244
- contextValue : neo4j . getContextValues ( ) ,
222
+ const gqlResult = await testHelper . runGraphQL ( query , {
245
223
variableValues : { title : movieTitle } ,
246
224
} ) ;
247
225
@@ -317,7 +295,7 @@ describe("union relationships", () => {
317
295
}
318
296
` ;
319
297
320
- await session . run (
298
+ await testHelper . runCypher (
321
299
`
322
300
CREATE (a:${ typeActor } { name: $actorName })
323
301
CREATE (m:${ typeMovie } { title: $movieTitle, runtime:$movieRuntime })
@@ -339,10 +317,7 @@ describe("union relationships", () => {
339
317
}
340
318
) ;
341
319
342
- const gqlResult = await graphql ( {
343
- schema : await neoSchema . getSchema ( ) ,
344
- source : query ,
345
- contextValue : neo4j . getContextValues ( ) ,
320
+ const gqlResult = await testHelper . runGraphQL ( query , {
346
321
variableValues : { title : movieTitle } ,
347
322
} ) ;
348
323
@@ -409,7 +384,7 @@ describe("union relationships", () => {
409
384
}
410
385
` ;
411
386
412
- await session . run (
387
+ await testHelper . runCypher (
413
388
`
414
389
CREATE (a:${ typeActor } { name: $actorName })
415
390
CREATE (m:${ typeMovie } { title: $movieTitle, runtime:$movieRuntime })
@@ -430,10 +405,7 @@ describe("union relationships", () => {
430
405
}
431
406
) ;
432
407
433
- const gqlResult = await graphql ( {
434
- schema : await neoSchema . getSchema ( ) ,
435
- source : query ,
436
- contextValue : neo4j . getContextValues ( ) ,
408
+ const gqlResult = await testHelper . runGraphQL ( query , {
437
409
variableValues : { title : movieTitle } ,
438
410
} ) ;
439
411
@@ -490,7 +462,7 @@ describe("union relationships", () => {
490
462
}
491
463
` ;
492
464
493
- await session . run (
465
+ await testHelper . runCypher (
494
466
`
495
467
CREATE (a:${ typeActor } { name: $actorName })
496
468
CREATE (m:${ typeMovie } { title: $movieTitle, runtime:$movieRuntime })
@@ -513,10 +485,7 @@ describe("union relationships", () => {
513
485
}
514
486
) ;
515
487
516
- const gqlResult = await graphql ( {
517
- schema : await neoSchema . getSchema ( ) ,
518
- source : query ,
519
- contextValue : neo4j . getContextValues ( ) ,
488
+ const gqlResult = await testHelper . runGraphQL ( query , {
520
489
variableValues : { title : movieTitle2 } ,
521
490
} ) ;
522
491
@@ -587,7 +556,7 @@ describe("union relationships", () => {
587
556
}
588
557
` ;
589
558
590
- await session . run (
559
+ await testHelper . runCypher (
591
560
`
592
561
CREATE (a:${ typeActor } { name: $actorName })
593
562
CREATE (m:${ typeMovie } { title: $movieTitle, runtime:$movieRuntime })
@@ -610,10 +579,7 @@ describe("union relationships", () => {
610
579
}
611
580
) ;
612
581
613
- const gqlResult = await graphql ( {
614
- schema : await neoSchema . getSchema ( ) ,
615
- source : query ,
616
- contextValue : neo4j . getContextValues ( ) ,
582
+ const gqlResult = await testHelper . runGraphQL ( query , {
617
583
variableValues : { title : movieTitle2 } ,
618
584
} ) ;
619
585
0 commit comments