Add updated test cases and update call to stop arrival helper

This commit is contained in:
2025-11-10 15:09:13 -08:00
parent 63ed267ded
commit 2a80a049bd
3 changed files with 52 additions and 8 deletions

View File

@@ -437,12 +437,15 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette
}
}
public async getArrivedStopIfExists(shuttle: IShuttle): Promise<IStop | undefined> {
public async getArrivedStopIfExists(
shuttle: IShuttle,
delta = 0.001,
): Promise<IStop | undefined> {
const orderedStops = await this.getOrderedStopsByRouteId(shuttle.routeId);
for (const orderedStop of orderedStops) {
const stop = await this.getStopById(orderedStop.stopId);
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop)) {
if (stop != null && shuttleHasArrivedAtStop(shuttle, stop, delta)) {
return stop;
}
return undefined;
@@ -454,7 +457,7 @@ export class RedisShuttleRepository extends EventEmitter implements ShuttleGette
throw Error("not implemented");
}
private async updateShuttleLastStopArrival(shuttle: IShuttle, lastStopArrival: ShuttleStopArrival) {
public async updateShuttleLastStopArrival(shuttle: IShuttle, lastStopArrival: ShuttleStopArrival) {
// Key: shuttleId:stopId:
// Value: just a marker (no numerical value)
}

View File

@@ -0,0 +1,37 @@
import { beforeEach, describe, it } from "@jest/globals";
import { RedisShuttleRepository } from "../RedisShuttleRepository";
import { afterEach } from "node:test";
describe("RedisShuttleRepository", () => {
let repository: RedisShuttleRepository;
beforeEach(async () => {
repository = new RedisShuttleRepository();
await repository.connect();
});
afterEach(async () => {
await repository.clearAllData();
await repository.disconnect();
});
describe("getArrivedStopIfExists", () => {
it("gets the stop that the shuttle is currently at, if exists", async () => {
});
it("returns undefined if shuttle is not currently at a stop", async () => {
});
});
describe("getShuttleLastStopArrival", () => {
it("gets the shuttle's last stop if existing in the data", async () => {
// Use updateShuttleLastStopArrival to populate data
});
it("returns undefined if the data has never been initialized", async () => {
});
});
});