Skip to content

Commit d46a789

Browse files
authored
Update integration tests for aggregations to use testHelpers (#4866)
1 parent a8032ed commit d46a789

40 files changed

+2285
-4205
lines changed

packages/graphql/tests/integration/aggregations/field-level/authorization/field-aggregation-authorization-where.int.test.ts

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

20-
import type { Driver, Session } from "neo4j-driver";
21-
import { graphql } from "graphql";
22-
import Neo4jHelper from "../../../neo4j";
23-
import { Neo4jGraphQL } from "../../../../../src/classes";
24-
import { UniqueType } from "../../../../utils/graphql-types";
2520
import { createBearerToken } from "../../../../utils/create-bearer-token";
21+
import type { UniqueType } from "../../../../utils/graphql-types";
22+
import { TestHelper } from "../../../utils/tests-helper";
2623

2724
describe(`Field Level Authorization Where Requests`, () => {
28-
let neoSchema: Neo4jGraphQL;
29-
let driver: Driver;
30-
let neo4j: Neo4jHelper;
31-
let session: Session;
32-
const typeMovie = new UniqueType("Movie");
33-
const typeActor = new UniqueType("Actor");
34-
const typeDefs = `
35-
type ${typeMovie.name} {
36-
name: String
37-
year: Int
38-
createdAt: DateTime
39-
${typeActor.plural}: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN)
40-
}
41-
42-
type ${typeActor.name} {
43-
name: String
44-
year: Int
45-
createdAt: DateTime
46-
testStr: String
47-
${typeMovie.plural}: [${typeMovie.name}!]! @relationship(type: "ACTED_IN", direction: OUT)
48-
}`;
25+
let testHelper: TestHelper;
26+
27+
let typeMovie: UniqueType;
28+
let typeActor: UniqueType;
29+
let typeDefs: string;
4930
const secret = "secret";
5031

51-
beforeAll(async () => {
52-
neo4j = new Neo4jHelper();
53-
driver = await neo4j.getDriver();
54-
session = await neo4j.getSession();
32+
beforeEach(async () => {
33+
testHelper = new TestHelper();
34+
35+
typeMovie = testHelper.createUniqueType("Movie");
36+
typeActor = testHelper.createUniqueType("Actor");
37+
typeDefs = `
38+
type ${typeMovie.name} {
39+
name: String
40+
year: Int
41+
createdAt: DateTime
42+
${typeActor.plural}: [${typeActor.name}!]! @relationship(type: "ACTED_IN", direction: IN)
43+
}
44+
45+
type ${typeActor.name} {
46+
name: String
47+
year: Int
48+
createdAt: DateTime
49+
testStr: String
50+
${typeMovie.plural}: [${typeMovie.name}!]! @relationship(type: "ACTED_IN", direction: OUT)
51+
}`;
5552

56-
await session.run(`
53+
await testHelper.runCypher(`
5754
CREATE (m:${typeMovie.name}
5855
{name: "Terminator",year:1990,createdAt: datetime()})
5956
<-[:ACTED_IN]-
@@ -63,7 +60,7 @@ describe(`Field Level Authorization Where Requests`, () => {
6360
const extendedTypeDefs = `${typeDefs}
6461
extend type ${typeActor.name} @authorization(filter: [{ operations: [AGGREGATE], where: { node: { testStr: "$jwt.sub" } } }])`;
6562

66-
neoSchema = new Neo4jGraphQL({
63+
await testHelper.initNeo4jGraphQL({
6764
typeDefs: extendedTypeDefs,
6865
features: {
6966
authorization: {
@@ -73,9 +70,8 @@ describe(`Field Level Authorization Where Requests`, () => {
7370
});
7471
});
7572

76-
afterAll(async () => {
77-
await session.close();
78-
await driver.close();
73+
afterEach(async () => {
74+
await testHelper.close();
7975
});
8076

8177
test("authenticated query", async () => {
@@ -88,11 +84,7 @@ describe(`Field Level Authorization Where Requests`, () => {
8884
}`;
8985

9086
const token = createBearerToken(secret, { sub: "1234" });
91-
const gqlResult = await graphql({
92-
schema: await neoSchema.getSchema(),
93-
source: query,
94-
contextValue: neo4j.getContextValues({ token }),
95-
});
87+
const gqlResult = await testHelper.runGraphQLWithToken(query, token);
9688
expect(gqlResult.errors).toBeUndefined();
9789
expect((gqlResult as any).data[typeMovie.plural][0][`${typeActor.plural}Aggregate`]).toEqual({
9890
count: 1,
@@ -108,11 +100,7 @@ describe(`Field Level Authorization Where Requests`, () => {
108100
}
109101
}`;
110102

111-
const gqlResult = await graphql({
112-
schema: await neoSchema.getSchema(),
113-
source: query,
114-
contextValue: neo4j.getContextValues(),
115-
});
103+
const gqlResult = await testHelper.runGraphQL(query);
116104

117105
expect(gqlResult.errors).toBeUndefined();
118106
expect(gqlResult.data as any).toEqual({
@@ -130,11 +118,7 @@ describe(`Field Level Authorization Where Requests`, () => {
130118
}`;
131119

132120
const invalidToken = createBearerToken(secret, { sub: "2222" });
133-
const gqlResult = await graphql({
134-
schema: await neoSchema.getSchema(),
135-
source: query,
136-
contextValue: neo4j.getContextValues({ token: invalidToken }),
137-
});
121+
const gqlResult = await testHelper.runGraphQLWithToken(query, invalidToken);
138122
expect(gqlResult.errors).toBeUndefined();
139123
expect((gqlResult as any).data[typeMovie.plural][0][`${typeActor.plural}Aggregate`]).toEqual({
140124
count: 0,

0 commit comments

Comments
 (0)