Skip to content

Commit f7bdadb

Browse files
authored
Update tests in array methods to use test helper (#4858)
* Add test helpers * WIP fix issue tests * Update issue integration tests to use TestHelpers * Fix eslint errors * Update test 349 * Improve contextValue in testHelper * Address PR comments * Fix bug with cleanNodes * Remove getSession from testHelper * Fix int test 464 * Remove deprecation notice from cleanNodesUsingSession * Update integration test for 505 * Update test 915 * Update remaining integration/issues tests with testHelper * Update tests in array methods to use test helper
1 parent bbeef3d commit f7bdadb

File tree

7 files changed

+188
-431
lines changed

7 files changed

+188
-431
lines changed

packages/graphql/tests/integration/array-methods/array-pop-and-push-errors.int.test.ts

Lines changed: 19 additions & 51 deletions
Original file line numberDiff line numberDiff line change
@@ -17,42 +17,26 @@
1717
* limitations under the License.
1818
*/
1919

20-
import { gql } from "graphql-tag";
2120
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";
2522
import { IncomingMessage } from "http";
2623
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";
3126

3227
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;
4129

42-
afterAll(async () => {
43-
await driver.close();
44-
});
45-
46-
beforeEach(async () => {
47-
session = await neo4j.getSession();
30+
beforeEach(() => {
31+
testHelper = new TestHelper();
4832
});
4933

5034
afterEach(async () => {
51-
await session.close();
35+
await testHelper.close();
5236
});
5337

5438
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");
5640

5741
const typeDefs = gql`
5842
type ${typeMovie} {
@@ -62,7 +46,7 @@ describe("array-pop-and-push", () => {
6246
}
6347
`;
6448

65-
const neoSchema = new Neo4jGraphQL({ typeDefs });
49+
await testHelper.initNeo4jGraphQL({ typeDefs });
6650

6751
const movieTitle = generate({
6852
charset: "alphabetic",
@@ -84,17 +68,9 @@ describe("array-pop-and-push", () => {
8468
CREATE (m:${typeMovie} {title:$movieTitle, tags: ["abc"] })
8569
`;
8670

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 });
9472

95-
if (gqlResult.errors) {
96-
console.log(JSON.stringify(gqlResult.errors, null, 2));
97-
}
73+
const gqlResult = await testHelper.runGraphQL(update);
9874

9975
expect(gqlResult.errors).toBeDefined();
10076
expect(
@@ -105,7 +81,7 @@ describe("array-pop-and-push", () => {
10581
});
10682

10783
test("should throw an error if not authenticated on field definition", async () => {
108-
const typeMovie = new UniqueType("Movie");
84+
const typeMovie = testHelper.createUniqueType("Movie");
10985
const typeDefs = `
11086
type ${typeMovie} {
11187
title: String
@@ -114,7 +90,7 @@ describe("array-pop-and-push", () => {
11490
}
11591
`;
11692

117-
const neoSchema = new Neo4jGraphQL({ typeDefs, features: { authorization: { key: "secret" } } });
93+
await testHelper.initNeo4jGraphQL({ typeDefs, features: { authorization: { key: "secret" } } });
11894

11995
const movieTitle = generate({
12096
charset: "alphabetic",
@@ -136,27 +112,23 @@ describe("array-pop-and-push", () => {
136112
CREATE (m:${typeMovie} {title:$movieTitle, tags: ['a', 'b'], moreTags: []})
137113
`;
138114

139-
await session.run(cypher, { movieTitle });
115+
await testHelper.runCypher(cypher, { movieTitle });
140116

141117
const token = "not valid token";
142118

143119
const socket = new Socket({ readable: true });
144120
const req = new IncomingMessage(socket);
145121
req.headers.authorization = `Bearer ${token}`;
146122

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);
152124

153125
expect(gqlResult.errors).toBeDefined();
154126
expect((gqlResult.errors as GraphQLError[]).some((el) => el.message.includes("Unauthenticated"))).toBeTruthy();
155127
expect(gqlResult.data).toBeNull();
156128
});
157129

158130
test("should throw an error when input is invalid", async () => {
159-
const typeMovie = new UniqueType("Movie");
131+
const typeMovie = testHelper.createUniqueType("Movie");
160132

161133
const typeDefs = gql`
162134
type ${typeMovie} {
@@ -166,7 +138,7 @@ describe("array-pop-and-push", () => {
166138
}
167139
`;
168140

169-
const neoSchema = new Neo4jGraphQL({ typeDefs });
141+
await testHelper.initNeo4jGraphQL({ typeDefs });
170142

171143
const movieTitle = generate({
172144
charset: "alphabetic",
@@ -188,13 +160,9 @@ describe("array-pop-and-push", () => {
188160
CREATE (m:${typeMovie} {title:$movieTitle, tags: ["abc"], moreTags: ["this", "that", "them"] })
189161
`;
190162

191-
await session.run(cypher, { movieTitle });
163+
await testHelper.runCypher(cypher, { movieTitle });
192164

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);
198166

199167
expect(gqlResult.errors).toBeDefined();
200168
expect(

packages/graphql/tests/integration/array-methods/array-pop-and-push.int.test.ts

Lines changed: 9 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -17,39 +17,23 @@
1717
* limitations under the License.
1818
*/
1919

20-
import { graphql } from "graphql";
2120
import { gql } from "graphql-tag";
22-
import type { Driver, Session } from "neo4j-driver";
2321
import { generate } from "randomstring";
24-
25-
import Neo4jHelper from "../neo4j";
26-
import { Neo4jGraphQL } from "../../../src/classes";
27-
import { UniqueType } from "../../utils/graphql-types";
22+
import { TestHelper } from "../utils/tests-helper";
2823

2924
describe("array-pop-and-push", () => {
30-
let driver: Driver;
31-
let session: Session;
32-
let neo4j: Neo4jHelper;
33-
34-
beforeAll(async () => {
35-
neo4j = new Neo4jHelper();
36-
driver = await neo4j.getDriver();
37-
});
25+
let testHelper: TestHelper;
3826

39-
afterAll(async () => {
40-
await driver.close();
41-
});
42-
43-
beforeEach(async () => {
44-
session = await neo4j.getSession();
27+
beforeEach(() => {
28+
testHelper = new TestHelper();
4529
});
4630

4731
afterEach(async () => {
48-
await session.close();
32+
await testHelper.close();
4933
});
5034

5135
test("should push to and pop from two different arrays in the same update", async () => {
52-
const typeMovie = new UniqueType("Movie");
36+
const typeMovie = testHelper.createUniqueType("Movie");
5337

5438
const typeDefs = gql`
5539
type ${typeMovie} {
@@ -59,7 +43,7 @@ describe("array-pop-and-push", () => {
5943
}
6044
`;
6145

62-
const neoSchema = new Neo4jGraphQL({ typeDefs });
46+
await testHelper.initNeo4jGraphQL({ typeDefs });
6347

6448
const movieTitle = generate({
6549
charset: "alphabetic",
@@ -81,13 +65,9 @@ describe("array-pop-and-push", () => {
8165
CREATE (m:${typeMovie} {title:$movieTitle, tags: ["abc"], moreTags: ["this", "that", "them"] })
8266
`;
8367

84-
await session.run(cypher, { movieTitle });
68+
await testHelper.runCypher(cypher, { movieTitle });
8569

86-
const gqlResult = await graphql({
87-
schema: await neoSchema.getSchema(),
88-
source: update,
89-
contextValue: neo4j.getContextValues(),
90-
});
70+
const gqlResult = await testHelper.runGraphQL(update);
9171

9272
if (gqlResult.errors) {
9373
console.log(JSON.stringify(gqlResult.errors, null, 2));

0 commit comments

Comments
 (0)