mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
define behavior of historical data logging through tests
This commit is contained in:
@@ -1,5 +1,8 @@
|
||||
import { beforeEach, describe, expect, it } from "@jest/globals";
|
||||
import { InMemoryParkingRepository } from "../../src/repositories/InMemoryParkingRepository";
|
||||
import { beforeEach, describe, expect, it, jest } from "@jest/globals";
|
||||
import {
|
||||
InMemoryParkingRepository,
|
||||
PARKING_LOGGING_INTERVAL_MS
|
||||
} from "../../src/repositories/InMemoryParkingRepository";
|
||||
import { IParkingStructure } from "../../src/entities/ParkingRepositoryEntities";
|
||||
|
||||
describe("InMemoryParkingRepository", () => {
|
||||
@@ -16,9 +19,11 @@ describe("InMemoryParkingRepository", () => {
|
||||
address: "300 E Walnut Ave, Orange, CA 92867",
|
||||
updatedTime: new Date(),
|
||||
};
|
||||
let historicalData = new Map();
|
||||
|
||||
beforeEach(() => {
|
||||
repository = new InMemoryParkingRepository();
|
||||
historicalData = new Map();
|
||||
repository = new InMemoryParkingRepository(new Map(), historicalData);
|
||||
});
|
||||
|
||||
describe("addOrUpdateParkingStructure", () => {
|
||||
@@ -35,6 +40,42 @@ describe("InMemoryParkingRepository", () => {
|
||||
const result = await repository.getParkingStructureById(testStructure.id);
|
||||
expect(result).toEqual(updatedStructure);
|
||||
});
|
||||
|
||||
it("should log historical data if past the logging interval", async () => {
|
||||
const now = Date.now();
|
||||
jest
|
||||
.useFakeTimers()
|
||||
.setSystemTime(now);
|
||||
|
||||
const expectedTimestampRecordMatcher = {
|
||||
spotsAvailable: testStructure.spotsAvailable,
|
||||
id: testStructure.id,
|
||||
timestampMs: now,
|
||||
}
|
||||
|
||||
await repository.addOrUpdateParkingStructure(testStructure);
|
||||
jest.setSystemTime(now + PARKING_LOGGING_INTERVAL_MS + 60);
|
||||
await repository.addOrUpdateParkingStructure(testStructure);
|
||||
|
||||
expect(historicalData.get(testStructure.id)).toContain(expectedTimestampRecordMatcher);
|
||||
expect(historicalData.get(testStructure.id)).toContain({
|
||||
...expectedTimestampRecordMatcher,
|
||||
timestampMs: now + PARKING_LOGGING_INTERVAL_MS + 60,
|
||||
});
|
||||
});
|
||||
|
||||
it("should not log historical data if not past the logging interval", async () => {
|
||||
const now = Date.now();
|
||||
jest
|
||||
.useFakeTimers()
|
||||
.setSystemTime(now);
|
||||
|
||||
await repository.addOrUpdateParkingStructure(testStructure);
|
||||
jest.setSystemTime(now + 60);
|
||||
await repository.addOrUpdateParkingStructure(testStructure);
|
||||
|
||||
expect(historicalData.get(testStructure.id)).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
||||
describe("removeParkingStructureIfExists", () => {
|
||||
|
||||
Reference in New Issue
Block a user