Skip to content

Commit

Permalink
migrate all the integration/aggregations tests to use UniqueType (#4828)
Browse files Browse the repository at this point in the history
  • Loading branch information
MacondoExpress authored Mar 6, 2024
1 parent b4b82f9 commit 17a74f2
Show file tree
Hide file tree
Showing 16 changed files with 694 additions and 1,357 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,32 @@
* limitations under the License.
*/

import type { Driver } from "neo4j-driver";
import { graphql } from "graphql";
import type { Driver } from "neo4j-driver";
import { generate } from "randomstring";
import Neo4jHelper from "../../neo4j";
import { Neo4jGraphQL } from "../../../../src/classes";
import { UniqueType } from "../../../utils/graphql-types";
import Neo4jHelper from "../../neo4j";

describe("aggregations-top_level-datetime", () => {
let driver: Driver;
let neo4j: Neo4jHelper;
let typeDefs: string;
let neoSchema: Neo4jGraphQL;
let Movie: UniqueType;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();
Movie = new UniqueType("Movie");
typeDefs = `
type ${Movie} {
testString: String
createdAt: DateTime
}
`;

neoSchema = new Neo4jGraphQL({ typeDefs });
});

afterAll(async () => {
Expand All @@ -39,29 +52,20 @@ describe("aggregations-top_level-datetime", () => {
test("should return the min of node properties", async () => {
const session = await neo4j.getSession();

const typeDefs = `
type Movie {
testString: String
createdAt: DateTime
}
`;

const testString = generate({
charset: "alphabetic",
readable: true,
});

const minDate = new Date();

const neoSchema = new Neo4jGraphQL({ typeDefs });

try {
await session.run(
`
CREATE (:Movie {testString: $testString, createdAt: datetime("${minDate.toISOString()}")})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime("${minDate.toISOString()}")})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
`,
{
testString,
Expand All @@ -70,7 +74,7 @@ describe("aggregations-top_level-datetime", () => {

const query = `
{
moviesAggregate(where: {testString: "${testString}"}) {
${Movie.operations.aggregate}(where: {testString: "${testString}"}) {
createdAt {
min
}
Expand All @@ -90,7 +94,7 @@ describe("aggregations-top_level-datetime", () => {

expect(gqlResult.errors).toBeUndefined();

expect((gqlResult.data as any).moviesAggregate).toEqual({
expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({
createdAt: {
min: minDate.toISOString(),
},
Expand All @@ -103,13 +107,6 @@ describe("aggregations-top_level-datetime", () => {
test("should return the max of node properties", async () => {
const session = await neo4j.getSession();

const typeDefs = `
type Movie {
testString: String
createdAt: DateTime
}
`;

const testString = generate({
charset: "alphabetic",
readable: true,
Expand All @@ -120,15 +117,13 @@ describe("aggregations-top_level-datetime", () => {
const maxDate = new Date();
maxDate.setDate(maxDate.getDate() + 1);

const neoSchema = new Neo4jGraphQL({ typeDefs });

try {
await session.run(
`
CREATE (:Movie {testString: $testString, createdAt: datetime("${minDate.toISOString()}")})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:Movie {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")})
CREATE (:${Movie} {testString: $testString, createdAt: datetime("${minDate.toISOString()}")})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")})
`,
{
testString,
Expand All @@ -137,7 +132,7 @@ describe("aggregations-top_level-datetime", () => {

const query = `
{
moviesAggregate(where: {testString: "${testString}"}) {
${Movie.operations.aggregate}(where: {testString: "${testString}"}) {
createdAt {
max
}
Expand All @@ -157,7 +152,7 @@ describe("aggregations-top_level-datetime", () => {

expect(gqlResult.errors).toBeUndefined();

expect((gqlResult.data as any).moviesAggregate).toEqual({
expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({
createdAt: {
max: maxDate.toISOString(),
},
Expand All @@ -170,13 +165,6 @@ describe("aggregations-top_level-datetime", () => {
test("should return the min and max of node properties", async () => {
const session = await neo4j.getSession();

const typeDefs = `
type Movie {
testString: String
createdAt: DateTime
}
`;

const testString = generate({
charset: "alphabetic",
readable: true,
Expand All @@ -187,15 +175,13 @@ describe("aggregations-top_level-datetime", () => {
const maxDate = new Date();
maxDate.setDate(maxDate.getDate() + 1);

const neoSchema = new Neo4jGraphQL({ typeDefs });

try {
await session.run(
`
CREATE (:Movie {testString: $testString, createdAt: datetime("${minDate.toISOString()}")})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:Movie {testString: $testString, createdAt: datetime()})
CREATE (:Movie {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")})
CREATE (:${Movie} {testString: $testString, createdAt: datetime("${minDate.toISOString()}")})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime()})
CREATE (:${Movie} {testString: $testString, createdAt: datetime("${maxDate.toISOString()}")})
`,
{
testString,
Expand All @@ -204,7 +190,7 @@ describe("aggregations-top_level-datetime", () => {

const query = `
{
moviesAggregate(where: {testString: "${testString}"}) {
${Movie.operations.aggregate}(where: {testString: "${testString}"}) {
createdAt {
min
max
Expand All @@ -225,7 +211,7 @@ describe("aggregations-top_level-datetime", () => {

expect(gqlResult.errors).toBeUndefined();

expect((gqlResult.data as any).moviesAggregate).toEqual({
expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({
createdAt: {
min: minDate.toISOString(),
max: maxDate.toISOString(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,20 +17,33 @@
* limitations under the License.
*/

import { graphql } from "graphql";
import type { Driver } from "neo4j-driver";
import neo4jDriver from "neo4j-driver";
import { graphql } from "graphql";
import { generate } from "randomstring";
import Neo4jHelper from "../../neo4j";
import { Neo4jGraphQL } from "../../../../src/classes";
import { UniqueType } from "../../../utils/graphql-types";
import Neo4jHelper from "../../neo4j";

describe("aggregations-top_level-duration", () => {
let driver: Driver;
let neo4j: Neo4jHelper;
let Movie: UniqueType;
let typeDefs: string;
let neoSchema: Neo4jGraphQL;

beforeAll(async () => {
neo4j = new Neo4jHelper();
driver = await neo4j.getDriver();
Movie = new UniqueType("Movie");
typeDefs = `
type ${Movie} {
testString: String
runningTime: Duration
}
`;

neoSchema = new Neo4jGraphQL({ typeDefs });
});

afterAll(async () => {
Expand All @@ -40,13 +53,6 @@ describe("aggregations-top_level-duration", () => {
test("should return the min of node properties", async () => {
const session = await neo4j.getSession();

const typeDefs = `
type Movie {
testString: String
runningTime: Duration
}
`;

const testString = generate({
charset: "alphabetic",
readable: true,
Expand All @@ -57,13 +63,11 @@ describe("aggregations-top_level-duration", () => {
const minDuration = new neo4jDriver.types.Duration(months, days, 0, 0);
const maxDuration = new neo4jDriver.types.Duration(months + 1, days, 0, 0);

const neoSchema = new Neo4jGraphQL({ typeDefs });

try {
await session.run(
`
CREATE (:Movie {testString: $testString, runningTime: $minDuration})
CREATE (:Movie {testString: $testString, runningTime: $maxDuration})
CREATE (:${Movie} {testString: $testString, runningTime: $minDuration})
CREATE (:${Movie} {testString: $testString, runningTime: $maxDuration})
`,
{
testString,
Expand All @@ -74,7 +78,7 @@ describe("aggregations-top_level-duration", () => {

const query = `
{
moviesAggregate(where: {testString: "${testString}"}) {
${Movie.operations.aggregate}(where: {testString: "${testString}"}) {
runningTime {
min
}
Expand All @@ -94,7 +98,7 @@ describe("aggregations-top_level-duration", () => {

expect(gqlResult.errors).toBeUndefined();

expect((gqlResult.data as any).moviesAggregate).toEqual({
expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({
runningTime: {
min: minDuration.toString(),
},
Expand All @@ -107,13 +111,6 @@ describe("aggregations-top_level-duration", () => {
test("should return the max of node properties", async () => {
const session = await neo4j.getSession();

const typeDefs = `
type Movie {
testString: String
runningTime: Duration
}
`;

const testString = generate({
charset: "alphabetic",
readable: true,
Expand All @@ -124,13 +121,11 @@ describe("aggregations-top_level-duration", () => {
const minDuration = new neo4jDriver.types.Duration(months, days, 0, 0);
const maxDuration = new neo4jDriver.types.Duration(months + 1, days, 0, 0);

const neoSchema = new Neo4jGraphQL({ typeDefs });

try {
await session.run(
`
CREATE (:Movie {testString: $testString, runningTime: $minDuration})
CREATE (:Movie {testString: $testString, runningTime: $maxDuration})
CREATE (:${Movie} {testString: $testString, runningTime: $minDuration})
CREATE (:${Movie} {testString: $testString, runningTime: $maxDuration})
`,
{
testString,
Expand All @@ -141,7 +136,7 @@ describe("aggregations-top_level-duration", () => {

const query = `
{
moviesAggregate(where: {testString: "${testString}"}) {
${Movie.operations.aggregate}(where: {testString: "${testString}"}) {
runningTime {
max
}
Expand All @@ -161,7 +156,7 @@ describe("aggregations-top_level-duration", () => {

expect(gqlResult.errors).toBeUndefined();

expect((gqlResult.data as any).moviesAggregate).toEqual({
expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({
runningTime: {
max: maxDuration.toString(),
},
Expand All @@ -174,13 +169,6 @@ describe("aggregations-top_level-duration", () => {
test("should return the min and max of node properties", async () => {
const session = await neo4j.getSession();

const typeDefs = `
type Movie {
testString: String
runningTime: Duration
}
`;

const testString = generate({
charset: "alphabetic",
readable: true,
Expand All @@ -191,13 +179,11 @@ describe("aggregations-top_level-duration", () => {
const minDuration = new neo4jDriver.types.Duration(months, days, 0, 0);
const maxDuration = new neo4jDriver.types.Duration(months + 1, days, 0, 0);

const neoSchema = new Neo4jGraphQL({ typeDefs });

try {
await session.run(
`
CREATE (:Movie {testString: $testString, runningTime: $minDuration})
CREATE (:Movie {testString: $testString, runningTime: $maxDuration})
CREATE (:${Movie} {testString: $testString, runningTime: $minDuration})
CREATE (:${Movie} {testString: $testString, runningTime: $maxDuration})
`,
{
testString,
Expand All @@ -208,7 +194,7 @@ describe("aggregations-top_level-duration", () => {

const query = `
{
moviesAggregate(where: {testString: "${testString}"}) {
${Movie.operations.aggregate}(where: {testString: "${testString}"}) {
runningTime {
min
max
Expand All @@ -229,7 +215,7 @@ describe("aggregations-top_level-duration", () => {

expect(gqlResult.errors).toBeUndefined();

expect((gqlResult.data as any).moviesAggregate).toEqual({
expect((gqlResult.data as any)[Movie.operations.aggregate]).toEqual({
runningTime: {
min: minDuration.toString(),
max: maxDuration.toString(),
Expand Down
Loading

0 comments on commit 17a74f2

Please sign in to comment.