Rename methods to indicate a single responsibility

This commit is contained in:
2025-09-26 14:31:20 -07:00
parent c244a4b037
commit 9a2b2f65b9
7 changed files with 30 additions and 30 deletions

View File

@@ -1,3 +1,3 @@
export interface RepositoryLoader {
fetchAndUpdateAll(): Promise<void>;
updateAll(): Promise<void>;
}

View File

@@ -33,7 +33,7 @@ export class TimedApiBasedRepositoryLoader {
if (!this.shouldBeRunning) return;
try {
await this.loader.fetchAndUpdateAll();
await this.loader.updateAll();
} catch (e) {
console.error(e);
}

View File

@@ -21,7 +21,7 @@ export class ChapmanApiBasedParkingRepositoryLoader implements ParkingRepository
this.fetchAndUpdateParkingStructures = this.fetchAndUpdateParkingStructures.bind(this);
}
async fetchAndUpdateAll() {
async updateAll() {
await this.fetchAndUpdateParkingStructures();
}

View File

@@ -34,7 +34,7 @@ describe("ChapmanApiBasedParkingRepositoryLoader", () => {
spy.mockResolvedValue(undefined);
});
await loader.fetchAndUpdateAll();
await loader.updateAll();
Object.values(spies).forEach((spy: any) => {
expect(spy).toHaveBeenCalled();

View File

@@ -28,18 +28,18 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
return ids;
}
public async fetchAndUpdateAll() {
await this.fetchAndUpdateRouteDataForSystem();
await this.fetchAndUpdateStopAndPolylineDataForRoutesInSystem();
await this.fetchAndUpdateShuttleDataForSystem();
public async updateAll() {
await this.updateRouteDataForSystem();
await this.updateStopAndPolylineDataForRoutesInSystem();
await this.updateShuttleDataForSystem();
// Because ETA method doesn't support pruning yet,
// add a call to the clear method here
await this.repository.clearEtaData();
await this.fetchAndUpdateEtaDataForExistingStopsForSystem();
await this.updateEtaDataForExistingStopsForSystem();
}
public async fetchAndUpdateRouteDataForSystem() {
public async updateRouteDataForSystem() {
const systemId = this.passioSystemId;
const routeIdsToPrune = await this.constructExistingEntityIdSet(async () => {
return await this.repository.getRoutes();
@@ -90,7 +90,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
}
}
public async fetchAndUpdateStopAndPolylineDataForRoutesInSystem() {
public async updateStopAndPolylineDataForRoutesInSystem() {
const passioSystemId = this.passioSystemId;
// Fetch from the API
@@ -131,7 +131,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
}
}
public async fetchAndUpdateShuttleDataForSystem() {
public async updateShuttleDataForSystem() {
const systemId = this.passioSystemId;
const shuttleIdsToPrune = await this.constructExistingEntityIdSet(async () => {
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();
await Promise.all(stops.map(async (stop) => {
let stopId = stop.id;
await this.fetchAndUpdateEtaDataForStopId(stopId);
await this.updateEtaDataForStopId(stopId);
}));
}
public async fetchAndUpdateEtaDataForStopId(stopId: string) {
public async updateEtaDataForStopId(stopId: string) {
const params = {
eta: "3",
stopIds: stopId,

View File

@@ -1,9 +1,9 @@
import { RepositoryLoader } from "../RepositoryLoader";
export interface ShuttleRepositoryLoader extends RepositoryLoader {
fetchAndUpdateRouteDataForSystem(): Promise<void>;
fetchAndUpdateStopAndPolylineDataForRoutesInSystem(): Promise<void>;
fetchAndUpdateShuttleDataForSystem(): Promise<void>;
fetchAndUpdateEtaDataForExistingStopsForSystem(): Promise<void>;
fetchAndUpdateEtaDataForStopId(stopId: string): Promise<void>;
updateRouteDataForSystem(): Promise<void>;
updateStopAndPolylineDataForRoutesInSystem(): Promise<void>;
updateShuttleDataForSystem(): Promise<void>;
updateEtaDataForExistingStopsForSystem(): Promise<void>;
updateEtaDataForStopId(stopId: string): Promise<void>;
}

View File

@@ -44,7 +44,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
spy.mockResolvedValue(undefined);
});
await loader.fetchAndUpdateAll();
await loader.updateAll();
Object.values(spies).forEach((spy: any) => {
expect(spy).toHaveBeenCalled();
@@ -65,7 +65,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
// Act
await loader.fetchAndUpdateRouteDataForSystem();
await loader.updateRouteDataForSystem();
// Assert
const routes = await loader.repository.getRoutes();
@@ -80,7 +80,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateRouteDataForSystem();
await loader.updateRouteDataForSystem();
});
});
});
@@ -99,7 +99,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInSystem();
await loader.updateStopAndPolylineDataForRoutesInSystem();
const stops = await loader.repository.getStops();
expect(stops.length).toEqual(stopsArray.length);
@@ -119,7 +119,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateStopAndPolylineDataForRoutesInSystem();
await loader.updateStopAndPolylineDataForRoutesInSystem();
});
})
});
@@ -135,7 +135,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
updateGlobalFetchMockJson(fetchShuttleDataSuccessfulResponse);
const busesInResponse = Object.values(fetchShuttleDataSuccessfulResponse.buses);
await loader.fetchAndUpdateShuttleDataForSystem();
await loader.updateShuttleDataForSystem();
const shuttles = await loader.repository.getShuttles();
@@ -146,7 +146,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateShuttleDataForSystem();
await loader.updateShuttleDataForSystem();
});
});
});
@@ -164,7 +164,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
await loader.repository.addOrUpdateStop(stop);
}));
await loader.fetchAndUpdateEtaDataForExistingStopsForSystem();
await loader.updateEtaDataForExistingStopsForSystem();
expect(spy.mock.calls.length).toEqual(stops.length);
});
@@ -177,7 +177,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
// @ts-ignore
const etasFromResponse = fetchEtaDataSuccessfulResponse.ETAs[stopId]
await loader.fetchAndUpdateEtaDataForStopId(stopId);
await loader.updateEtaDataForStopId(stopId);
const etas = await loader.repository.getEtasForStopId(stopId);
expect(etas.length).toEqual(etasFromResponse.length);
@@ -187,7 +187,7 @@ describe("ApiBasedShuttleRepositoryLoader", () => {
updateGlobalFetchMockJsonToThrowSyntaxError();
await assertAsyncCallbackThrowsApiResponseError(async () => {
await loader.fetchAndUpdateEtaDataForStopId("263");
await loader.updateEtaDataForStopId("263");
});
});
});