mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add shuttle tests
This commit is contained in:
@@ -5,7 +5,7 @@ import { UnoptimizedInMemoryRepository } from "../../src/repositories/Unoptimize
|
||||
import { setUpTestServer } from "../testHelpers/apolloSetupHelpers";
|
||||
import { generateMockRoutes, generateMockShuttles, generateMockStops } from "../generators";
|
||||
import {
|
||||
addMockRouteToRepository,
|
||||
addMockRouteToRepository, addMockShuttleToRepository,
|
||||
addMockStopToRepository,
|
||||
addMockSystemToRepository
|
||||
} from "../testHelpers/repositorySetupHelpers";
|
||||
@@ -233,27 +233,69 @@ describe("SystemResolvers", () => {
|
||||
});
|
||||
|
||||
describe("shuttle", () => {
|
||||
const query = `
|
||||
query GetSystemShuttle($systemId: ID!, $shuttleId: ID!) {
|
||||
system(id: $systemId) {
|
||||
shuttle(id: $shuttleId) {
|
||||
id
|
||||
name
|
||||
async function getResponseForShuttleQuery(shuttleId: string) {
|
||||
const query = `
|
||||
query GetSystemShuttle($systemId: ID!, $shuttleId: ID!) {
|
||||
system(id: $systemId) {
|
||||
shuttle(id: $shuttleId) {
|
||||
id
|
||||
name
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
return await testServer.executeOperation({
|
||||
query,
|
||||
variables: {
|
||||
systemId: mockSystem.id,
|
||||
shuttleId: shuttleId,
|
||||
}
|
||||
}, {
|
||||
contextValue: {
|
||||
repository,
|
||||
}
|
||||
});
|
||||
}
|
||||
`;
|
||||
|
||||
it("gets the shuttle with the correct id", async () => {
|
||||
const mockShuttle = await addMockShuttleToRepository(repository, mockSystem.id);
|
||||
|
||||
const response = await getResponseForShuttleQuery(mockShuttle.id);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
const shuttle = (response.body.singleResult.data as any).system.shuttle;
|
||||
expect(shuttle.id).toEqual(mockShuttle.id);
|
||||
expect(shuttle.name).toEqual(mockShuttle.name);
|
||||
});
|
||||
|
||||
it("returns null if the shuttle isn't associated with the system", async () => {
|
||||
const updatedSystem = {
|
||||
...mockSystem,
|
||||
id: "2",
|
||||
}
|
||||
await repository.addOrUpdateSystem(updatedSystem);
|
||||
|
||||
const mockShuttle = await addMockShuttleToRepository(repository, updatedSystem.id);
|
||||
|
||||
const response = await getResponseForShuttleQuery(mockShuttle.id);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
|
||||
const shuttle = (response.body.singleResult.data as any).system.shuttle;
|
||||
expect(shuttle).toBeNull();
|
||||
});
|
||||
|
||||
it("returns null if there is no shuttle", async () => {
|
||||
const response = await getResponseForShuttleQuery("nonexistent-shuttle-id");
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
|
||||
const shuttle = (response.body.singleResult.data as any).system.shuttle;
|
||||
expect(shuttle).toBeNull();
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user