mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +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 { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
|
||||
import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse";
|
||||
import { ISystem } from "../../src/entities/entities";
|
||||
import {
|
||||
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.
|
||||
@@ -111,7 +111,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
||||
});
|
||||
|
||||
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);
|
||||
|
||||
await loader.fetchAndUpdateRouteDataForSystemId("263");
|
||||
@@ -150,7 +150,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
||||
})
|
||||
|
||||
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);
|
||||
|
||||
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
|
||||
@@ -180,23 +180,78 @@ describe("ApiBasedRepositoryLoader", () => {
|
||||
})
|
||||
});
|
||||
|
||||
describe("fetchAndUpdateShuttleDataForExistingSystems", () => {
|
||||
it("updates shuttle data in repository if there are systems and response received", async () => {
|
||||
describe("fetchAndUpdateShuttleDataForExistingSystemsInRepository", () => {
|
||||
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 () => {
|
||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||
|
||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||
await loader.fetchAndUpdateShuttleDataForSystemId("263");
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchAndUpdateEtaDataForExistingStopsForSystemsInRepository", () => {
|
||||
it("calls fetchAndUpdateEtaDataFoExistingStopsForSystemId for every system in repository", async () => {
|
||||
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchAndUpdateEtaDataForExistingSystems", () => {
|
||||
it("updates shuttle data in repository if there are systems and response received", async () => {
|
||||
describe("fetchAndUpdateEtaDataForExistingStopsForSystemId", () => {
|
||||
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 () => {
|
||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||
|
||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||
await loader.fetchAndUpdateEtaDataForStopId("263");
|
||||
});
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user