mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add addOrUpdate tests for UnoptimizedInMemoryRepository
This commit is contained in:
@@ -310,4 +310,160 @@ describe("UnoptimizedInMemoryRepository", () => {
|
|||||||
expect(result).toEqual([]);
|
expect(result).toEqual([]);
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
describe("addOrUpdateSystem", () => {
|
||||||
|
test("adds a new system if nonexistent", async () => {
|
||||||
|
const newSystem = { id: "sys1", name: "System A", millisecondsSinceEpoch: 1620000000000 };
|
||||||
|
|
||||||
|
await repository.addOrUpdateSystem(newSystem);
|
||||||
|
|
||||||
|
const result = await repository.getSystems();
|
||||||
|
expect(result).toEqual([newSystem]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates an existing system if it exists", async () => {
|
||||||
|
const existingSystem = { id: "sys1", name: "System A", millisecondsSinceEpoch: 1620000000000 };
|
||||||
|
const updatedSystem = { id: "sys1", name: "Updated System A", millisecondsSinceEpoch: 1625000000000 };
|
||||||
|
|
||||||
|
await repository.addOrUpdateSystem(existingSystem);
|
||||||
|
await repository.addOrUpdateSystem(updatedSystem);
|
||||||
|
|
||||||
|
const result = await repository.getSystems();
|
||||||
|
expect(result).toEqual([updatedSystem]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("addOrUpdateRoute", () => {
|
||||||
|
test("adds a new route if nonexistent", async () => {
|
||||||
|
const newRoute = { id: "route1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] };
|
||||||
|
|
||||||
|
await repository.addOrUpdateRoute(newRoute);
|
||||||
|
|
||||||
|
const result = await repository.getRoutesBySystemId("sys1");
|
||||||
|
expect(result).toEqual([newRoute]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates an existing route if it exists", async () => {
|
||||||
|
const existingRoute = { id: "route1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] };
|
||||||
|
const updatedRoute = { id: "route1", name: "Updated Route 1", color: "blue", systemId: "sys1", polylineCoordinates: [] };
|
||||||
|
|
||||||
|
await repository.addOrUpdateRoute(existingRoute);
|
||||||
|
await repository.addOrUpdateRoute(updatedRoute);
|
||||||
|
|
||||||
|
const result = await repository.getRoutesBySystemId("sys1");
|
||||||
|
expect(result).toEqual([updatedRoute]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("addOrUpdateShuttle", () => {
|
||||||
|
test("adds a new shuttle if nonexistent", async () => {
|
||||||
|
const newShuttle = { id: "shuttle1", name: "Shuttle A", coordinates: { latitude: 10, longitude: 20 }, routeId: "route1", systemId: "sys1" };
|
||||||
|
|
||||||
|
await repository.addOrUpdateShuttle(newShuttle);
|
||||||
|
|
||||||
|
const result = await repository.getShuttlesBySystemId("sys1");
|
||||||
|
expect(result).toEqual([newShuttle]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates an existing shuttle if it exists", async () => {
|
||||||
|
const existingShuttle = { id: "shuttle1", name: "Shuttle A", coordinates: { latitude: 10, longitude: 20 }, routeId: "route1", systemId: "sys1" };
|
||||||
|
const updatedShuttle = { id: "shuttle1", name: "Updated Shuttle A", coordinates: { latitude: 30, longitude: 40 }, routeId: "route1", systemId: "sys1" };
|
||||||
|
|
||||||
|
await repository.addOrUpdateShuttle(existingShuttle);
|
||||||
|
await repository.addOrUpdateShuttle(updatedShuttle);
|
||||||
|
|
||||||
|
const result = await repository.getShuttlesBySystemId("sys1");
|
||||||
|
expect(result).toEqual([updatedShuttle]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("addOrUpdateStop", () => {
|
||||||
|
test("adds a new stop if nonexistent", async () => {
|
||||||
|
const newStop = { id: "stop1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } };
|
||||||
|
|
||||||
|
await repository.addOrUpdateStop(newStop);
|
||||||
|
|
||||||
|
const result = await repository.getStopsBySystemId("sys1");
|
||||||
|
expect(result).toEqual([newStop]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates an existing stop if it exists", async () => {
|
||||||
|
const existingStop = { id: "stop1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } };
|
||||||
|
const updatedStop = { id: "stop1", name: "Updated Stop A", systemId: "sys1", coordinates: { latitude: 30, longitude: 40 } };
|
||||||
|
|
||||||
|
await repository.addOrUpdateStop(existingStop);
|
||||||
|
await repository.addOrUpdateStop(updatedStop);
|
||||||
|
|
||||||
|
const result = await repository.getStopsBySystemId("sys1");
|
||||||
|
expect(result).toEqual([updatedStop]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("addOrUpdateOrderedStop", () => {
|
||||||
|
test("adds a new ordered stop if nonexistent", async () => {
|
||||||
|
const newOrderedStop = { routeId: "route1", stopId: "stop1", position: 1 };
|
||||||
|
|
||||||
|
await repository.addOrUpdateOrderedStop(newOrderedStop);
|
||||||
|
|
||||||
|
const result = await repository.getOrderedStopsByRouteId("route1");
|
||||||
|
expect(result).toEqual([newOrderedStop]);
|
||||||
|
});
|
||||||
|
|
||||||
|
test("updates an existing ordered stop if it exists", async () => {
|
||||||
|
const existingOrderedStop = { routeId: "route1", stopId: "stop1", position: 1 };
|
||||||
|
const updatedOrderedStop = { routeId: "route1", stopId: "stop1", position: 2 };
|
||||||
|
|
||||||
|
await repository.addOrUpdateOrderedStop(existingOrderedStop);
|
||||||
|
await repository.addOrUpdateOrderedStop(updatedOrderedStop);
|
||||||
|
|
||||||
|
const result = await repository.getOrderedStopsByRouteId("route1");
|
||||||
|
expect(result).toEqual([updatedOrderedStop]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("addOrUpdateEta", () => {
|
||||||
|
test("adds a new ETA if nonexistent", async () => {
|
||||||
|
const newEta = { shuttleId: "shuttle1", stopId: "stop1", secondsRemaining: 120 };
|
||||||
|
|
||||||
|
await repository.addOrUpdateEta(newEta);
|
||||||
|
|
||||||
|
const result = await repository.getEtasForShuttleId("shuttle1");
|
||||||
|
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 };
|
||||||
|
|
||||||
|
await repository.addOrUpdateEta(existingEta);
|
||||||
|
await repository.addOrUpdateEta(updatedEta);
|
||||||
|
|
||||||
|
const result = await repository.getEtasForShuttleId("shuttle1");
|
||||||
|
expect(result).toEqual([updatedEta]);
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clearSystemData", () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clearShuttleData", () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clearEtaData", () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clearOrderedStopData", () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clearRouteData", () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("clearStopData", () => {
|
||||||
|
|
||||||
|
});
|
||||||
});
|
});
|
||||||
Reference in New Issue
Block a user