17
17
* limitations under the License.
18
18
*/
19
19
20
- import { gql } from "graphql-tag" ;
21
20
import type { GraphQLError } from "graphql" ;
22
- import { graphql } from "graphql" ;
23
- import type { Driver , Session } from "neo4j-driver" ;
24
- import { generate } from "randomstring" ;
21
+ import { gql } from "graphql-tag" ;
25
22
import { IncomingMessage } from "http" ;
26
23
import { Socket } from "net" ;
27
-
28
- import { Neo4jGraphQL } from "../../../src/classes" ;
29
- import Neo4jHelper from "../neo4j" ;
30
- import { UniqueType } from "../../utils/graphql-types" ;
24
+ import { generate } from "randomstring" ;
25
+ import { TestHelper } from "../utils/tests-helper" ;
31
26
32
27
describe ( "array-pop-and-push" , ( ) => {
33
- let driver : Driver ;
34
- let session : Session ;
35
- let neo4j : Neo4jHelper ;
36
-
37
- beforeAll ( async ( ) => {
38
- neo4j = new Neo4jHelper ( ) ;
39
- driver = await neo4j . getDriver ( ) ;
40
- } ) ;
28
+ let testHelper : TestHelper ;
41
29
42
- afterAll ( async ( ) => {
43
- await driver . close ( ) ;
44
- } ) ;
45
-
46
- beforeEach ( async ( ) => {
47
- session = await neo4j . getSession ( ) ;
30
+ beforeEach ( ( ) => {
31
+ testHelper = new TestHelper ( ) ;
48
32
} ) ;
49
33
50
34
afterEach ( async ( ) => {
51
- await session . close ( ) ;
35
+ await testHelper . close ( ) ;
52
36
} ) ;
53
37
54
38
test ( "should throw an error when trying to pop an element from a non-existing array" , async ( ) => {
55
- const typeMovie = new UniqueType ( "Movie" ) ;
39
+ const typeMovie = testHelper . createUniqueType ( "Movie" ) ;
56
40
57
41
const typeDefs = gql `
58
42
type ${ typeMovie } {
@@ -62,7 +46,7 @@ describe("array-pop-and-push", () => {
62
46
}
63
47
` ;
64
48
65
- const neoSchema = new Neo4jGraphQL ( { typeDefs } ) ;
49
+ await testHelper . initNeo4jGraphQL ( { typeDefs } ) ;
66
50
67
51
const movieTitle = generate ( {
68
52
charset : "alphabetic" ,
@@ -84,17 +68,9 @@ describe("array-pop-and-push", () => {
84
68
CREATE (m:${ typeMovie } {title:$movieTitle, tags: ["abc"] })
85
69
` ;
86
70
87
- await session . run ( cypher , { movieTitle } ) ;
88
-
89
- const gqlResult = await graphql ( {
90
- schema : await neoSchema . getSchema ( ) ,
91
- source : update ,
92
- contextValue : neo4j . getContextValues ( ) ,
93
- } ) ;
71
+ await testHelper . runCypher ( cypher , { movieTitle } ) ;
94
72
95
- if ( gqlResult . errors ) {
96
- console . log ( JSON . stringify ( gqlResult . errors , null , 2 ) ) ;
97
- }
73
+ const gqlResult = await testHelper . runGraphQL ( update ) ;
98
74
99
75
expect ( gqlResult . errors ) . toBeDefined ( ) ;
100
76
expect (
@@ -105,7 +81,7 @@ describe("array-pop-and-push", () => {
105
81
} ) ;
106
82
107
83
test ( "should throw an error if not authenticated on field definition" , async ( ) => {
108
- const typeMovie = new UniqueType ( "Movie" ) ;
84
+ const typeMovie = testHelper . createUniqueType ( "Movie" ) ;
109
85
const typeDefs = `
110
86
type ${ typeMovie } {
111
87
title: String
@@ -114,7 +90,7 @@ describe("array-pop-and-push", () => {
114
90
}
115
91
` ;
116
92
117
- const neoSchema = new Neo4jGraphQL ( { typeDefs, features : { authorization : { key : "secret" } } } ) ;
93
+ await testHelper . initNeo4jGraphQL ( { typeDefs, features : { authorization : { key : "secret" } } } ) ;
118
94
119
95
const movieTitle = generate ( {
120
96
charset : "alphabetic" ,
@@ -136,27 +112,23 @@ describe("array-pop-and-push", () => {
136
112
CREATE (m:${ typeMovie } {title:$movieTitle, tags: ['a', 'b'], moreTags: []})
137
113
` ;
138
114
139
- await session . run ( cypher , { movieTitle } ) ;
115
+ await testHelper . runCypher ( cypher , { movieTitle } ) ;
140
116
141
117
const token = "not valid token" ;
142
118
143
119
const socket = new Socket ( { readable : true } ) ;
144
120
const req = new IncomingMessage ( socket ) ;
145
121
req . headers . authorization = `Bearer ${ token } ` ;
146
122
147
- const gqlResult = await graphql ( {
148
- schema : await neoSchema . getSchema ( ) ,
149
- source : update ,
150
- contextValue : neo4j . getContextValues ( ) ,
151
- } ) ;
123
+ const gqlResult = await testHelper . runGraphQL ( update ) ;
152
124
153
125
expect ( gqlResult . errors ) . toBeDefined ( ) ;
154
126
expect ( ( gqlResult . errors as GraphQLError [ ] ) . some ( ( el ) => el . message . includes ( "Unauthenticated" ) ) ) . toBeTruthy ( ) ;
155
127
expect ( gqlResult . data ) . toBeNull ( ) ;
156
128
} ) ;
157
129
158
130
test ( "should throw an error when input is invalid" , async ( ) => {
159
- const typeMovie = new UniqueType ( "Movie" ) ;
131
+ const typeMovie = testHelper . createUniqueType ( "Movie" ) ;
160
132
161
133
const typeDefs = gql `
162
134
type ${ typeMovie } {
@@ -166,7 +138,7 @@ describe("array-pop-and-push", () => {
166
138
}
167
139
` ;
168
140
169
- const neoSchema = new Neo4jGraphQL ( { typeDefs } ) ;
141
+ await testHelper . initNeo4jGraphQL ( { typeDefs } ) ;
170
142
171
143
const movieTitle = generate ( {
172
144
charset : "alphabetic" ,
@@ -188,13 +160,9 @@ describe("array-pop-and-push", () => {
188
160
CREATE (m:${ typeMovie } {title:$movieTitle, tags: ["abc"], moreTags: ["this", "that", "them"] })
189
161
` ;
190
162
191
- await session . run ( cypher , { movieTitle } ) ;
163
+ await testHelper . runCypher ( cypher , { movieTitle } ) ;
192
164
193
- const gqlResult = await graphql ( {
194
- schema : await neoSchema . getSchema ( ) ,
195
- source : update ,
196
- contextValue : neo4j . getContextValues ( ) ,
197
- } ) ;
165
+ const gqlResult = await testHelper . runGraphQL ( update ) ;
198
166
199
167
expect ( gqlResult . errors ) . toBeDefined ( ) ;
200
168
expect (
0 commit comments