mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-16 23:40:32 +00:00
Rename getArrivedStopIfExists to getArrivedStopIfNextStop, and add more documentation
This commit is contained in:
@@ -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> {
|
||||
|
||||
@@ -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>;
|
||||
}
|
||||
|
||||
@@ -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> {
|
||||
|
||||
@@ -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)
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user