mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add tests for etas resolver
This commit is contained in:
@@ -22,6 +22,32 @@ describe("ShuttleResolvers", () => {
|
|||||||
repository = new UnoptimizedInMemoryRepository();
|
repository = new UnoptimizedInMemoryRepository();
|
||||||
});
|
});
|
||||||
|
|
||||||
|
let mockSystem: ISystem;
|
||||||
|
let mockShuttle: IShuttle;
|
||||||
|
|
||||||
|
beforeEach(async () => {
|
||||||
|
const mockSystems = generateMockSystems();
|
||||||
|
mockSystem = mockSystems[0];
|
||||||
|
mockSystem.id = "1";
|
||||||
|
await repository.addOrUpdateSystem(mockSystem);
|
||||||
|
|
||||||
|
const mockShuttles = generateMockShuttles();
|
||||||
|
mockShuttle = mockShuttles[0];
|
||||||
|
mockShuttle.systemId = mockSystem.id;
|
||||||
|
mockShuttle.id = "1";
|
||||||
|
await repository.addOrUpdateShuttle(mockShuttle);
|
||||||
|
});
|
||||||
|
|
||||||
|
|
||||||
|
async function addMockEtas(shuttleId: string) {
|
||||||
|
const etas = generateMockEtas();
|
||||||
|
await Promise.all(etas.map(async (eta) => {
|
||||||
|
eta.shuttleId = shuttleId;
|
||||||
|
await repository.addOrUpdateEta(eta);
|
||||||
|
}));
|
||||||
|
return etas;
|
||||||
|
}
|
||||||
|
|
||||||
describe("eta", () => {
|
describe("eta", () => {
|
||||||
const query = `
|
const query = `
|
||||||
query GetShuttleETAs($systemId: ID!, $shuttleId: ID!, $stopId: ID!)
|
query GetShuttleETAs($systemId: ID!, $shuttleId: ID!, $stopId: ID!)
|
||||||
@@ -35,29 +61,8 @@ describe("ShuttleResolvers", () => {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
`
|
`
|
||||||
let mockSystem: ISystem;
|
|
||||||
let mockShuttle: IShuttle;
|
|
||||||
|
|
||||||
beforeEach(async () => {
|
|
||||||
// Arrange
|
|
||||||
const mockSystems = generateMockSystems();
|
|
||||||
mockSystem = mockSystems[0];
|
|
||||||
mockSystem.id = "1";
|
|
||||||
await repository.addOrUpdateSystem(mockSystem);
|
|
||||||
|
|
||||||
const mockShuttles = generateMockShuttles();
|
|
||||||
mockShuttle = mockShuttles[0];
|
|
||||||
mockShuttle.systemId = mockSystem.id;
|
|
||||||
mockShuttle.id = "1";
|
|
||||||
await repository.addOrUpdateShuttle(mockShuttle);
|
|
||||||
});
|
|
||||||
|
|
||||||
it("returns ETA data for stop ID if exists", async () => {
|
it("returns ETA data for stop ID if exists", async () => {
|
||||||
const etas = generateMockEtas();
|
const etas = await addMockEtas(mockShuttle.id);
|
||||||
await Promise.all(etas.map(async (eta) => {
|
|
||||||
eta.shuttleId = mockShuttle.id;
|
|
||||||
await repository.addOrUpdateEta(eta);
|
|
||||||
}));
|
|
||||||
|
|
||||||
const mockEta = etas[1];
|
const mockEta = etas[1];
|
||||||
|
|
||||||
@@ -101,4 +106,58 @@ describe("ShuttleResolvers", () => {
|
|||||||
expect((response.body.singleResult.data as any).system.shuttle.eta).toBeNull();
|
expect((response.body.singleResult.data as any).system.shuttle.eta).toBeNull();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("etas", () => {
|
||||||
|
const query = `
|
||||||
|
query GetShuttleETAs($systemId: ID!, $shuttleId: ID!)
|
||||||
|
{
|
||||||
|
system(id: $systemId) {
|
||||||
|
shuttle(id: $shuttleId) {
|
||||||
|
etas {
|
||||||
|
secondsRemaining
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
}
|
||||||
|
`
|
||||||
|
|
||||||
|
it("returns associated ETAs if they exist for the shuttle", async () => {
|
||||||
|
const etas = await addMockEtas(mockShuttle.id);
|
||||||
|
|
||||||
|
const response = await testServer.executeOperation({
|
||||||
|
query,
|
||||||
|
variables: {
|
||||||
|
systemId: mockSystem.id,
|
||||||
|
shuttleId: mockShuttle.id,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
contextValue: {
|
||||||
|
repository,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(response.body.kind === "single");
|
||||||
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
expect((response.body.singleResult.data as any).system.shuttle.etas).toHaveLength(etas.length);
|
||||||
|
});
|
||||||
|
|
||||||
|
it("returns empty array if no ETAs exist", async () => {
|
||||||
|
const response = await testServer.executeOperation({
|
||||||
|
query,
|
||||||
|
variables: {
|
||||||
|
systemId: mockSystem.id,
|
||||||
|
shuttleId: mockShuttle.id,
|
||||||
|
},
|
||||||
|
}, {
|
||||||
|
contextValue: {
|
||||||
|
repository,
|
||||||
|
}
|
||||||
|
});
|
||||||
|
|
||||||
|
assert(response.body.kind === "single");
|
||||||
|
expect(response.body.singleResult.errors).toBeUndefined();
|
||||||
|
expect((response.body.singleResult.data as any).system.shuttle.etas).toHaveLength(0);
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user