mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add rest of tests
This commit is contained in:
@@ -1,5 +1,9 @@
|
||||
import { beforeEach, describe, expect, jest, test } from "@jest/globals";
|
||||
import { ApiBasedRepository } from "../../src/repositories/ApiBasedRepository";
|
||||
import {
|
||||
ApiBasedRepository,
|
||||
ApiBasedRepositoryCache,
|
||||
ApiBasedRepositoryMillisecondTTLs
|
||||
} from "../../src/repositories/ApiBasedRepository";
|
||||
import { IEta } from "../../src/entities/entities";
|
||||
|
||||
/**
|
||||
@@ -208,15 +212,47 @@ describe("getEtaForShuttleAndStopId", () => {
|
||||
stopId: "177666",
|
||||
};
|
||||
|
||||
expect(result).toEqual(expectedEta);
|
||||
expect(result?.secondsRemaining).toEqual("5577");
|
||||
expect(result?.millisecondsSinceEpoch).toBeDefined();
|
||||
});
|
||||
|
||||
test("getEtaForShuttleAndStopId returns null if API call is invalid", async () => {
|
||||
const repository = new ApiBasedRepository();
|
||||
const result = await repository.getEtaForShuttleAndStopId("5577", "177666");
|
||||
|
||||
expect(result).toEqual(null);
|
||||
});
|
||||
|
||||
test("getEtasForShuttleAndStopId returns old data if not expired", async () => {
|
||||
const expectedEta: IEta = {
|
||||
secondsRemaining: 587,
|
||||
shuttleId: "5577",
|
||||
stopId: "177666",
|
||||
millisecondsSinceEpoch: Date.now(),
|
||||
};
|
||||
|
||||
const initialCache: ApiBasedRepositoryCache = {
|
||||
etasForShuttleId: {
|
||||
"5577": [
|
||||
expectedEta,
|
||||
],
|
||||
},
|
||||
etasForStopId: {
|
||||
"177666": [
|
||||
expectedEta,
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const ttls: ApiBasedRepositoryMillisecondTTLs = {
|
||||
etasForShuttleId: 100000,
|
||||
etasForStopId: 100000,
|
||||
}
|
||||
|
||||
const repository = new ApiBasedRepository(initialCache, ttls);
|
||||
const result = repository.getEtaForShuttleAndStopId("5577", "177666");
|
||||
|
||||
expect(result).toEqual(expectedEta);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user