mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Move all tests to subdirectories underneath code to be tested
This commit is contained in:
87
src/resolvers/__tests__/EtaResolverTests.test.ts
Normal file
87
src/resolvers/__tests__/EtaResolverTests.test.ts
Normal file
@@ -0,0 +1,87 @@
|
||||
import { beforeEach, describe, expect, it } from "@jest/globals";
|
||||
import { setupTestServerContext, setupTestServerHolder } from "../../../test/testHelpers/apolloTestServerHelpers";
|
||||
import { IEta, IShuttle, IStop } from "../../entities/ShuttleRepositoryEntities";
|
||||
import {
|
||||
addMockEtaToRepository,
|
||||
addMockShuttleToRepository,
|
||||
addMockStopToRepository,
|
||||
} from "../../../test/testHelpers/repositorySetupHelpers";
|
||||
import assert = require("node:assert");
|
||||
|
||||
describe("EtaResolvers", () => {
|
||||
const holder = setupTestServerHolder();
|
||||
const context = setupTestServerContext();
|
||||
|
||||
let mockShuttle: IShuttle;
|
||||
let mockStop: IStop;
|
||||
let expectedEta: IEta;
|
||||
|
||||
beforeEach(async () => {
|
||||
mockShuttle = await addMockShuttleToRepository(context.systems[0].shuttleRepository, context.systems[0].id);
|
||||
mockStop = await addMockStopToRepository(context.systems[0].shuttleRepository, context.systems[0].id);
|
||||
expectedEta = await addMockEtaToRepository(context.systems[0].shuttleRepository, mockStop.id, mockShuttle.id);
|
||||
});
|
||||
|
||||
async function getResponseForEtaQuery(query: string) {
|
||||
return await holder.testServer.executeOperation({
|
||||
query,
|
||||
variables: {
|
||||
systemId: context.systems[0].id,
|
||||
shuttleId: mockShuttle.id,
|
||||
},
|
||||
}, {
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
describe("stop", () => {
|
||||
const query = `
|
||||
query GetETAStop($systemId: ID!, $shuttleId: ID!) {
|
||||
system(id: $systemId) {
|
||||
shuttle(id: $shuttleId) {
|
||||
etas {
|
||||
stop {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
it("returns the associated stop if it exists", async () => {
|
||||
const response = await getResponseForEtaQuery(query);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
const eta = (response.body.singleResult.data?.system as any).shuttle.etas[0];
|
||||
expect(eta.stop.id).toEqual(expectedEta.stopId);
|
||||
});
|
||||
});
|
||||
|
||||
describe("shuttle", () => {
|
||||
const query = `
|
||||
query GetETAShuttle($systemId: ID!, $shuttleId: ID!) {
|
||||
system(id: $systemId) {
|
||||
shuttle(id: $shuttleId) {
|
||||
etas {
|
||||
shuttle {
|
||||
id
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
it("returns the associated shuttle if it exists", async () => {
|
||||
const response = await getResponseForEtaQuery(query);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
const eta = (response.body.singleResult.data?.system as any).shuttle.etas[0];
|
||||
expect(eta.shuttle.id).toEqual(expectedEta.shuttleId);
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user