diff --git a/test/resolvers/SystemResolverTests.test.ts b/test/resolvers/SystemResolverTests.test.ts index c098aff..12f1543 100644 --- a/test/resolvers/SystemResolverTests.test.ts +++ b/test/resolvers/SystemResolverTests.test.ts @@ -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(); }); });