do the same with mock stops

This commit is contained in:
2025-01-21 15:25:47 -08:00
parent dd2fde30b9
commit 7b3f7e5960
2 changed files with 23 additions and 16 deletions

View File

@@ -1,4 +1,4 @@
import { IRoute, IShuttle, ISystem } from "../src/entities/entities"; import { IRoute, IShuttle, IStop, ISystem } from "../src/entities/entities";
// Use a single set of generators in case any of the // Use a single set of generators in case any of the
// interfaces change in the future // interfaces change in the future
@@ -25,4 +25,12 @@ export function generateMockRoutes(): IRoute[] {
{ id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [] }, { id: "r2", name: "Route 2", color: "blue", systemId: "sys2", polylineCoordinates: [] },
{ id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [] }, { id: "r3", name: "Route 3", color: "green", systemId: "sys3", polylineCoordinates: [] },
]; ];
}
export function generateMockStops(): IStop[] {
return [
{ id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
{ id: "st2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 15, longitude: 25 } },
{ id: "st3", name: "Stop C", systemId: "sys3", coordinates: { latitude: 30, longitude: 40 } },
];
} }

View File

@@ -1,6 +1,6 @@
import { beforeEach, describe, expect, test } from "@jest/globals"; import { beforeEach, describe, expect, test } from "@jest/globals";
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
import { generateMockRoutes, generateMockShuttles, generateMockSystems } from "../generators"; import { generateMockRoutes, generateMockShuttles, generateMockStops, generateMockSystems } from "../generators";
// For repositories created in the future, reuse core testing // For repositories created in the future, reuse core testing
// logic from here and differentiate setup (e.g. creating mocks) // logic from here and differentiate setup (e.g. creating mocks)
@@ -57,11 +57,7 @@ describe("UnoptimizedInMemoryRepository", () => {
describe("getStopsBySystemId", () => { describe("getStopsBySystemId", () => {
test("gets stops by system ID", async () => { test("gets stops by system ID", async () => {
const mockStops = [ const mockStops = generateMockStops();
{ id: "1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
{ id: "2", name: "Stop B", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } },
{ id: "3", name: "Stop C", systemId: "sys2", coordinates: { latitude: 30, longitude: 40 } },
];
for (const stop of mockStops) { for (const stop of mockStops) {
await repository.addOrUpdateStop(stop); await repository.addOrUpdateStop(stop);
} }
@@ -78,7 +74,8 @@ describe("UnoptimizedInMemoryRepository", () => {
describe("getStopById", () => { describe("getStopById", () => {
test("gets a stop by ID if it exists", async () => { test("gets a stop by ID if it exists", async () => {
const mockStop = { id: "st1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }; const mockStops = generateMockStops();
const mockStop = mockStops[0];
await repository.addOrUpdateStop(mockStop); await repository.addOrUpdateStop(mockStop);
const result = await repository.getStopById("st1"); const result = await repository.getStopById("st1");
@@ -369,7 +366,8 @@ describe("UnoptimizedInMemoryRepository", () => {
describe("addOrUpdateStop", () => { describe("addOrUpdateStop", () => {
test("adds a new stop if nonexistent", async () => { test("adds a new stop if nonexistent", async () => {
const newStop = { id: "stop1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }; const mockStops = generateMockStops();
const newStop = mockStops[0];
await repository.addOrUpdateStop(newStop); await repository.addOrUpdateStop(newStop);
@@ -378,8 +376,10 @@ describe("UnoptimizedInMemoryRepository", () => {
}); });
test("updates an existing stop if it exists", async () => { test("updates an existing stop if it exists", async () => {
const existingStop = { id: "stop1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }; const mockStops = generateMockStops();
const updatedStop = { id: "stop1", name: "Updated Stop A", systemId: "sys1", coordinates: { latitude: 30, longitude: 40 } }; const existingStop = mockStops[0];
const updatedStop = structuredClone(existingStop);
updatedStop.name = "Updated Stop";
await repository.addOrUpdateStop(existingStop); await repository.addOrUpdateStop(existingStop);
await repository.addOrUpdateStop(updatedStop); await repository.addOrUpdateStop(updatedStop);
@@ -518,11 +518,10 @@ describe("UnoptimizedInMemoryRepository", () => {
describe("clearStopData", () => { describe("clearStopData", () => {
test("clears all stops from the repository", async () => { test("clears all stops from the repository", async () => {
const stop1 = { id: "stop1", name: "Stop A", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } }; const mockStops = generateMockStops();
const stop2 = { id: "stop2", name: "Stop B", systemId: "sys2", coordinates: { latitude: 10, longitude: 20 } }; for (const stop of mockStops) {
await repository.addOrUpdateStop(stop);
await repository.addOrUpdateStop(stop1); }
await repository.addOrUpdateStop(stop2);
await repository.clearStopData(); await repository.clearStopData();