mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
implement parkingStructure tests
This commit is contained in:
@@ -370,12 +370,66 @@ describe("SystemResolvers", () => {
|
||||
});
|
||||
|
||||
describe("parkingStructure", () => {
|
||||
it("returns the correct parking structure given the id", async () => {
|
||||
async function getResponseForParkingStructureQuery(parkingStructureId: string) {
|
||||
const query = `
|
||||
query GetParkingStructureBySystem($systemId: ID!, $parkingStructureId: ID!) {
|
||||
system(id: $systemId) {
|
||||
parkingStructure(id: $parkingStructureId) {
|
||||
name
|
||||
id
|
||||
capacity
|
||||
spotsAvailable
|
||||
coordinates {
|
||||
latitude
|
||||
longitude
|
||||
}
|
||||
address
|
||||
}
|
||||
}
|
||||
}
|
||||
`;
|
||||
|
||||
return await holder.testServer.executeOperation({
|
||||
query,
|
||||
variables: {
|
||||
systemId: mockSystem.id,
|
||||
parkingStructureId,
|
||||
}
|
||||
}, {
|
||||
contextValue: context
|
||||
|
||||
});
|
||||
}
|
||||
|
||||
it("returns the correct parking structure given the id", async () => {
|
||||
const generatedParkingStructures = generateParkingStructures();
|
||||
await Promise.all(generatedParkingStructures.map(async (structure) => {
|
||||
await context.systems[0].parkingRepository?.addOrUpdateParkingStructure(structure);
|
||||
}));
|
||||
const expectedParkingStructure = generatedParkingStructures[1];
|
||||
|
||||
const response = await getResponseForParkingStructureQuery(expectedParkingStructure.id);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
const parkingStructure = (response.body.singleResult.data as any).system.parkingStructure;
|
||||
expect(parkingStructure).toEqual(expectedParkingStructure);
|
||||
});
|
||||
|
||||
it("returns null if there is no matching parking structure", async () => {
|
||||
const generatedParkingStructures = generateParkingStructures();
|
||||
await Promise.all(generatedParkingStructures.map(async (structure) => {
|
||||
await context.systems[0].parkingRepository?.addOrUpdateParkingStructure(structure);
|
||||
}));
|
||||
|
||||
const nonexistentId = generatedParkingStructures[0].id + "12345";
|
||||
|
||||
const response = await getResponseForParkingStructureQuery(nonexistentId);
|
||||
|
||||
assert(response.body.kind === "single");
|
||||
expect(response.body.singleResult.errors).toBeUndefined();
|
||||
const parkingStructure = (response.body.singleResult.data as any).system.parkingStructure;
|
||||
expect(parkingStructure).toBeNull();
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user