Update getArrivedStopIfExists method to take an argument returnNextStopOnly
This commit is contained in:
@@ -577,7 +577,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
test("gets the stop that the shuttle is currently at, if exists", async () => {
|
||||
const { sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
|
||||
|
||||
const result = await repository.getArrivedStopIfExists(shuttle);
|
||||
const result = await repository.getArrivedStopIfExists(shuttle, false);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result?.id).toBe("st2");
|
||||
@@ -588,10 +588,32 @@ 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);
|
||||
const result = await repository.getArrivedStopIfExists(shuttle, false);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
test("only gets the shuttle's next stop if parameter passed and shuttle has arrived at stop", async () => {
|
||||
const { sampleShuttleNotInRepository: shuttle, stop1, stop2 } = await setupRouteAndOrderedStops();
|
||||
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
await repository.addOrUpdateShuttle(shuttle);
|
||||
|
||||
let result = await repository.getArrivedStopIfExists(shuttle, true);
|
||||
expect(result).toBeUndefined();
|
||||
|
||||
shuttle.coordinates = stop2.coordinates;
|
||||
result = await repository.getArrivedStopIfExists(shuttle, true);
|
||||
expect(result).not.toBeUndefined();
|
||||
});
|
||||
|
||||
test("still gets any stop for the shuttle if the shuttle has no last stop", async () => {
|
||||
const { sampleShuttleNotInRepository: shuttle, stop1 } = await setupRouteAndOrderedStops();
|
||||
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
const result = await repository.getArrivedStopIfExists(shuttle, true);
|
||||
expect(result).not.toBeUndefined();
|
||||
});
|
||||
});
|
||||
|
||||
describe("getShuttleLastStopArrival", () => {
|
||||
|
||||
Reference in New Issue
Block a user