Skip to content

Commit a8032ed

Browse files
authored
Update config options integrations tests (#4859)
1 parent 42efdb1 commit a8032ed

File tree

2 files changed

+25
-60
lines changed

2 files changed

+25
-60
lines changed

packages/graphql/tests/integration/config-options/query-options.int.test.ts

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

20-
import { graphql } from "graphql";
21-
import type { Driver } from "neo4j-driver";
2220
import { generate } from "randomstring";
23-
import { Neo4jGraphQL } from "../../../src/classes";
24-
import { UniqueType } from "../../utils/graphql-types";
25-
import Neo4jHelper from "../neo4j";
21+
import type { Neo4jGraphQL } from "../../../src";
22+
import type { UniqueType } from "../../utils/graphql-types";
23+
import { TestHelper } from "../utils/tests-helper";
2624

2725
describe("query options", () => {
28-
let driver: Driver;
29-
let neo4j: Neo4jHelper;
3026
let neoSchema: Neo4jGraphQL;
3127

28+
let testHelper: TestHelper;
29+
3230
let Actor: UniqueType;
3331
let Movie: UniqueType;
3432

35-
beforeAll(async () => {
36-
neo4j = new Neo4jHelper();
37-
driver = await neo4j.getDriver();
38-
Actor = new UniqueType("Actor");
39-
Movie = new UniqueType("Movie");
33+
beforeEach(async () => {
34+
testHelper = new TestHelper();
35+
Actor = testHelper.createUniqueType("Actor");
36+
Movie = testHelper.createUniqueType("Movie");
37+
4038
const typeDefs = `
4139
type ${Actor} {
4240
name: String
@@ -50,19 +48,16 @@ describe("query options", () => {
5048
}
5149
`;
5250

53-
neoSchema = new Neo4jGraphQL({
51+
neoSchema = await testHelper.initNeo4jGraphQL({
5452
typeDefs,
55-
driver,
5653
});
5754
});
5855

59-
afterAll(async () => {
60-
await driver.close();
56+
afterEach(async () => {
57+
await testHelper.close();
6158
});
6259

6360
test("queries should work with runtime set to interpreted", async () => {
64-
const session = await neo4j.getSession();
65-
6661
const id = generate({
6762
charset: "alphabetic",
6863
});
@@ -75,28 +70,22 @@ describe("query options", () => {
7570
}
7671
`;
7772

78-
try {
79-
await neoSchema.checkNeo4jCompat();
73+
await neoSchema.checkNeo4jCompat();
8074

81-
await session.run(
82-
`
75+
await testHelper.runCypher(
76+
`
8377
CREATE (:${Movie} {id: $id}), (:${Movie} {id: $id}), (:${Movie} {id: $id})
8478
`,
85-
{ id }
86-
);
79+
{ id }
80+
);
8781

88-
const result = await graphql({
89-
schema: await neoSchema.getSchema(),
90-
source: query,
91-
variableValues: { id },
92-
contextValue: neo4j.getContextValues({ cypherQueryOptions: { runtime: "interpreted" } }),
93-
});
82+
const result = await testHelper.runGraphQL(query, {
83+
variableValues: { id },
84+
contextValue: { cypherQueryOptions: { runtime: "interpreted" } },
85+
});
9486

95-
expect(result.errors).toBeFalsy();
87+
expect(result.errors).toBeFalsy();
9688

97-
expect(result?.data?.[Movie.plural]).toEqual([{ id }, { id }, { id }]);
98-
} finally {
99-
await session.close();
100-
}
89+
expect(result?.data?.[Movie.plural]).toEqual([{ id }, { id }, { id }]);
10190
});
10291
});

packages/graphql/tests/integration/config-options/startup-validation.int.test.ts

Lines changed: 1 addition & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -17,15 +17,10 @@
1717
* limitations under the License.
1818
*/
1919

20-
import type { Driver } from "neo4j-driver";
21-
import Neo4jHelper from "../neo4j";
22-
import { Neo4jGraphQL } from "../../../src/classes";
2320
import { GraphQLError } from "graphql";
21+
import { Neo4jGraphQL } from "../../../src/classes";
2422

2523
describe("Startup Validation", () => {
26-
let driver: Driver;
27-
let neo4j: Neo4jHelper;
28-
2924
const typePointAlreadyExistsErrors = [
3025
new GraphQLError(
3126
'Type "Point" already exists in the schema. It cannot also be defined in this type definition.'
@@ -103,19 +98,9 @@ describe("Startup Validation", () => {
10398
}
10499
`;
105100

106-
beforeAll(async () => {
107-
neo4j = new Neo4jHelper();
108-
driver = await neo4j.getDriver();
109-
});
110-
111-
afterAll(async () => {
112-
await driver.close();
113-
});
114-
115101
test("should not throw an error for valid type defs when running startup validation", async () => {
116102
const neoSchema = new Neo4jGraphQL({
117103
typeDefs: validTypeDefs,
118-
driver,
119104
validate: true,
120105
});
121106

@@ -125,7 +110,6 @@ describe("Startup Validation", () => {
125110
test("should throw an error for invalid type defs by default", async () => {
126111
const neoSchema = new Neo4jGraphQL({
127112
typeDefs: invalidTypeDefs,
128-
driver,
129113
});
130114

131115
await expect(neoSchema.getSchema()).rejects.toIncludeSameMembers(typePointAlreadyExistsErrors);
@@ -134,7 +118,6 @@ describe("Startup Validation", () => {
134118
test("should not throw an error for invalid type defs when validate is false", async () => {
135119
const neoSchema = new Neo4jGraphQL({
136120
typeDefs: invalidTypeDefs,
137-
driver,
138121
validate: false,
139122
});
140123

@@ -144,7 +127,6 @@ describe("Startup Validation", () => {
144127
test("should throw an error for invalid type defs when validate is true", async () => {
145128
const neoSchema = new Neo4jGraphQL({
146129
typeDefs: invalidTypeDefs,
147-
driver,
148130
validate: true,
149131
});
150132

@@ -165,7 +147,6 @@ describe("Startup Validation", () => {
165147
test("should warn for missing custom resolvers", async () => {
166148
const neoSchema = new Neo4jGraphQL({
167149
typeDefs: customResolverTypeDefs,
168-
driver,
169150
});
170151

171152
await neoSchema.getSchema();
@@ -176,7 +157,6 @@ describe("Startup Validation", () => {
176157
test("should throw an error for invalid type defs when validate is true, and warn will not be reached", async () => {
177158
const neoSchema = new Neo4jGraphQL({
178159
typeDefs: invalidAndCustomResolverTypeDefs,
179-
driver,
180160
validate: true,
181161
});
182162

@@ -187,7 +167,6 @@ describe("Startup Validation", () => {
187167
test("should throw no errors when validate is false, but warn for custom resolvers", async () => {
188168
const neoSchema = new Neo4jGraphQL({
189169
typeDefs: invalidAndCustomResolverTypeDefs,
190-
driver,
191170
validate: false,
192171
});
193172

@@ -199,7 +178,6 @@ describe("Startup Validation", () => {
199178
test("should throw an error for duplicate relationship fields when validate is true", async () => {
200179
const neoSchema = new Neo4jGraphQL({
201180
typeDefs: invalidDuplicateRelationship,
202-
driver,
203181
validate: true,
204182
});
205183

@@ -213,7 +191,6 @@ describe("Startup Validation", () => {
213191
test("should not throw an error for duplicate relationship fields validate is false", async () => {
214192
const neoSchema = new Neo4jGraphQL({
215193
typeDefs: invalidDuplicateRelationship,
216-
driver,
217194
validate: false,
218195
});
219196

@@ -223,7 +200,6 @@ describe("Startup Validation", () => {
223200
test("should throw no errors when validate is false", async () => {
224201
const neoSchema = new Neo4jGraphQL({
225202
typeDefs: invalidAll,
226-
driver,
227203
validate: false,
228204
});
229205

0 commit comments

Comments
 (0)