mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Rename methods to indicate a single responsibility
This commit is contained in:
@@ -1,3 +1,3 @@
|
|||||||
export interface RepositoryLoader {
|
export interface RepositoryLoader {
|
||||||
fetchAndUpdateAll(): Promise<void>;
|
updateAll(): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -33,7 +33,7 @@ export class TimedApiBasedRepositoryLoader {
|
|||||||
if (!this.shouldBeRunning) return;
|
if (!this.shouldBeRunning) return;
|
||||||
|
|
||||||
try {
|
try {
|
||||||
await this.loader.fetchAndUpdateAll();
|
await this.loader.updateAll();
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
console.error(e);
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -21,7 +21,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository
|
|||||||
this.fetchAndUpdateParkingStructures = this.fetchAndUpdateParkingStructures.bind(this);
|
this.fetchAndUpdateParkingStructures = this.fetchAndUpdateParkingStructures.bind(this);
|
||||||
}
|
}
|
||||||
|
|
||||||
async fetchAndUpdateAll() {
|
async updateAll() {
|
||||||
await this.fetchAndUpdateParkingStructures();
|
await this.fetchAndUpdateParkingStructures();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
@@ -34,7 +34,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => {
|
|||||||
spy.mockResolvedValue(undefined);
|
spy.mockResolvedValue(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
await loader.fetchAndUpdateAll();
|
await loader.updateAll();
|
||||||
|
|
||||||
Object.values(spies).forEach((spy: any) => {
|
Object.values(spies).forEach((spy: any) => {
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
|
|||||||
@@ -28,18 +28,18 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
|||||||
return ids;
|
return ids;
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateAll() {
|
public async updateAll() {
|
||||||
await this.fetchAndUpdateRouteDataForSystem();
|
await this.updateRouteDataForSystem();
|
||||||
await this.fetchAndUpdateStopAndPolylineDataForRoutesInSystem();
|
await this.updateStopAndPolylineDataForRoutesInSystem();
|
||||||
await this.fetchAndUpdateShuttleDataForSystem();
|
await this.updateShuttleDataForSystem();
|
||||||
|
|
||||||
// Because ETA method doesn't support pruning yet,
|
// Because ETA method doesn't support pruning yet,
|
||||||
// add a call to the clear method here
|
// add a call to the clear method here
|
||||||
await this.repository.clearEtaData();
|
await this.repository.clearEtaData();
|
||||||
await this.fetchAndUpdateEtaDataForExistingStopsForSystem();
|
await this.updateEtaDataForExistingStopsForSystem();
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateRouteDataForSystem() {
|
public async updateRouteDataForSystem() {
|
||||||
const systemId = this.passioSystemId;
|
const systemId = this.passioSystemId;
|
||||||
const routeIdsToPrune = await this.constructExistingEntityIdSet(async () => {
|
const routeIdsToPrune = await this.constructExistingEntityIdSet(async () => {
|
||||||
return await this.repository.getRoutes();
|
return await this.repository.getRoutes();
|
||||||
@@ -90,7 +90,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateStopAndPolylineDataForRoutesInSystem() {
|
public async updateStopAndPolylineDataForRoutesInSystem() {
|
||||||
const passioSystemId = this.passioSystemId;
|
const passioSystemId = this.passioSystemId;
|
||||||
|
|
||||||
// Fetch from the API
|
// Fetch from the API
|
||||||
@@ -131,7 +131,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateShuttleDataForSystem() {
|
public async updateShuttleDataForSystem() {
|
||||||
const systemId = this.passioSystemId;
|
const systemId = this.passioSystemId;
|
||||||
const shuttleIdsToPrune = await this.constructExistingEntityIdSet(async () => {
|
const shuttleIdsToPrune = await this.constructExistingEntityIdSet(async () => {
|
||||||
return await this.repository.getShuttles();
|
return await this.repository.getShuttles();
|
||||||
@@ -191,15 +191,15 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateEtaDataForExistingStopsForSystem() {
|
public async updateEtaDataForExistingStopsForSystem() {
|
||||||
const stops = await this.repository.getStops();
|
const stops = await this.repository.getStops();
|
||||||
await Promise.all(stops.map(async (stop) => {
|
await Promise.all(stops.map(async (stop) => {
|
||||||
let stopId = stop.id;
|
let stopId = stop.id;
|
||||||
await this.fetchAndUpdateEtaDataForStopId(stopId);
|
await this.updateEtaDataForStopId(stopId);
|
||||||
}));
|
}));
|
||||||
}
|
}
|
||||||
|
|
||||||
public async fetchAndUpdateEtaDataForStopId(stopId: string) {
|
public async updateEtaDataForStopId(stopId: string) {
|
||||||
const params = {
|
const params = {
|
||||||
eta: "3",
|
eta: "3",
|
||||||
stopIds: stopId,
|
stopIds: stopId,
|
||||||
|
|||||||
@@ -1,9 +1,9 @@
|
|||||||
import { RepositoryLoader } from "../RepositoryLoader";
|
import { RepositoryLoader } from "../RepositoryLoader";
|
||||||
|
|
||||||
export interface ShuttleRepositoryLoader extends RepositoryLoader {
|
export interface ShuttleRepositoryLoader extends RepositoryLoader {
|
||||||
fetchAndUpdateRouteDataForSystem(): Promise<void>;
|
updateRouteDataForSystem(): Promise<void>;
|
||||||
fetchAndUpdateStopAndPolylineDataForRoutesInSystem(): Promise<void>;
|
updateStopAndPolylineDataForRoutesInSystem(): Promise<void>;
|
||||||
fetchAndUpdateShuttleDataForSystem(): Promise<void>;
|
updateShuttleDataForSystem(): Promise<void>;
|
||||||
fetchAndUpdateEtaDataForExistingStopsForSystem(): Promise<void>;
|
updateEtaDataForExistingStopsForSystem(): Promise<void>;
|
||||||
fetchAndUpdateEtaDataForStopId(stopId: string): Promise<void>;
|
updateEtaDataForStopId(stopId: string): Promise<void>;
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -44,7 +44,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
spy.mockResolvedValue(undefined);
|
spy.mockResolvedValue(undefined);
|
||||||
});
|
});
|
||||||
|
|
||||||
await loader.fetchAndUpdateAll();
|
await loader.updateAll();
|
||||||
|
|
||||||
Object.values(spies).forEach((spy: any) => {
|
Object.values(spies).forEach((spy: any) => {
|
||||||
expect(spy).toHaveBeenCalled();
|
expect(spy).toHaveBeenCalled();
|
||||||
@@ -65,7 +65,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
|
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
|
||||||
|
|
||||||
// Act
|
// Act
|
||||||
await loader.fetchAndUpdateRouteDataForSystem();
|
await loader.updateRouteDataForSystem();
|
||||||
|
|
||||||
// Assert
|
// Assert
|
||||||
const routes = await loader.repository.getRoutes();
|
const routes = await loader.repository.getRoutes();
|
||||||
@@ -80,7 +80,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||||
|
|
||||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
await loader.fetchAndUpdateRouteDataForSystem();
|
await loader.updateRouteDataForSystem();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -99,7 +99,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
|
|
||||||
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
|
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
|
||||||
|
|
||||||
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInSystem();
|
await loader.updateStopAndPolylineDataForRoutesInSystem();
|
||||||
|
|
||||||
const stops = await loader.repository.getStops();
|
const stops = await loader.repository.getStops();
|
||||||
expect(stops.length).toEqual(stopsArray.length);
|
expect(stops.length).toEqual(stopsArray.length);
|
||||||
@@ -119,7 +119,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||||
|
|
||||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInSystem();
|
await loader.updateStopAndPolylineDataForRoutesInSystem();
|
||||||
});
|
});
|
||||||
})
|
})
|
||||||
});
|
});
|
||||||
@@ -135,7 +135,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
updateGlobalFetchMockJson(fetchShuttleDataSuccessfulResponse);
|
updateGlobalFetchMockJson(fetchShuttleDataSuccessfulResponse);
|
||||||
const busesInResponse = Object.values(fetchShuttleDataSuccessfulResponse.buses);
|
const busesInResponse = Object.values(fetchShuttleDataSuccessfulResponse.buses);
|
||||||
|
|
||||||
await loader.fetchAndUpdateShuttleDataForSystem();
|
await loader.updateShuttleDataForSystem();
|
||||||
|
|
||||||
const shuttles = await loader.repository.getShuttles();
|
const shuttles = await loader.repository.getShuttles();
|
||||||
|
|
||||||
@@ -146,7 +146,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||||
|
|
||||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
await loader.fetchAndUpdateShuttleDataForSystem();
|
await loader.updateShuttleDataForSystem();
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
@@ -164,7 +164,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
await loader.repository.addOrUpdateStop(stop);
|
await loader.repository.addOrUpdateStop(stop);
|
||||||
}));
|
}));
|
||||||
|
|
||||||
await loader.fetchAndUpdateEtaDataForExistingStopsForSystem();
|
await loader.updateEtaDataForExistingStopsForSystem();
|
||||||
|
|
||||||
expect(spy.mock.calls.length).toEqual(stops.length);
|
expect(spy.mock.calls.length).toEqual(stops.length);
|
||||||
});
|
});
|
||||||
@@ -177,7 +177,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
// @ts-ignore
|
// @ts-ignore
|
||||||
const etasFromResponse = fetchEtaDataSuccessfulResponse.ETAs[stopId]
|
const etasFromResponse = fetchEtaDataSuccessfulResponse.ETAs[stopId]
|
||||||
|
|
||||||
await loader.fetchAndUpdateEtaDataForStopId(stopId);
|
await loader.updateEtaDataForStopId(stopId);
|
||||||
|
|
||||||
const etas = await loader.repository.getEtasForStopId(stopId);
|
const etas = await loader.repository.getEtasForStopId(stopId);
|
||||||
expect(etas.length).toEqual(etasFromResponse.length);
|
expect(etas.length).toEqual(etasFromResponse.length);
|
||||||
@@ -187,7 +187,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
|
|||||||
updateGlobalFetchMockJsonToThrowSyntaxError();
|
updateGlobalFetchMockJsonToThrowSyntaxError();
|
||||||
|
|
||||||
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
await loader.fetchAndUpdateEtaDataForStopId("263");
|
await loader.updateEtaDataForStopId("263");
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|||||||
Reference in New Issue
Block a user