Rename getArrivedStopIfExists to getArrivedStopIfNextStop, and add more documentation

This commit is contained in:
2025-11-21 11:42:42 -08:00
parent 715bef163c
commit ee10daf957
4 changed files with 33 additions and 31 deletions

View File

@@ -375,9 +375,9 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
if (isAtStop) {
// Allow retrieval of the shuttle's current stop
// Will still return undefined when the shuttle leaves the stop
arrivedStop = await this.getArrivedStopIfExists(shuttle, true);
arrivedStop = await this.getArrivedStopIfNextStop(shuttle, true);
} else {
arrivedStop = await this.getArrivedStopIfExists(shuttle, false);
arrivedStop = await this.getArrivedStopIfNextStop(shuttle, false);
}
// Will not fire *any* events if the same stop
@@ -452,7 +452,7 @@ export class RedisShuttleRepository extends BaseRedisRepository implements Shutt
}
}
public async getArrivedStopIfExists(
public async getArrivedStopIfNextStop(
shuttle: IShuttle,
canReturnShuttleCurrentStop: boolean = false,
): Promise<IStop | undefined> {

View File

@@ -104,7 +104,9 @@ export interface ShuttleGetterRepository extends EventEmitter {
checkIfShuttleIsAtStop(shuttleId: string): Promise<boolean>;
/**
* Get the stop that the shuttle is currently at, if it exists.
* Get the stop that the shuttle is currently at, if it's the shuttle's
* next stop based on the "last stop" the shuttle was at. If there was no
* "last stop" for the shuttle, it may return any stop on the shuttle's route.
*
* @param shuttle
* @param canReturnShuttleCurrentStop If set to true, and the shuttle's "last stop"
@@ -113,5 +115,5 @@ export interface ShuttleGetterRepository extends EventEmitter {
* This flag has no effect if the shuttle has not had a "last stop".
* @returns
*/
getArrivedStopIfExists(shuttle: IShuttle, canReturnShuttleCurrentStop: boolean): Promise<IStop | undefined>;
getArrivedStopIfNextStop(shuttle: IShuttle, canReturnShuttleCurrentStop: boolean): Promise<IStop | undefined>;
}

View File

@@ -190,9 +190,9 @@ export class UnoptimizedInMemoryShuttleRepository
if (isAtStop) {
// Allow retrieval of the shuttle's current stop
// Will still return undefined when the shuttle leaves the stop
arrivedStop = await this.getArrivedStopIfExists(shuttle, true);
arrivedStop = await this.getArrivedStopIfNextStop(shuttle, true);
} else {
arrivedStop = await this.getArrivedStopIfExists(shuttle, false);
arrivedStop = await this.getArrivedStopIfNextStop(shuttle, false);
}
@@ -268,7 +268,7 @@ export class UnoptimizedInMemoryShuttleRepository
return sum / filteredPoints.length;
}
public async getArrivedStopIfExists(
public async getArrivedStopIfNextStop(
shuttle: IShuttle,
canReturnShuttleCurrentStop: boolean = false,
): Promise<IStop | undefined> {

View File

@@ -577,7 +577,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
test("gets any stop that the shuttle is currently at, if the shuttle has not had a last stop", async () => {
const { sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
const result = await repository.getArrivedStopIfExists(shuttle, false);
const result = await repository.getArrivedStopIfNextStop(shuttle, false);
expect(result).toBeDefined();
expect(result?.id).toBe("st2");
@@ -588,7 +588,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
const { sampleShuttleNotInRepository } = await setupRouteAndOrderedStops();
const shuttle = { ...sampleShuttleNotInRepository, coordinates: { latitude: 12.5, longitude: 22.5 } }; // Not at any stop
const result = await repository.getArrivedStopIfExists(shuttle, false);
const result = await repository.getArrivedStopIfNextStop(shuttle, false);
expect(result).toBeUndefined();
});
@@ -599,11 +599,11 @@ describe.each(repositoryImplementations)('$name', (holder) => {
shuttle.coordinates = stop1.coordinates;
await repository.addOrUpdateShuttle(shuttle);
let result = await repository.getArrivedStopIfExists(shuttle, false);
let result = await repository.getArrivedStopIfNextStop(shuttle, false);
expect(result).toBeUndefined();
shuttle.coordinates = stop2.coordinates;
result = await repository.getArrivedStopIfExists(shuttle, false);
result = await repository.getArrivedStopIfNextStop(shuttle, false);
expect(result).not.toBeUndefined();
});
@@ -613,7 +613,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
shuttle.coordinates = stop1.coordinates;
await repository.addOrUpdateShuttle(shuttle);
const result = await repository.getArrivedStopIfExists(shuttle, true);
const result = await repository.getArrivedStopIfNextStop(shuttle, true);
expect(result?.id === stop1.id)
});