add pruning checks for other data models

This commit is contained in:
2025-01-22 21:21:44 -08:00
parent e7e513b0b1
commit eb0882b2e5

View File

@@ -7,7 +7,14 @@ import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteDat
import {
fetchStopAndPolylineDataSuccessfulResponse
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
import { generateMockStops, generateMockSystems } from "../generators";
import {
generateMockEtas,
generateMockOrderedStops,
generateMockRoutes,
generateMockShuttles,
generateMockStops,
generateMockSystems
} from "../generators";
import { IStop } from "../../src/entities/entities";
import {
fetchShuttleDataSuccessfulResponse
@@ -89,12 +96,23 @@ describe("ApiBasedRepositoryLoader", () => {
});
describe("fetchAndUpdateRouteDataForSystemId", () => {
const systemId = "263";
it("updates route data in repository if response received", async () => {
// Arrange
// Test pruning
const routesToPrune = generateMockRoutes();
await Promise.all(routesToPrune.map(async (route) => {
route.systemId = systemId;
await loader.repository.addOrUpdateRoute(route);
}));
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
await loader.fetchAndUpdateRouteDataForSystemId("263");
// Act
await loader.fetchAndUpdateRouteDataForSystemId(systemId);
const routes = await loader.repository.getRoutesBySystemId("263");
// Assert
const routes = await loader.repository.getRoutesBySystemId(systemId);
expect(routes.length).toEqual(fetchRouteDataSuccessfulResponse.all.length)
});
@@ -106,7 +124,7 @@ describe("ApiBasedRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateRouteDataForSystemId("263");
await loader.fetchAndUpdateRouteDataForSystemId(systemId);
});
});
});
@@ -128,14 +146,23 @@ describe("ApiBasedRepositoryLoader", () => {
})
describe("fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId", () => {
const systemId = "263";
it("updates stop and polyline data if response received", async () => {
// Arrange
// Test pruning of stops only
const stopsToPrune = generateMockStops();
await Promise.all(stopsToPrune.map(async (stop) => {
stop.systemId = systemId;
await loader.repository.addOrUpdateStop(stop);
}));
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
await loader.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId("263");
await loader.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId);
const stops = await loader.repository.getStopsBySystemId("263");
const stops = await loader.repository.getStopsBySystemId(systemId);
expect(stops.length).toEqual(stopsArray.length);
await Promise.all(stops.map(async (stop) => {
@@ -143,7 +170,7 @@ describe("ApiBasedRepositoryLoader", () => {
expect(orderedStops.length).toBeGreaterThan(0);
}));
const routes = await loader.repository.getRoutesBySystemId("263");
const routes = await loader.repository.getRoutesBySystemId(systemId);
routes.forEach((route) => {
expect(route.polylineCoordinates.length).toBeGreaterThan(0);
});
@@ -153,7 +180,7 @@ describe("ApiBasedRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId("263");
await loader.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId);
});
})
});
@@ -174,13 +201,20 @@ describe("ApiBasedRepositoryLoader", () => {
});
describe("fetchAndUpdateShuttleDataForSystemId", () => {
const systemId = "263";
it("updates shuttle data in repository if response received", async () => {
const shuttlesToPrune = generateMockShuttles();
await Promise.all(shuttlesToPrune.map(async (shuttle) => {
shuttle.systemId = systemId;
await loader.repository.addOrUpdateShuttle(shuttle);
}))
updateGlobalFetchMockJson(fetchShuttleDataSuccessfulResponse);
const busesInResponse = Object.values(fetchShuttleDataSuccessfulResponse.buses);
await loader.fetchAndUpdateShuttleDataForSystemId("263");
await loader.fetchAndUpdateShuttleDataForSystemId(systemId);
const shuttles = await loader.repository.getShuttlesBySystemId("263");
const shuttles = await loader.repository.getShuttlesBySystemId(systemId);
expect(shuttles.length).toEqual(busesInResponse.length);
});
@@ -189,7 +223,7 @@ describe("ApiBasedRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateShuttleDataForSystemId("263");
await loader.fetchAndUpdateShuttleDataForSystemId(systemId);
});
});
});
@@ -229,9 +263,15 @@ describe("ApiBasedRepositoryLoader", () => {
});
describe("fetchAndUpdateEtaDataForStopId", () => {
it("updates ETA data for stop id if response received", async () => {
updateGlobalFetchMockJson(fetchEtaDataSuccessfulResponse);
const stopId = "177666";
it("updates ETA data for stop id if response received", async () => {
const etasToPrune = generateMockEtas();
await Promise.all(etasToPrune.map(async (eta) => {
eta.stopId = stopId;
await loader.repository.addOrUpdateEta(eta);
}))
updateGlobalFetchMockJson(fetchEtaDataSuccessfulResponse);
// @ts-ignore
const etasFromResponse = fetchEtaDataSuccessfulResponse.ETAs[stopId]