mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
Restore the pruning test for shuttles
This commit is contained in:
@@ -5,7 +5,7 @@ import { fetchRouteDataSuccessfulResponse } from "../../../../testHelpers/jsonSn
|
||||
import {
|
||||
fetchStopAndPolylineDataSuccessfulResponse
|
||||
} from "../../../../testHelpers/jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
|
||||
import { generateMockRoutes, generateMockStops } from "../../../../testHelpers/mockDataGenerators";
|
||||
import { generateMockRoutes, generateMockShuttles, generateMockStops } from "../../../../testHelpers/mockDataGenerators";
|
||||
import {
|
||||
fetchShuttleDataSuccessfulResponse
|
||||
} from "../../../../testHelpers/jsonSnapshots/fetchShuttleData/fetchShuttleDataSuccessfulResponse";
|
||||
@@ -206,6 +206,49 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
||||
expect(shuttles.length).toEqual(0);
|
||||
});
|
||||
|
||||
it("prunes shuttles correctly", async () => {
|
||||
const distanceMiles = 1;
|
||||
loader = new ApiBasedShuttleRepositoryLoader(
|
||||
"263",
|
||||
"1",
|
||||
new UnoptimizedInMemoryShuttleRepository(),
|
||||
distanceMiles,
|
||||
);
|
||||
|
||||
// Add mock shuttles to repository (these should be pruned)
|
||||
const shuttlesToPrune = generateMockShuttles();
|
||||
await Promise.all(shuttlesToPrune.map(async (shuttle) => {
|
||||
shuttle.systemId = systemId;
|
||||
await loader.repository.addOrUpdateShuttle(shuttle);
|
||||
}));
|
||||
|
||||
const routes = generateMockRoutesWithPolylineCoordinates();
|
||||
await addMockRoutes(routes);
|
||||
|
||||
const modifiedSuccessfulResponse = getMockJsonResponseMatchingRouteAndCoordinates(
|
||||
routes[0],
|
||||
"-117.86187",
|
||||
"33.78792"
|
||||
);
|
||||
|
||||
updateGlobalFetchMockJson(modifiedSuccessfulResponse);
|
||||
|
||||
// Update shuttles from API
|
||||
await loader.updateShuttleDataForSystemBasedOnProximityToRoutes();
|
||||
|
||||
// Old shuttles should be pruned, only API shuttles should remain
|
||||
const shuttles = await loader.repository.getShuttles();
|
||||
const busesInResponse = Object.values(modifiedSuccessfulResponse.buses);
|
||||
|
||||
expect(shuttles.length).toEqual(busesInResponse.length);
|
||||
|
||||
// Verify none of the original mock shuttles remain
|
||||
shuttlesToPrune.forEach((originalShuttle) => {
|
||||
const foundShuttle = shuttles.find(s => s.id === originalShuttle.id);
|
||||
expect(foundShuttle).toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
it("throws the correct error if the API response contains no data", async () => {
|
||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user