differentiate between passio system ID and internal ID in loader class

This commit is contained in:
2025-04-07 13:26:19 -07:00
parent 12f0a41153
commit 25f2a8c458
5 changed files with 33 additions and 21 deletions

View File

@@ -43,7 +43,11 @@ export class InterchangeSystem {
args: InterchangeSystemBuilderArguments, args: InterchangeSystemBuilderArguments,
) { ) {
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(); const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
const shuttleDataLoader = new TimedApiBasedShuttleRepositoryLoader(args.passioSystemId, shuttleRepository); const shuttleDataLoader = new TimedApiBasedShuttleRepositoryLoader(
args.passioSystemId,
args.id,
shuttleRepository
);
await shuttleDataLoader.start(); await shuttleDataLoader.start();
const notificationRepository = new RedisNotificationRepository(); const notificationRepository = new RedisNotificationRepository();
@@ -75,7 +79,11 @@ export class InterchangeSystem {
args: InterchangeSystemBuilderArguments, args: InterchangeSystemBuilderArguments,
) { ) {
const shuttleRepository = new UnoptimizedInMemoryShuttleRepository(); const shuttleRepository = new UnoptimizedInMemoryShuttleRepository();
const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(args.passioSystemId, shuttleRepository); const shuttleDataLoader = new ApiBasedShuttleRepositoryLoader(
args.passioSystemId,
args.id,
shuttleRepository
);
const notificationRepository = new InMemoryNotificationRepository(); const notificationRepository = new InMemoryNotificationRepository();
const notificationScheduler = new ETANotificationScheduler( const notificationScheduler = new ETANotificationScheduler(

View File

@@ -18,7 +18,8 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
baseUrl = "https://passiogo.com/mapGetData.php"; baseUrl = "https://passiogo.com/mapGetData.php";
constructor( constructor(
public systemId: string, public passioSystemId: string,
public systemIdForConstructedData: string,
public repository: ShuttleGetterSetterRepository, public repository: ShuttleGetterSetterRepository,
) { ) {
} }
@@ -33,7 +34,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
} }
public async fetchAndUpdateRouteDataForSystem() { public async fetchAndUpdateRouteDataForSystem() {
const systemId = this.systemId; const systemId = this.passioSystemId;
const routeIdsToPrune = await this.constructExistingEntityIdSet(async () => { const routeIdsToPrune = await this.constructExistingEntityIdSet(async () => {
return await this.repository.getRoutesBySystemId(systemId); return await this.repository.getRoutesBySystemId(systemId);
}); });
@@ -65,7 +66,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
color: jsonRoute.color, color: jsonRoute.color,
id: jsonRoute.myid, id: jsonRoute.myid,
polylineCoordinates: [], polylineCoordinates: [],
systemId: systemId, systemId: this.systemIdForConstructedData,
}; };
await this.repository.addOrUpdateRoute(constructedRoute); await this.repository.addOrUpdateRoute(constructedRoute);
@@ -83,7 +84,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
} }
public async fetchAndUpdateStopAndPolylineDataForRoutesInSystem() { public async fetchAndUpdateStopAndPolylineDataForRoutesInSystem() {
const systemId = this.systemId; const systemId = this.passioSystemId;
// Fetch from the API // Fetch from the API
// Pass JSON output into two different methods to update repository // Pass JSON output into two different methods to update repository
@@ -124,7 +125,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
} }
public async fetchAndUpdateShuttleDataForSystem() { public async fetchAndUpdateShuttleDataForSystem() {
const systemId = this.systemId; const systemId = this.passioSystemId;
const shuttleIdsToPrune = await this.constructExistingEntityIdSet(async () => { const shuttleIdsToPrune = await this.constructExistingEntityIdSet(async () => {
return await this.repository.getShuttlesBySystemId(systemId); return await this.repository.getShuttlesBySystemId(systemId);
}); });
@@ -163,7 +164,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
longitude: parseFloat(jsonBus.longitude), longitude: parseFloat(jsonBus.longitude),
}, },
routeId: jsonBus.routeId, routeId: jsonBus.routeId,
systemId: systemId, systemId: this.systemIdForConstructedData,
id: `${jsonBus.busId}`, id: `${jsonBus.busId}`,
orientationInDegrees: parseFloat(jsonBus.calculatedCourse) orientationInDegrees: parseFloat(jsonBus.calculatedCourse)
} }
@@ -183,7 +184,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
} }
public async fetchAndUpdateEtaDataForExistingStopsForSystem() { public async fetchAndUpdateEtaDataForExistingStopsForSystem() {
const stops = await this.repository.getStopsBySystemId(this.systemId); const stops = await this.repository.getStopsBySystemId(this.passioSystemId);
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.fetchAndUpdateEtaDataForStopId(stopId);
@@ -215,7 +216,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
shuttleId: `${shuttleId}`, shuttleId: `${shuttleId}`,
stopId: stopId, stopId: stopId,
millisecondsSinceEpoch: Date.now(), millisecondsSinceEpoch: Date.now(),
systemId: this.systemId, systemId: this.systemIdForConstructedData,
}; };
this.repository.addOrUpdateEta(eta); this.repository.addOrUpdateEta(eta);
@@ -273,7 +274,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
routeId, routeId,
stopId, stopId,
position: index + 1, position: index + 1,
systemId: this.systemId, systemId: this.systemIdForConstructedData,
}; };
} }
@@ -282,7 +283,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
routeId, routeId,
stopId: jsonOrderedStopData[index - 1][1], stopId: jsonOrderedStopData[index - 1][1],
position: index, position: index,
systemId: this.systemId, systemId: this.systemIdForConstructedData,
}; };
} }
if (index < jsonOrderedStopData.length - 1) { if (index < jsonOrderedStopData.length - 1) {
@@ -290,7 +291,7 @@ export class ApiBasedShuttleRepositoryLoader implements ShuttleRepositoryLoader
routeId, routeId,
stopId: jsonOrderedStopData[index + 1][1], stopId: jsonOrderedStopData[index + 1][1],
position: index + 2, position: index + 2,
systemId: this.systemId, systemId: this.systemIdForConstructedData,
}; };
} }

