mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add test for updateEtasForSystemIfTTL if data is not TTL
This commit is contained in:
@@ -210,46 +210,12 @@ describe("getEtaForShuttleAndStopId", () => {
|
||||
expect(result?.millisecondsSinceEpoch).toBeDefined();
|
||||
});
|
||||
|
||||
test("getEtaForShuttleAndStopId returns null if API call is invalid", async () => {
|
||||
test("getEtaForShuttleAndStopId returns null if API call is invalid and cache is empty", 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 () => {
|
||||
updateGlobalFetchMockJson(genericEtaDataByStopId);
|
||||
|
||||
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);
|
||||
});
|
||||
});
|
||||
|
||||
describe("getEtasForShuttleId", () => {
|
||||
@@ -342,7 +308,56 @@ describe("getEtasForStopId", () => {
|
||||
|
||||
describe("updateEtasForSystemIfTTL", () => {
|
||||
test("updateEtasForSystemIfTTL does nothing if data is not TTL", async () => {
|
||||
updateGlobalFetchMockJson(genericEtaDataByStopId);
|
||||
|
||||
// If ETA data is not TTL, then don't do anything
|
||||
const expectedEta: IEta = {
|
||||
secondsRemaining: 587,
|
||||
shuttleId: "5577",
|
||||
stopId: "177666",
|
||||
millisecondsSinceEpoch: Date.now() - 1000,
|
||||
};
|
||||
|
||||
const initialCache: ApiBasedRepositoryCache = {
|
||||
etasForShuttleId: {
|
||||
"5577": [
|
||||
expectedEta,
|
||||
],
|
||||
},
|
||||
etasForStopId: {
|
||||
"177666": [
|
||||
expectedEta,
|
||||
],
|
||||
},
|
||||
stopsBySystemId: {
|
||||
"1": [
|
||||
{
|
||||
systemId: "1",
|
||||
millisecondsSinceEpoch: Date.now() - 1000,
|
||||
name: "Chapman Court",
|
||||
id: "177666",
|
||||
coordinates: {
|
||||
latitude: 33.796796,
|
||||
longitude: -117.889293
|
||||
},
|
||||
}
|
||||
],
|
||||
},
|
||||
};
|
||||
|
||||
const ttls: ApiBasedRepositoryMillisecondTTLs = {
|
||||
etasForShuttleId: 100000,
|
||||
etasForStopId: 100000,
|
||||
};
|
||||
|
||||
const repository = new ApiBasedRepository(initialCache, ttls);
|
||||
await repository.updateEtasForSystemIfTTL("1");
|
||||
|
||||
const updatedResult = await repository.getEtaForShuttleAndStopId(
|
||||
"5577",
|
||||
"177666",
|
||||
);
|
||||
expect(updatedResult?.millisecondsSinceEpoch).toEqual(expectedEta.millisecondsSinceEpoch);
|
||||
});
|
||||
|
||||
test("updateEtasForSystemIfTTL updates all ETA data if data is TTL", async () => {
|
||||
|
||||
Reference in New Issue
Block a user