mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
use generator method for shuttles
This commit is contained in:
@@ -1,7 +1,6 @@
|
||||
import { beforeEach, describe, expect, test } from "@jest/globals";
|
||||
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
||||
import { generateMockSystems } from "../generators";
|
||||
import { mock } from "node:test";
|
||||
import { generateMockShuttles, generateMockSystems } from "../generators";
|
||||
|
||||
// For repositories created in the future, reuse core testing
|
||||
// logic from here and differentiate setup (e.g. creating mocks)
|
||||
@@ -129,11 +128,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
});
|
||||
describe("getShuttlesBySystemId", () => {
|
||||
test("gets all shuttles for a specific system ID", async () => {
|
||||
const mockShuttles = [
|
||||
{ id: "sh1", name: "Shuttle A", routeId: "r1", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
|
||||
{ id: "sh2", name: "Shuttle B", routeId: "r2", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } },
|
||||
{ id: "sh3", name: "Shuttle C", routeId: "r3", systemId: "sys2", coordinates: { latitude: 30, longitude: 40 } },
|
||||
];
|
||||
const mockShuttles = generateMockShuttles();
|
||||
for (const shuttle of mockShuttles) {
|
||||
await repository.addOrUpdateShuttle(shuttle);
|
||||
}
|
||||
@@ -150,11 +145,7 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getShuttlesByRouteId", () => {
|
||||
test("gets all shuttles for a specific route ID", async () => {
|
||||
const mockShuttles = [
|
||||
{ id: "sh1", name: "Shuttle A", routeId: "r1", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
|
||||
{ id: "sh2", name: "Shuttle B", routeId: "r1", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } },
|
||||
{ id: "sh3", name: "Shuttle C", routeId: "r2", systemId: "sys2", coordinates: { latitude: 30, longitude: 40 } },
|
||||
];
|
||||
const mockShuttles = generateMockShuttles();
|
||||
for (const shuttle of mockShuttles) {
|
||||
await repository.addOrUpdateShuttle(shuttle);
|
||||
}
|
||||
@@ -171,15 +162,12 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("getShuttleById", () => {
|
||||
test("gets a shuttle by ID if it exists", async () => {
|
||||
const mockShuttles = [
|
||||
{ id: "1", name: "Shuttle A", routeId: "r1", systemId: "sys1", coordinates: { latitude: 10, longitude: 20 } },
|
||||
{ id: "2", name: "Shuttle B", routeId: "r2", systemId: "sys1", coordinates: { latitude: 15, longitude: 25 } },
|
||||
];
|
||||
const mockShuttles = generateMockShuttles();
|
||||
for (const shuttle of mockShuttles) {
|
||||
await repository.addOrUpdateShuttle(shuttle);
|
||||
}
|
||||
|
||||
const result = await repository.getShuttleById("2");
|
||||
const result = await repository.getShuttleById("sh2");
|
||||
expect(result).toEqual(mockShuttles[1]);
|
||||
});
|
||||
|
||||
@@ -356,7 +344,8 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
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" };
|
||||
const mockShuttles = generateMockShuttles();
|
||||
const newShuttle = mockShuttles[0];
|
||||
|
||||
await repository.addOrUpdateShuttle(newShuttle);
|
||||
|
||||
@@ -365,8 +354,10 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
});
|
||||
|
||||
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" };
|
||||
const mockShuttles = generateMockShuttles();
|
||||
const existingShuttle = mockShuttles[0];
|
||||
const updatedShuttle = structuredClone(existingShuttle);
|
||||
updatedShuttle.name = "Updated Shuttle";
|
||||
|
||||
await repository.addOrUpdateShuttle(existingShuttle);
|
||||
await repository.addOrUpdateShuttle(updatedShuttle);
|
||||
@@ -469,10 +460,10 @@ describe("UnoptimizedInMemoryRepository", () => {
|
||||
|
||||
describe("clearShuttleData", () => {
|
||||
test("clears all shuttles from the repository", async () => {
|
||||
const shuttle1 = { id: "shuttle1", name: "Shuttle A", systemId: "sys1", routeId: "route1", coordinates: { latitude: 10, longitude: 20 } };
|
||||
const shuttle2 = { id: "shuttle2", name: "Shuttle B", systemId: "sys2", routeId: "route2", coordinates: { latitude: 15, longitude: 25 } };
|
||||
await repository.addOrUpdateShuttle(shuttle1);
|
||||
await repository.addOrUpdateShuttle(shuttle2);
|
||||
const mockShuttles = generateMockShuttles();
|
||||
for (const shuttle of mockShuttles) {
|
||||
await repository.addOrUpdateShuttle(shuttle);
|
||||
}
|
||||
|
||||
await repository.clearShuttleData();
|
||||
|
||||
|
||||
Reference in New Issue
Block a user