mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 16:00:32 +00:00
do the same with mock stops
This commit is contained in:
@@ -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
|
||||||
@@ -26,3 +26,11 @@ export function generateMockRoutes(): IRoute[] {
|
|||||||
{ 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 } },
|
||||||
|
];
|
||||||
|
}
|
||||||
@@ -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();
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user