mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +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 { setUpTestServer } from "../testHelpers/apolloSetupHelpers";
|
||||||
import { generateMockRoutes, generateMockShuttles, generateMockStops } from "../generators";
|
import { generateMockRoutes, generateMockShuttles, generateMockStops } from "../generators";
|
||||||
import {
|
import {
|
||||||
addMockRouteToRepository,
|
addMockRouteToRepository, addMockShuttleToRepository,
|
||||||
addMockStopToRepository,
|
addMockStopToRepository,
|
||||||
addMockSystemToRepository
|
addMockSystemToRepository
|
||||||
} from "../testHelpers/repositorySetupHelpers";
|
} from "../testHelpers/repositorySetupHelpers";
|
||||||
@@ -233,27 +233,69 @@ describe("SystemResolvers", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("shuttle", () => {
|
describe("shuttle", () => {
|
||||||
const query = `
|
async function getResponseForShuttleQuery(shuttleId: string) {
|
||||||
query GetSystemShuttle($systemId: ID!, $shuttleId: ID!) {
|
const query = `
|
||||||
system(id: $systemId) {
|
query GetSystemShuttle($systemId: ID!, $shuttleId: ID!) {
|
||||||
shuttle(id: $shuttleId) {
|
system(id: $systemId) {
|
||||||
id
|
shuttle(id: $shuttleId) {
|
||||||
name
|
id
|
||||||
|
name
|
||||||
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
`;
|
||||||
|
|
||||||
|
return await testServer.executeOperation({
|
||||||
|
query,
|
||||||
|
variables: {
|
||||||
|
systemId: mockSystem.id,
|
||||||
|
shuttleId: shuttleId,
|
||||||
|
}
|
||||||
|
}, {
|
||||||
|
contextValue: {
|
||||||
|
repository,
|
||||||
|
}
|
||||||
|
});
|
||||||
}
|
}
|
||||||
`;
|
|
||||||
|
|
||||||
it("gets the shuttle with the correct id", async () => {
|
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 () => {
|
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 () => {
|
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