Skip to content

Commit 42efdb1

Browse files
authored
Update flaky tests in issues (#4849)
* 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
1 parent 663f1cd commit 42efdb1

File tree

174 files changed

+4887
-8947
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

174 files changed

+4887
-8947
lines changed

packages/graphql/tests/integration/issues/1049.int.test.ts

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,24 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { GraphQLSchema } from "graphql";
21-
import { graphql } from "graphql";
22-
import type { Driver, Session } from "neo4j-driver";
23-
import { Neo4jGraphQL } from "../../../src";
24-
import { UniqueType } from "../../utils/graphql-types";
25-
import Neo4jHelper from "../neo4j";
20+
import type { UniqueType } from "../../utils/graphql-types";
21+
import { TestHelper } from "../utils/tests-helper";
2622

2723
describe("https://github.com/neo4j/graphql/issues/1049", () => {
28-
let schema: GraphQLSchema;
29-
let neo4j: Neo4jHelper;
30-
let driver: Driver;
31-
let session: Session;
32-
33-
const Book = new UniqueType("Book");
34-
const Film = new UniqueType("Film");
35-
const Person = new UniqueType("Person");
36-
const Media = new UniqueType("Media");
37-
38-
async function graphqlQuery(query: string) {
39-
return graphql({
40-
schema,
41-
source: query,
42-
contextValue: neo4j.getContextValues(),
43-
});
44-
}
24+
let testHelper: TestHelper;
25+
26+
let Book: UniqueType;
27+
let Film: UniqueType;
28+
let Person: UniqueType;
29+
let Media: UniqueType;
4530

4631
beforeAll(async () => {
47-
neo4j = new Neo4jHelper();
48-
driver = await neo4j.getDriver();
32+
testHelper = new TestHelper();
33+
34+
Book = testHelper.createUniqueType("Book");
35+
Film = testHelper.createUniqueType("Film");
36+
Person = testHelper.createUniqueType("Person");
37+
Media = testHelper.createUniqueType("Media");
4938

5039
const typeDefs = `
5140
interface ${Media.name} {
@@ -92,15 +81,11 @@ describe("https://github.com/neo4j/graphql/issues/1049", () => {
9281
}
9382
`;
9483

95-
session = await neo4j.getSession();
96-
97-
const neoGraphql = new Neo4jGraphQL({ typeDefs, driver });
98-
schema = await neoGraphql.getSchema();
84+
await testHelper.initNeo4jGraphQL({ typeDefs });
9985
});
10086

10187
afterAll(async () => {
102-
await session.close();
103-
await driver.close();
88+
await testHelper.close();
10489
});
10590

10691
test("error should not be thrown", async () => {
@@ -126,7 +111,7 @@ describe("https://github.com/neo4j/graphql/issues/1049", () => {
126111
}
127112
`;
128113

129-
const mutationResult = await graphqlQuery(mutation);
114+
const mutationResult = await testHelper.runGraphQL(mutation);
130115
expect(mutationResult.errors).toBeUndefined();
131116

132117
const query = `
@@ -137,7 +122,7 @@ describe("https://github.com/neo4j/graphql/issues/1049", () => {
137122
}
138123
`;
139124

140-
const queryResult = await graphqlQuery(query);
125+
const queryResult = await testHelper.runGraphQL(query);
141126
expect(queryResult.errors).toBeUndefined();
142127
expect(queryResult.data).toEqual({ [Person.plural]: [{ name: "Bob" }] });
143128
});

packages/graphql/tests/integration/issues/1050.int.test.ts

Lines changed: 24 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -17,30 +17,24 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { GraphQLSchema } from "graphql";
21-
import { graphql } from "graphql";
22-
import type { Driver, Session } from "neo4j-driver";
2320
import { gql } from "graphql-tag";
24-
import Neo4jHelper from "../neo4j";
25-
import { getQuerySource } from "../../utils/get-query-source";
26-
import { UniqueType } from "../../utils/graphql-types";
27-
import { Neo4jGraphQL } from "../../../src";
28-
import { createBearerToken } from "../../utils/create-bearer-token";
21+
import type { UniqueType } from "../../utils/graphql-types";
22+
import { TestHelper } from "../utils/tests-helper";
2923

3024
describe("https://github.com/neo4j/graphql/issues/1050", () => {
31-
const testUser = new UniqueType("User");
32-
const testInbox = new UniqueType("Inbox");
33-
const testMessage = new UniqueType("Message");
34-
const testAttachment = new UniqueType("Attachment");
25+
let testUser: UniqueType;
26+
let testInbox: UniqueType;
27+
let testMessage: UniqueType;
28+
let testAttachment: UniqueType;
3529

36-
let schema: GraphQLSchema;
37-
let driver: Driver;
38-
let neo4j: Neo4jHelper;
39-
let session: Session;
30+
let testHelper: TestHelper;
4031

41-
beforeAll(async () => {
42-
neo4j = new Neo4jHelper();
43-
driver = await neo4j.getDriver();
32+
beforeEach(async () => {
33+
testHelper = new TestHelper();
34+
testUser = testHelper.createUniqueType("User");
35+
testInbox = testHelper.createUniqueType("Inbox");
36+
testMessage = testHelper.createUniqueType("Message");
37+
testAttachment = testHelper.createUniqueType("Attachment");
4438

4539
const typeDefs = gql`
4640
type ${testUser.name} {
@@ -103,36 +97,25 @@ describe("https://github.com/neo4j/graphql/issues/1050", () => {
10397
]
10498
)
10599
`;
106-
const neoGraphql = new Neo4jGraphQL({ typeDefs, driver, features: { authorization: { key: "secret" } } });
107-
schema = await neoGraphql.getSchema();
108-
});
109-
110-
beforeEach(async () => {
111-
session = await neo4j.getSession();
100+
await testHelper.initNeo4jGraphQL({
101+
typeDefs,
102+
features: { authorization: { key: "secret" } },
103+
});
112104
});
113105

114106
afterEach(async () => {
115-
const labelMatches = [testUser, testInbox, testMessage, testAttachment]
116-
.map((testNodeType) => `n:${testNodeType.name}`)
117-
.join(" OR ");
118-
await session.run(`MATCH (n) WHERE ${labelMatches} DETACH DELETE n`);
119-
120-
await session.close();
121-
});
122-
123-
afterAll(async () => {
124-
await driver.close();
107+
await testHelper.close();
125108
});
126109

127110
test("should handle auth appropriately for nested connection", async () => {
128-
await session.run(`
111+
await testHelper.runCypher(`
129112
CREATE (c:${testUser.name} {id: 'abc'})
130113
-[:OWNS]->(i:${testInbox.name} {ownerId: 'abc'})
131114
-[:CONTAINS]->(m:${testMessage.name} {ownerId: 'abc', subject: 'Hello', body: 'World'})
132115
<-[:ATTACHED_TO]-(a:${testAttachment.name} {ownerId: 'abc', contents: 'something interesting'})
133116
`);
134117

135-
const query = gql`
118+
const query = /* GraphQL */ `
136119
query {
137120
${testUser.plural} {
138121
inboxes {
@@ -150,15 +133,13 @@ describe("https://github.com/neo4j/graphql/issues/1050", () => {
150133
}
151134
`;
152135

153-
const result = await graphql({
154-
schema,
155-
source: getQuerySource(query),
156-
contextValue: neo4j.getContextValues({
157-
token: createBearerToken("secret"),
136+
const result = await testHelper.runGraphQL(query, {
137+
contextValue: {
138+
token: testHelper.createBearerToken("secret"),
158139
user: {
159140
id: "abc",
160141
},
161-
}),
142+
},
162143
});
163144
expect(result.errors).toBeUndefined();
164145
expect(result.data as any).toEqual({

packages/graphql/tests/integration/issues/1115.int.test.ts

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

20-
import type { GraphQLSchema } from "graphql";
21-
import { graphql } from "graphql";
22-
import type { Driver } from "neo4j-driver";
23-
import Neo4jHelper from "../neo4j";
24-
import { Neo4jGraphQL } from "../../../src";
25-
import { UniqueType } from "../../utils/graphql-types";
26-
import { runCypher } from "../../utils/run-cypher";
27-
import { createBearerToken } from "../../utils/create-bearer-token";
20+
import type { UniqueType } from "../../utils/graphql-types";
21+
import { TestHelper } from "../utils/tests-helper";
2822

2923
describe("https://github.com/neo4j/graphql/issues/1115", () => {
30-
const parentType = new UniqueType("Parent");
31-
const childType = new UniqueType("Child");
24+
let parentType: UniqueType;
25+
let childType: UniqueType;
3226

33-
let schema: GraphQLSchema;
34-
let driver: Driver;
35-
let neo4j: Neo4jHelper;
27+
let testHelper: TestHelper;
3628

3729
beforeAll(async () => {
38-
neo4j = new Neo4jHelper();
39-
driver = await neo4j.getDriver();
30+
testHelper = new TestHelper();
31+
parentType = testHelper.createUniqueType("Parent");
32+
childType = testHelper.createUniqueType("Child");
4033

4134
const typeDefs = `
4235
type JWTPayload @jwt {
@@ -59,27 +52,24 @@ describe("https://github.com/neo4j/graphql/issues/1115", () => {
5952
]
6053
)
6154
`;
62-
const neoGraphql = new Neo4jGraphQL({
55+
await testHelper.initNeo4jGraphQL({
6356
typeDefs,
64-
driver,
6557
features: {
6658
authorization: {
6759
key: "secret",
6860
},
6961
},
7062
});
71-
schema = await neoGraphql.getSchema();
7263
});
7364

7465
afterAll(async () => {
75-
await driver.close();
66+
await testHelper.close();
7667
});
7768

7869
test("should not throw on multiple connectOrCreate with auth", async () => {
79-
const session = await neo4j.getSession();
80-
await runCypher(session, `CREATE (:${parentType})<-[:HAS]-(:${childType} {tcId: "123"})`);
70+
await testHelper.runCypher(`CREATE (:${parentType})<-[:HAS]-(:${childType} {tcId: "123"})`);
8171

82-
const token = createBearerToken("secret", { roles: ["upstream"] });
72+
const token = testHelper.createBearerToken("secret", { roles: ["upstream"] });
8373
const query = `
8474
mutation {
8575
${parentType.operations.update}(
@@ -103,11 +93,7 @@ describe("https://github.com/neo4j/graphql/issues/1115", () => {
10393
}
10494
`;
10595

106-
const res = await graphql({
107-
schema,
108-
source: query,
109-
contextValue: neo4j.getContextValues({ token }),
110-
});
96+
const res = await testHelper.runGraphQLWithToken(query, token);
11197

11298
expect(res.errors).toBeUndefined();
11399
expect(res.data).toEqual({

packages/graphql/tests/integration/issues/1121.int.test.ts

Lines changed: 18 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -17,35 +17,24 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { GraphQLSchema } from "graphql";
21-
import { graphql } from "graphql";
22-
import type { Driver, Session } from "neo4j-driver";
23-
import { Neo4jGraphQL } from "../../../src";
24-
import { UniqueType } from "../../utils/graphql-types";
25-
import Neo4jHelper from "../neo4j";
20+
import type { UniqueType } from "../../utils/graphql-types";
21+
import { TestHelper } from "../utils/tests-helper";
2622

2723
describe("https://github.com/neo4j/graphql/issues/1121", () => {
28-
let schema: GraphQLSchema;
29-
let neo4j: Neo4jHelper;
30-
let driver: Driver;
31-
let session: Session;
32-
33-
const Food = new UniqueType("Food");
34-
const Banana = new UniqueType("Banana");
35-
const Sugar = new UniqueType("Sugar");
36-
const Syrup = new UniqueType("Syrup");
37-
38-
async function graphqlQuery(query: string) {
39-
return graphql({
40-
schema,
41-
source: query,
42-
contextValue: neo4j.getContextValues(),
43-
});
44-
}
24+
let testHelper: TestHelper;
25+
26+
let Food: UniqueType;
27+
let Banana: UniqueType;
28+
let Sugar: UniqueType;
29+
let Syrup: UniqueType;
4530

4631
beforeAll(async () => {
47-
neo4j = new Neo4jHelper();
48-
driver = await neo4j.getDriver();
32+
testHelper = new TestHelper();
33+
34+
Food = testHelper.createUniqueType("Food");
35+
Banana = testHelper.createUniqueType("Banana");
36+
Sugar = testHelper.createUniqueType("Sugar");
37+
Syrup = testHelper.createUniqueType("Syrup");
4938

5039
const typeDefs = `
5140
type ${Food.name} {
@@ -85,15 +74,11 @@ describe("https://github.com/neo4j/graphql/issues/1121", () => {
8574
}
8675
`;
8776

88-
session = await neo4j.getSession();
89-
90-
const neoGraphql = new Neo4jGraphQL({ typeDefs, driver });
91-
schema = await neoGraphql.getSchema();
77+
await testHelper.initNeo4jGraphQL({ typeDefs });
9278
});
9379

9480
afterAll(async () => {
95-
await session.close();
96-
await driver.close();
81+
await testHelper.close();
9782
});
9883

9984
test("error should not be thrown", async () => {
@@ -125,7 +110,7 @@ describe("https://github.com/neo4j/graphql/issues/1121", () => {
125110
}
126111
`;
127112

128-
const mutationResult = await graphqlQuery(mutation);
113+
const mutationResult = await testHelper.runGraphQL(mutation);
129114
expect(mutationResult.errors).toBeUndefined();
130115

131116
const query = `
@@ -144,7 +129,7 @@ describe("https://github.com/neo4j/graphql/issues/1121", () => {
144129
}
145130
`;
146131

147-
const queryResult = await graphqlQuery(query);
132+
const queryResult = await testHelper.runGraphQL(query);
148133
expect(queryResult.errors).toBeUndefined();
149134
expect(queryResult.data).toEqual({
150135
[Food.plural]: [

0 commit comments

Comments
 (0)