mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
add test for fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository
This commit is contained in:
@@ -98,9 +98,7 @@ export class ApiBasedRepositoryLoader {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems() {
|
public async fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository() {
|
||||||
// Fetch from the API
|
|
||||||
// Pass JSON output into two different methods to update repository
|
|
||||||
const systems = await this.repository.getSystems();
|
const systems = await this.repository.getSystems();
|
||||||
await Promise.all(systems.map(async (system: ISystem) => {
|
await Promise.all(systems.map(async (system: ISystem) => {
|
||||||
await this.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(system.id);
|
await this.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(system.id);
|
||||||
@@ -108,6 +106,8 @@ export class ApiBasedRepositoryLoader {
|
|||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId: string) {
|
public async fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId(systemId: string) {
|
||||||
|
// Fetch from the API
|
||||||
|
// Pass JSON output into two different methods to update repository
|
||||||
const params = {
|
const params = {
|
||||||
getStops: "2",
|
getStops: "2",
|
||||||
};
|
};
|
||||||
|
|||||||
@@ -52,7 +52,7 @@ export class TimedApiBasedRepositoryLoader extends ApiBasedRepositoryLoader {
|
|||||||
await this.repository.clearRouteData();
|
await this.repository.clearRouteData();
|
||||||
await this.fetchAndUpdateRouteDataForExistingSystemsInRepository();
|
await this.fetchAndUpdateRouteDataForExistingSystemsInRepository();
|
||||||
await this.repository.clearStopData();
|
await this.repository.clearStopData();
|
||||||
await this.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems();
|
await this.fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystemsInRepository();
|
||||||
await this.repository.clearShuttleData();
|
await this.repository.clearShuttleData();
|
||||||
await this.fetchAndUpdateShuttleDataForExistingSystems();
|
await this.fetchAndUpdateShuttleDataForExistingSystems();
|
||||||
await this.repository.clearEtaData();
|
await this.repository.clearEtaData();
|
||||||
|
|||||||
@@ -8,6 +8,7 @@ import { ISystem } from "../../src/entities/entities";
|
|||||||
import {
|
import {
|
||||||
fetchStopAndPolylineDataSuccessfulResponse
|
fetchStopAndPolylineDataSuccessfulResponse
|
||||||
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
|
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
|
||||||
|
import { generateMockSystems } from "../generators";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to update behavior of the global `fetch` function.
|
* Function to update behavior of the global `fetch` function.
|
||||||
@@ -97,16 +98,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
test("calls fetchAndUpdateRouteDataForSystemId for all systems in repository", async () => {
|
test("calls fetchAndUpdateRouteDataForSystemId for all systems in repository", async () => {
|
||||||
const spy = jest.spyOn(loader, "fetchAndUpdateRouteDataForSystemId");
|
const spy = jest.spyOn(loader, "fetchAndUpdateRouteDataForSystemId");
|
||||||
|
|
||||||
const systems: ISystem[] = [
|
const systems = generateMockSystems();
|
||||||
{
|
|
||||||
name: "Chapman University",
|
|
||||||
id: "1",
|
|
||||||
},
|
|
||||||
{
|
|
||||||
name: "City of Monterey Park",
|
|
||||||
id: "2",
|
|
||||||
}
|
|
||||||
];
|
|
||||||
|
|
||||||
await Promise.all(systems.map(async (system) => {
|
await Promise.all(systems.map(async (system) => {
|
||||||
await loader.repository.addOrUpdateSystem(system);
|
await loader.repository.addOrUpdateSystem(system);
|
||||||
@@ -114,7 +106,7 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
|
|
||||||
await loader.fetchAndUpdateRouteDataForExistingSystemsInRepository();
|
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", () => {
|
describe("fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId", () => {
|
||||||
it("updates stop and polyline data if there are systems and response received", async () => {
|
it("updates stop and polyline data if there are systems and response received", async () => {
|
||||||
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);
|
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);
|
||||||
|
|||||||
Reference in New Issue
Block a user