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 { export interface RepositoryLoader {
fetchAndUpdateAll(): Promise<void>; updateAll(): Promise<void>;
} }

View File

@@ -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);
} }

View File

@@ -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();
} }

View File

@@ -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();

View File

@@ -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,

View File

@@ -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>;
} }

View File

@@ -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");
}); });
}); });
}); });