mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
do the same with eta data
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
import { IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../src/entities/entities";
|
||||
import { IEta, IOrderedStop, IRoute, IShuttle, IStop, ISystem } from "../src/entities/entities";
|
||||
|
||||
// Use a single set of generators in case any of the
|
||||
// interfaces change in the future
|
||||
@@ -42,4 +42,12 @@ export function generateMockOrderedStops(): IOrderedStop[] {
|
||||
{ stopId: "st2", routeId: "r1", position: 3 },
|
||||
{ stopId: "st2", routeId: "r2", position: 4 },
|
||||
];
|
||||
}
|
||||
|
||||
export function generateMockEtas(): IEta[] {
|
||||
return [
|
||||
{ shuttleId: "sh1", stopId: "st1", secondsRemaining: 120 },
|
||||
{ shuttleId: "sh1", stopId: "st2", secondsRemaining: 180 },
|
||||
{ shuttleId: "sh2", stopId: "st3", secondsRemaining: 240 },
|
||||
];
|
||||
}
|
||||
@@ -1,6 +1,7 @@
|
||||
import { beforeEach, describe, expect, test } from "@jest/globals";
|
||||
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
||||
import {
|
||||
generateMockEtas,
|
||||
generateMockOrderedStops,
|
||||
generateMockRoutes,
|
||||
generateMockShuttles,
|
||||
@@ -176,11 +177,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getEtasForShuttleId", () => {
|
||||
test("gets ETAs for a specific shuttle ID", async () => {
|
||||
const mockEtas = [
|
||||
{ shuttleId: "sh1", stopId: "st1", secondsRemaining: 120 },
|
||||
{ shuttleId: "sh1", stopId: "st2", secondsRemaining: 180 },
|
||||
{ shuttleId: "sh2", stopId: "st3", secondsRemaining: 240 },
|
||||
];
|
||||
const mockEtas = generateMockEtas();
|
||||
for (const eta of mockEtas) {
|
||||
await repository.addOrUpdateEta(eta);
|
||||
}
|
||||
@@ -197,11 +194,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getEtasForStopId", () => {
|
||||
test("gets ETAs for a specific stop ID", async () => {
|
||||
const mockEtas = [
|
||||
{ shuttleId: "s1", stopId: "st1", secondsRemaining: 120 },
|
||||
{ shuttleId: "s2", stopId: "st1", secondsRemaining: 180 },
|
||||
{ shuttleId: "s3", stopId: "st2", secondsRemaining: 240 },
|
||||
];
|
||||
const mockEtas = generateMockEtas();
|
||||
for (const eta of mockEtas) {
|
||||
await repository.addOrUpdateEta(eta);
|
||||
}
|
||||
@@ -218,7 +211,8 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getEtaForShuttleAndStopId", () => {
|
||||
test("gets a single ETA for a specific shuttle and stop ID", async () => {
|
||||
const mockEta = { shuttleId: "sh1", stopId: "st1", secondsRemaining: 120 };
|
||||
const mockEtas = generateMockEtas();
|
||||
const mockEta = mockEtas[0];
|
||||
await repository.addOrUpdateEta(mockEta);
|
||||
|
||||
const result = await repository.getEtaForShuttleAndStopId("sh1", "st1");
|
||||
@@ -412,22 +406,25 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("addOrUpdateEta", () => {
|
||||
test("adds a new ETA if nonexistent", async () => {
|
||||
const newEta = { shuttleId: "shuttle1", stopId: "stop1", secondsRemaining: 120 };
|
||||
const mockEtas = generateMockEtas();
|
||||
const newEta = mockEtas[0];
|
||||
|
||||
await repository.addOrUpdateEta(newEta);
|
||||
|
||||
const result = await repository.getEtasForShuttleId("shuttle1");
|
||||
const result = await repository.getEtasForShuttleId(newEta.shuttleId);
|
||||
expect(result).toEqual([newEta]);
|
||||
});
|
||||
|
||||
test("updates an existing ETA if it exists", async () => {
|
||||
const existingEta = { shuttleId: "shuttle1", stopId: "stop1", secondsRemaining: 120 };
|
||||
const updatedEta = { shuttleId: "shuttle1", stopId: "stop1", secondsRemaining: 60 };
|
||||
const mockEtas = generateMockEtas();
|
||||
const existingEta = mockEtas[0];
|
||||
const updatedEta = structuredClone(existingEta);
|
||||
updatedEta.secondsRemaining = existingEta.secondsRemaining + 60;
|
||||
|
||||
await repository.addOrUpdateEta(existingEta);
|
||||
await repository.addOrUpdateEta(updatedEta);
|
||||
|
||||
const result = await repository.getEtasForShuttleId("shuttle1");
|
||||
const result = await repository.getEtasForShuttleId(existingEta.shuttleId);
|
||||
expect(result).toEqual([updatedEta]);
|
||||
});
|
||||
});
|
||||
@@ -473,11 +470,10 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("clearEtaData", () => {
|
||||
test("clears all ETAs from the repository", async () => {
|
||||
const eta1 = { shuttleId: "shuttle1", stopId: "stop1", secondsRemaining: 120 };
|
||||
const eta2 = { shuttleId: "shuttle2", stopId: "stop2", secondsRemaining: 150 };
|
||||
|
||||
await repository.addOrUpdateEta(eta1);
|
||||
await repository.addOrUpdateEta(eta2);
|
||||
const mockEtas = generateMockEtas();
|
||||
for (const eta of mockEtas) {
|
||||
await repository.addOrUpdateEta(eta);
|
||||
}
|
||||
|
||||
await repository.clearEtaData();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user