Move duplicate shuttle declarations in tests to a "sample" shuttle generated by the setup function
This commit is contained in:
@@ -76,19 +76,11 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
|
||||
describe("handleShuttleWillArriveAtStop", () => {
|
||||
test("updates how long the shuttle took to get from one stop to another", async () => {
|
||||
const { route, systemId, stop2, stop1 } = await setupRouteAndOrderedStops();
|
||||
const { route, stop2, stop1, sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
|
||||
|
||||
repository.startListeningForUpdates();
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
name: "Shuttle 1",
|
||||
routeId: route.id,
|
||||
systemId: systemId,
|
||||
coordinates: stop1.coordinates,
|
||||
orientationInDegrees: 0,
|
||||
updatedTime: new Date(),
|
||||
};
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
|
||||
const firstStopArrivalTime = new Date(2025, 0, 1, 12, 0, 0);
|
||||
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopArrivalTime.getTime());
|
||||
@@ -118,7 +110,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
currentTime: Date,
|
||||
shuttleSecondArrivalTimeAtFirstStop: Date
|
||||
) {
|
||||
const { route, systemId, stop1, stop2, stop3 } = await setupRouteAndOrderedStops();
|
||||
const { stop1, stop2, stop3, sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
|
||||
|
||||
// Populating travel time data
|
||||
const firstStopArrivalTime = new Date(2025, 0, 1, 11, 0, 0);
|
||||
@@ -128,15 +120,7 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
repository.setReferenceTime(currentTime);
|
||||
repository.startListeningForUpdates();
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
name: "Shuttle 1",
|
||||
routeId: route.id,
|
||||
systemId: systemId,
|
||||
coordinates: stop1.coordinates,
|
||||
orientationInDegrees: 0,
|
||||
updatedTime: new Date(),
|
||||
};
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
|
||||
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopArrivalTime.getTime());
|
||||
|
||||
@@ -196,19 +180,11 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
|
||||
describe("getAverageTravelTimeSeconds", () => {
|
||||
test("returns the average travel time when historical data exists", async () => {
|
||||
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops();
|
||||
const { route, stop1, stop2, sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
|
||||
|
||||
repository.startListeningForUpdates();
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
name: "Shuttle 1",
|
||||
routeId: route.id,
|
||||
systemId: systemId,
|
||||
coordinates: stop1.coordinates,
|
||||
orientationInDegrees: 0,
|
||||
updatedTime: new Date(),
|
||||
};
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
|
||||
const firstStopTime = new Date(2025, 0, 1, 12, 0, 0);
|
||||
await shuttleRepository.addOrUpdateShuttle(shuttle, firstStopTime.getTime());
|
||||
@@ -232,19 +208,11 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
});
|
||||
|
||||
test("returns average of multiple data points", async () => {
|
||||
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops();
|
||||
const { route, stop1, stop2, sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
|
||||
|
||||
repository.startListeningForUpdates();
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
name: "Shuttle 1",
|
||||
routeId: route.id,
|
||||
systemId: systemId,
|
||||
coordinates: stop1.coordinates,
|
||||
orientationInDegrees: 0,
|
||||
updatedTime: new Date(),
|
||||
};
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
|
||||
// First trip: 10 minutes travel time
|
||||
await shuttleRepository.addOrUpdateShuttle(shuttle, new Date(2025, 0, 1, 12, 0, 0).getTime());
|
||||
@@ -288,19 +256,11 @@ describe.each(repositoryImplementations)('$name', (holder) => {
|
||||
});
|
||||
|
||||
test("returns undefined when querying outside the time range of data", async () => {
|
||||
const { route, systemId, stop1, stop2 } = await setupRouteAndOrderedStops();
|
||||
const { route, stop1, stop2, sampleShuttleNotInRepository: shuttle } = await setupRouteAndOrderedStops();
|
||||
|
||||
repository.startListeningForUpdates();
|
||||
|
||||
const shuttle = {
|
||||
id: "sh1",
|
||||
name: "Shuttle 1",
|
||||
routeId: route.id,
|
||||
systemId: systemId,
|
||||
coordinates: stop1.coordinates,
|
||||
orientationInDegrees: 0,
|
||||
updatedTime: new Date(),
|
||||
};
|
||||
shuttle.coordinates = stop1.coordinates;
|
||||
|
||||
await shuttleRepository.addOrUpdateShuttle(shuttle, new Date(2025, 0, 1, 12, 0, 0).getTime());
|
||||
shuttle.coordinates = stop2.coordinates;
|
||||
|
||||
Reference in New Issue
Block a user