add test for fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository

This commit is contained in:
2025-01-22 15:03:29 -08:00
parent 81d0bb9e01
commit 95f2181b1c
3 changed files with 23 additions and 15 deletions

View File

@@ -8,6 +8,7 @@ import { ISystem } from "../../src/entities/entities";
import {
fetchStopAndPolylineDataSuccessfulResponse
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
import { generateMockSystems } from "../generators";
/**
* Function to update behavior of the global `fetch` function.
@@ -97,16 +98,7 @@ describe("ApiBasedRepositoryLoader", () => {
test("calls fetchAndUpdateRouteDataForSystemId for all systems in repository", async () => {
const spy = jest.spyOn(loader, "fetchAndUpdateRouteDataForSystemId");
const systems: ISystem[] = [
{
name: "Chapman University",
id: "1",
},
{
name: "City of Monterey Park",
id: "2",
}
];
const systems = generateMockSystems();
await Promise.all(systems.map(async (system) => {
await loader.repository.addOrUpdateSystem(system);
@@ -114,7 +106,7 @@ describe("ApiBasedRepositoryLoader", () => {
await loader.fetchAndUpdateRouteDataForExistingSystemsInRepository();
expect(spy.mock.calls.length).toBe(2);
expect(spy.mock.calls.length).toBe(systems.length);
});
});
@@ -141,6 +133,22 @@ describe("ApiBasedRepositoryLoader", () => {
});
});
describe("fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository", () => {
it("calls fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId for every system", async () => {
const spy = jest.spyOn(loader, "fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId");
const systems = generateMockSystems();
await Promise.all(systems.map(async (system) => {
await loader.repository.addOrUpdateSystem(system);
}));
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository();
expect(spy.mock.calls.length).toBe(systems.length);
});
})
describe("fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId", () => {
it("updates stop and polyline data if there are systems and response received", async () => {
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);