Update the method to accept a canReturnShuttleCurrentStop flag instead

This commit is contained in:
2025-11-21 11:07:47 -08:00
parent 8c341e91e0
commit 413443a162
4 changed files with 44 additions and 24 deletions

View File

@@ -574,7 +574,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
});
describe("getArrivedStopIfExists", () => {
test("gets the stop that the shuttle is currently at, if exists", async () => {
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);
@@ -593,27 +593,30 @@ describe.each(repositoryImplementations)('$name', (holder) => {
expect(result).toBeUndefined();
});
test("only gets the shuttle's next stop if parameter passed and shuttle has arrived at stop", async () => {
test("only gets the shuttle's next stop if shuttle has previously arrived at a stop", async () => {
const { sampleShuttleNotInRepository: shuttle, stop1, stop2 } = await setupRouteAndOrderedStops();
shuttle.coordinates = stop1.coordinates;
await repository.addOrUpdateShuttle(shuttle);
let result = await repository.getArrivedStopIfExists(shuttle, true);
let result = await repository.getArrivedStopIfExists(shuttle, false);
expect(result).toBeUndefined();
shuttle.coordinates = stop2.coordinates;
result = await repository.getArrivedStopIfExists(shuttle, true);
result = await repository.getArrivedStopIfExists(shuttle, false);
expect(result).not.toBeUndefined();
});
test("still gets any stop for the shuttle if the shuttle has no last stop", async () => {
test("returns the shuttle's currently arrived stop if flag passed", async () => {
const { sampleShuttleNotInRepository: shuttle, stop1 } = await setupRouteAndOrderedStops();
shuttle.coordinates = stop1.coordinates;
await repository.addOrUpdateShuttle(shuttle);
const result = await repository.getArrivedStopIfExists(shuttle, true);
expect(result).not.toBeUndefined();
expect(result?.id === stop1.id)
});
});
describe("getShuttleLastStopArrival", () => {