Update InMemoryParkingRepository.ts and tests to use the circular queue

This commit is contained in:
2025-07-02 18:48:33 -04:00
parent 220b402b3b
commit 2b04ca01a9
2 changed files with 13 additions and 10 deletions

View File

@@ -1,9 +1,10 @@
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
import {
InMemoryParkingRepository,
PARKING_LOGGING_INTERVAL_MS
PARKING_LOGGING_INTERVAL_MS, ParkingStructureID
} from "../../src/repositories/InMemoryParkingRepository";
import { IParkingStructure } from "../../src/entities/ParkingRepositoryEntities";
import { IParkingStructure, IParkingStructureTimestampRecord } from "../../src/entities/ParkingRepositoryEntities";
import { CircularQueue } from "../../src/types/CircularQueue";
describe("InMemoryParkingRepository", () => {
let repository: InMemoryParkingRepository;
@@ -19,7 +20,7 @@ describe("InMemoryParkingRepository", () => {
address: "300 E Walnut Ave, Orange, CA 92867",
updatedTime: new Date(),
};
let historicalData = new Map();
let historicalData: Map<ParkingStructureID, CircularQueue<IParkingStructureTimestampRecord>> = new Map();
beforeEach(() => {
historicalData = new Map();
@@ -57,8 +58,8 @@ describe("InMemoryParkingRepository", () => {
jest.setSystemTime(now + PARKING_LOGGING_INTERVAL_MS + 60);
await repository.addOrUpdateParkingStructure(testStructure);
expect(historicalData.get(testStructure.id)).toContainEqual(expectedTimestampRecordMatcher);
expect(historicalData.get(testStructure.id)).toContainEqual({
expect(historicalData.get(testStructure.id)?.get(0)).toEqual(expectedTimestampRecordMatcher);
expect(historicalData.get(testStructure.id)?.get(1)).toEqual({
...expectedTimestampRecordMatcher,
timestampMs: now + PARKING_LOGGING_INTERVAL_MS + 60,
});
@@ -74,7 +75,7 @@ describe("InMemoryParkingRepository", () => {
jest.setSystemTime(now + 60);
await repository.addOrUpdateParkingStructure(testStructure);
expect(historicalData.get(testStructure.id)).toHaveLength(1);
expect(historicalData.get(testStructure.id)?.size()).toEqual(1);
});
});