mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
90 lines
2.6 KiB
TypeScript
90 lines
2.6 KiB
TypeScript
import { beforeEach, describe, expect, it } from "@jest/globals";
|
|
import { setupTestServerContext } from "../testHelpers/apolloTestServerHelpers";
|
|
import { IEta, IShuttle, IStop, ISystem } from "../../src/entities/entities";
|
|
import {
|
|
addMockEtaToRepository, addMockShuttleToRepository,
|
|
addMockStopToRepository,
|
|
addMockSystemToRepository
|
|
} from "../testHelpers/repositorySetupHelpers";
|
|
import assert = require("node:assert");
|
|
|
|
describe("EtaResolvers", () => {
|
|
const context = setupTestServerContext();
|
|
|
|
let mockSystem: ISystem;
|
|
let mockShuttle: IShuttle;
|
|
let mockStop: IStop;
|
|
let expectedEta: IEta;
|
|
|
|
beforeEach(async () => {
|
|
mockSystem = await addMockSystemToRepository(context.repository);
|
|
mockShuttle = await addMockShuttleToRepository(context.repository, mockSystem.id);
|
|
mockStop = await addMockStopToRepository(context.repository, mockSystem.id);
|
|
expectedEta = await addMockEtaToRepository(context.repository, mockStop.id, mockShuttle.id);
|
|
});
|
|
|
|
async function getResponseForEtaQuery(query: string) {
|
|
const response = await context.testServer.executeOperation({
|
|
query,
|
|
variables: {
|
|
systemId: mockSystem.id,
|
|
shuttleId: mockShuttle.id,
|
|
},
|
|
}, {
|
|
contextValue: {
|
|
repository: context.repository,
|
|
}
|
|
});
|
|
return response;
|
|
}
|
|
|
|
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);
|
|
});
|
|
});
|
|
}); |