mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-19 08:50:29 +00:00
Implement getShuttleLastStopArrival and updateShuttleLastStopArrival
This commit is contained in:
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, it } from "@jest/globals";
|
||||
import { beforeEach, describe, it, expect, afterEach } from "@jest/globals";
|
||||
import { RedisShuttleRepository } from "../RedisShuttleRepository";
|
||||
import { afterEach } from "node:test";
|
||||
import { generateMockShuttles } from "../../../../testHelpers/mockDataGenerators";
|
||||
|
||||
describe("RedisShuttleRepository", () => {
|
||||
let repository: RedisShuttleRepository;
|
||||
@@ -27,11 +27,52 @@ describe("RedisShuttleRepository", () => {
|
||||
|
||||
describe("getShuttleLastStopArrival", () => {
|
||||
it("gets the shuttle's last stop if existing in the data", async () => {
|
||||
// Use updateShuttleLastStopArrival to populate data
|
||||
const mockShuttles = generateMockShuttles();
|
||||
const shuttle = mockShuttles[0];
|
||||
const stopArrival = {
|
||||
stopId: "st1",
|
||||
timestamp: new Date("2024-01-15T10:30:00Z"),
|
||||
};
|
||||
|
||||
await repository.updateShuttleLastStopArrival(shuttle, stopArrival);
|
||||
const result = await repository.getShuttleLastStopArrival(shuttle);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result?.stopId).toBe(stopArrival.stopId);
|
||||
expect(result?.timestamp.getTime()).toBe(stopArrival.timestamp.getTime());
|
||||
});
|
||||
|
||||
it("returns undefined if the data has never been initialized", async () => {
|
||||
|
||||
const mockShuttles = generateMockShuttles();
|
||||
const shuttle = mockShuttles[0];
|
||||
|
||||
const result = await repository.getShuttleLastStopArrival(shuttle);
|
||||
|
||||
expect(result).toBeUndefined();
|
||||
});
|
||||
|
||||
it("returns the most recent stop arrival when updated multiple times", async () => {
|
||||
const mockShuttles = generateMockShuttles();
|
||||
const shuttle = mockShuttles[0];
|
||||
|
||||
const firstArrival = {
|
||||
stopId: "st1",
|
||||
timestamp: new Date("2024-01-15T10:30:00Z"),
|
||||
};
|
||||
|
||||
const secondArrival = {
|
||||
stopId: "st2",
|
||||
timestamp: new Date("2024-01-15T10:35:00Z"),
|
||||
};
|
||||
|
||||
await repository.updateShuttleLastStopArrival(shuttle, firstArrival);
|
||||
await repository.updateShuttleLastStopArrival(shuttle, secondArrival);
|
||||
|
||||
const result = await repository.getShuttleLastStopArrival(shuttle);
|
||||
|
||||
expect(result).toBeDefined();
|
||||
expect(result?.stopId).toBe(secondArrival.stopId);
|
||||
expect(result?.timestamp.getTime()).toBe(secondArrival.timestamp.getTime());
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user