View File

@@ -22,10 +22,11 @@ export class TimedApiBasedShuttleRepositoryLoader extends ApiBasedShuttleReposit
readonly timeout = 10000; readonly timeout = 10000;
constructor( constructor(
public systemId: string, public passioSystemId: string,
public systemIdForConstructedData: string,
repository: ShuttleGetterSetterRepository, repository: ShuttleGetterSetterRepository,
) { ) {
super(systemId, repository); super(passioSystemId, systemIdForConstructedData, repository);
this.startFetchDataAndUpdate = this.startFetchDataAndUpdate.bind(this); this.startFetchDataAndUpdate = this.startFetchDataAndUpdate.bind(this);
} }

View File

@@ -1,13 +1,11 @@
import { beforeEach, describe, expect, it, jest, test } from "@jest/globals"; import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import { ApiBasedShuttleRepositoryLoader, ApiResponseError } from "../../src/loaders/ApiBasedShuttleRepositoryLoader"; import { ApiBasedShuttleRepositoryLoader, ApiResponseError } from "../../src/loaders/ApiBasedShuttleRepositoryLoader";
import { UnoptimizedInMemoryShuttleRepository } from "../../src/repositories/UnoptimizedInMemoryShuttleRepository"; import { UnoptimizedInMemoryShuttleRepository } from "../../src/repositories/UnoptimizedInMemoryShuttleRepository";
import { fetchSystemDataSuccessfulResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse";
import { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse"; import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse";
import { import {
fetchStopAndPolylineDataSuccessfulResponse fetchStopAndPolylineDataSuccessfulResponse
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse"; } from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
import { generateMockRoutes, generateMockShuttles, generateMockStops, generateMockPassioSystems } from "../testHelpers/mockDataGenerators"; import { generateMockRoutes, generateMockShuttles, generateMockStops } from "../testHelpers/mockDataGenerators";
import { import {
fetchShuttleDataSuccessfulResponse fetchShuttleDataSuccessfulResponse
} from "../jsonSnapshots/fetchShuttleData/fetchShuttleDataSuccessfulResponse"; } from "../jsonSnapshots/fetchShuttleData/fetchShuttleDataSuccessfulResponse";
@@ -26,7 +24,7 @@ describe("ApiBasedRepositoryLoader", () => {
let loader: ApiBasedShuttleRepositoryLoader; let loader: ApiBasedShuttleRepositoryLoader;
beforeEach(() => { beforeEach(() => {
loader = new ApiBasedShuttleRepositoryLoader("263", new UnoptimizedInMemoryShuttleRepository()); loader = new ApiBasedShuttleRepositoryLoader("263", "1", new UnoptimizedInMemoryShuttleRepository());
resetGlobalFetchMockJson(); resetGlobalFetchMockJson();
}); });

View File

@@ -15,7 +15,11 @@ describe("TimedApiBasedRepositoryLoader", () => {
beforeEach(() => { beforeEach(() => {
resetGlobalFetchMockJson(); resetGlobalFetchMockJson();
loader = new TimedApiBasedShuttleRepositoryLoader("1", new UnoptimizedInMemoryShuttleRepository()); loader = new TimedApiBasedShuttleRepositoryLoader(
"1",
"1",
new UnoptimizedInMemoryShuttleRepository()
);
spies = { spies = {
fetchAndUpdateRouteDataForSystem: jest.spyOn(loader, 'fetchAndUpdateRouteDataForSystem'), fetchAndUpdateRouteDataForSystem: jest.spyOn(loader, 'fetchAndUpdateRouteDataForSystem'),