add test case for fetch existing systems method

This commit is contained in:
2025-01-22 14:43:09 -08:00
parent 9fda898ecb
commit 1fea82179a

View File

@@ -4,6 +4,7 @@ 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";
/**
* Function to update behavior of the global `fetch` function.
@@ -79,9 +80,28 @@ describe("ApiBasedRepositoryLoader", () => {
describe("fetchAndUpdateRouteDataForExistingSystemsInRepository", () => {
// TODO
// Add a test case to ensure that fetchAndUpdateRouteDataForSystemId
// was called for every available system ID
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",
}
];
await Promise.all(systems.map(async (system) => {
await loader.repository.addOrUpdateSystem(system);
}));
await loader.fetchAndUpdateRouteDataForExistingSystemsInRepository();
expect(spy.mock.calls.length).toBe(2);
});
});
describe("fetchAndUpdateRouteDataForSystemId", () => {