mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
update test for getShuttleById
This commit is contained in:
@@ -509,50 +509,18 @@ describe("getShuttleById", () => {
|
||||
expect(shuttle).toBeNull();
|
||||
});
|
||||
|
||||
test("getShuttleById returns old data if not expired", async () => {
|
||||
updateGlobalFetchMockJson(genericShuttleDataBySystemId);
|
||||
|
||||
const expectedShuttle = {
|
||||
coordinates: {
|
||||
latitude: 33.791781,
|
||||
longitude: -117.8589646,
|
||||
},
|
||||
name: "08",
|
||||
routeId: "53966",
|
||||
systemId: "1",
|
||||
id: "5577",
|
||||
millisecondsSinceEpoch: Date.now() - 1000,
|
||||
}
|
||||
|
||||
const initialCache: ApiBasedRepositoryCache = {
|
||||
shuttleByShuttleId: {
|
||||
"5577": expectedShuttle
|
||||
}
|
||||
};
|
||||
|
||||
const ttls: ApiBasedRepositoryMillisecondTTLs = {
|
||||
shuttleByShuttleId: 100000,
|
||||
};
|
||||
|
||||
const repository = new ApiBasedRepository(initialCache, ttls);
|
||||
const shuttle = await repository.getShuttleById("5577");
|
||||
|
||||
expect(shuttle).toEqual(expectedShuttle);
|
||||
});
|
||||
|
||||
test("getShuttleById returns fresh data if expired", async () => {
|
||||
test("getShuttleById returns data if present", async () => {
|
||||
updateGlobalFetchMockJson(genericShuttleDataBySystemId);
|
||||
|
||||
const initialCacheShuttle = {
|
||||
coordinates: {
|
||||
latitude: 33.791781,
|
||||
latitude: 33.7917818,
|
||||
longitude: -117.8589646,
|
||||
},
|
||||
name: "08",
|
||||
routeId: "53966",
|
||||
systemId: "1",
|
||||
id: "5577",
|
||||
millisecondsSinceEpoch: Date.now() - 100000,
|
||||
}
|
||||
|
||||
const initialCache: ApiBasedRepositoryCache = {
|
||||
@@ -566,9 +534,11 @@ describe("getShuttleById", () => {
|
||||
};
|
||||
|
||||
const repository = new ApiBasedRepository(initialCache, ttls);
|
||||
repository.updateStopsForSystemIdIfTTL = jest.fn(async () => {
|
||||
})
|
||||
|
||||
const shuttle = await repository.getShuttleById("5577");
|
||||
expect(shuttle?.id).toEqual(initialCacheShuttle.id);
|
||||
expect(initialCacheShuttle.millisecondsSinceEpoch).not.toEqual(shuttle?.millisecondsSinceEpoch);
|
||||
expect(shuttle).toEqual(initialCacheShuttle);
|
||||
});
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user