mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
88 lines
2.6 KiB
TypeScript
88 lines
2.6 KiB
TypeScript
import { beforeEach, describe, expect, it } from "@jest/globals";
|
|
import { setupTestServerContext, setupTestServerHolder } from "../testHelpers/apolloTestServerHelpers";
|
|
import { IEta, IShuttle, IStop, IPassioSystem } from "../../src/entities/entities";
|
|
import {
|
|
addMockEtaToRepository, addMockShuttleToRepository,
|
|
addMockStopToRepository,
|
|
} from "../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) {
|
|
const response = await holder.testServer.executeOperation({
|
|
query,
|
|
variables: {
|
|
systemId: context.systems[0].id,
|
|
shuttleId: mockShuttle.id,
|
|
},
|
|
}, {
|
|
contextValue: context
|
|
|
|
});
|
|
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);
|
|
});
|
|
});
|
|
});
|