mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add remaining test cases
This commit is contained in:
@@ -4,11 +4,11 @@ import { UnoptimizedInMemoryRepository } from "../../src/repositories/Unoptimize
|
|||||||
import { fetchSystemDataSuccessfulResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse";
|
import { fetchSystemDataSuccessfulResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse";
|
||||||
import { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
|
import { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
|
||||||
import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse";
|
import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse";
|
||||||
import { ISystem } from "../../src/entities/entities";
|
|
||||||
import {
|
import {
|
||||||
fetchStopAndPolylineDataSuccessfulResponse
|
fetchStopAndPolylineDataSuccessfulResponse
|
||||||
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
|
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
|
||||||
import { generateMockSystems } from "../generators";
|
import { generateMockStops, generateMockSystems } from "../generators";
|
||||||
|
import { IStop } from "../../src/entities/entities";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to update behavior of the global `fetch` function.
|
* Function to update behavior of the global `fetch` function.
|
||||||
@@ -111,7 +111,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
});
|
});
|
||||||
|
|
||||||
describe("fetchAndUpdateRouteDataForSystemId", () => {
|
describe("fetchAndUpdateRouteDataForSystemId", () => {
|
||||||
it("updates route data in repository if there are systems and response received", async () => {
|
it("updates route data in repository if response received", async () => {
|
||||||
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
|
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
|
||||||
|
|
||||||
await loader.fetchAndUpdateRouteDataForSystemId("263");
|
await loader.fetchAndUpdateRouteDataForSystemId("263");
|
||||||
@@ -150,7 +150,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
})
|
})
|
||||||
|
|
||||||
describe("fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId", () => {
|
describe("fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId", () => {
|
||||||
it("updates stop and polyline data if there are systems and response received", async () => {
|
it("updates stop and polyline data if response received", async () => {
|
||||||
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);
|
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);
|
||||||
|
|
||||||
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
|
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
|
||||||
@@ -180,23 +180,78 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
})
|
})
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetchAndUpdateShuttleDataForExistingSystems", () => {
|
describe("fetchAndUpdateShuttleDataForExistingSystemsInRepository", () => {
|
||||||
it("updates shuttle data in repository if there are systems and response received", async () => {
|
it("calls fetchAndUpdateShuttleDataForSystemId for every system", async () => {
|
||||||
|
const spy = jest.spyOn(loader, "fetchAndUpdateShuttleDataForSystemId");
|
||||||
|
|
||||||
|
const systems = generateMockSystems();
|
||||||
|
await Promise.all(systems.map(async (system) => {
|
||||||
|
await loader.repository.addOrUpdateSystem(system);
|
||||||
|
}))
|
||||||
|
|
||||||
|
await loader.fetchAndUpdateShuttleDataForExistingSystemsInRepository();
|
||||||
|
|
||||||
|
expect(spy.mock.calls.length).toBe(systems.length);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetchAndUpdateShuttleDataForSystemId", () => {
|
||||||
|
it("updates shuttle data in repository if response received", async () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws the correct error if the API response contains no data", async () => {
|
it("throws the correct error if the API response contains no data", async () => {
|
||||||
|
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||||
|
|
||||||
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
|
await loader.fetchAndUpdateShuttleDataForSystemId("263");
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetchAndUpdateEtaDataForExistingStopsForSystemsInRepository", () => {
|
||||||
|
it("calls fetchAndUpdateEtaDataFoExistingStopsForSystemId for every system in repository", async () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetchAndUpdateEtaDataForExistingSystems", () => {
|
describe("fetchAndUpdateEtaDataForExistingStopsForSystemId", () => {
|
||||||
it("updates shuttle data in repository if there are systems and response received", async () => {
|
it("calls fetchAndUpdateEtaDataForStopId for every stop in repository", async () => {
|
||||||
|
// const systems = generateMockSystems();
|
||||||
|
// await Promise.all(systems.map(async (system) => {
|
||||||
|
// await loader.repository.addOrUpdateSystem(system);
|
||||||
|
// }));
|
||||||
|
//
|
||||||
|
// const stop: IStop = {
|
||||||
|
// coordinates: {
|
||||||
|
// latitude: 1,
|
||||||
|
// longitude: 1,
|
||||||
|
// },
|
||||||
|
// id: "1",
|
||||||
|
// name: "Chapman Court",
|
||||||
|
// systemId: "263",
|
||||||
|
// };
|
||||||
|
// await loader.repository.addOrUpdateStop(stop);
|
||||||
|
const stops = generateMockStops();
|
||||||
|
await Promise.all(stops.map(async (stop) => {
|
||||||
|
await loader.repository.addOrUpdateStop(stop);
|
||||||
|
}))
|
||||||
|
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetchAndUpdateEtaDataForStopId", () => {
|
||||||
|
it("updates ETA data for stop id if response received", async () => {
|
||||||
|
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws the correct error if the API response contains no data", async () => {
|
it("throws the correct error if the API response contains no data", async () => {
|
||||||
|
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||||
|
|
||||||
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
|
await loader.fetchAndUpdateEtaDataForStopId("263");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user