mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
do the same for mock routes
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, test } from "@jest/globals";
|
||||
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
||||
import { generateMockShuttles, generateMockSystems } from "../generators";
|
||||
import { generateMockRoutes, generateMockShuttles, generateMockSystems } from "../generators";
|
||||
|
||||
// For repositories created in the future, reuse core testing
|
||||
// logic from here and differentiate setup (e.g. creating mocks)
|
||||
@@ -93,11 +93,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getRoutesBySystemId", () => {
|
||||
test("gets all routes for a specific system ID", async () => {
|
||||
const mockRoutes = [
|
||||
{ id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] },
|
||||
{ id: "r2", name: "Route 2", color: "blue", systemId: "sys1", polylineCoordinates: [] },
|
||||
{ id: "r3", name: "Route 3", color: "green", systemId: "sys2", polylineCoordinates: [] },
|
||||
];
|
||||
const mockRoutes = generateMockRoutes();
|
||||
for (const route of mockRoutes) {
|
||||
await repository.addOrUpdateRoute(route);
|
||||
}
|
||||
@@ -114,7 +110,8 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getRouteById", () => {
|
||||
test("gets a route by ID if it exists", async () => {
|
||||
const mockRoute = { id: "r1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] };
|
||||
const mockRoutes = generateMockRoutes();
|
||||
const mockRoute = mockRoutes[0];
|
||||
await repository.addOrUpdateRoute(mockRoute);
|
||||
|
||||
const result = await repository.getRouteById("r1");
|
||||
@@ -322,7 +319,8 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("addOrUpdateRoute", () => {
|
||||
test("adds a new route if nonexistent", async () => {
|
||||
const newRoute = { id: "route1", name: "Route 1", color: "red", systemId: "sys1", polylineCoordinates: [] };
|
||||
const mockRoutes = generateMockRoutes();
|
||||
const newRoute = mockRoutes[0];
|
||||
|
||||
await repository.addOrUpdateRoute(newRoute);
|
||||
|
||||
@@ -331,8 +329,10 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
});
|
||||
|
||||
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: [] };
|
||||
const mockRoutes = generateMockRoutes();
|
||||
const existingRoute = mockRoutes[0];
|
||||
const updatedRoute = structuredClone(existingRoute);
|
||||
updatedRoute.name = "Updated Route";
|
||||
|
||||
await repository.addOrUpdateRoute(existingRoute);
|
||||
await repository.addOrUpdateRoute(updatedRoute);
|
||||
@@ -504,11 +504,10 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("clearRouteData", () => {
|
||||
test("clears all routes from the repository", async () => {
|
||||
const route1 = { id: "route1", name: "Route 1", systemId: "sys1", color: "#ffffff", polylineCoordinates: [] };
|
||||
const route2 = { id: "route2", name: "Route 2", systemId: "sys2", color: "#ffffff", polylineCoordinates: [] };
|
||||
|
||||
await repository.addOrUpdateRoute(route1);
|
||||
await repository.addOrUpdateRoute(route2);
|
||||
const mockRoutes = generateMockRoutes();
|
||||
for (const route of mockRoutes) {
|
||||
await repository.addOrUpdateRoute(route);
|
||||
}
|
||||
|
||||
await repository.clearRouteData();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user