mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
92 lines
2.7 KiB
TypeScript
92 lines
2.7 KiB
TypeScript
import { beforeEach, describe, expect, it, jest, test } from "@jest/globals";
|
|
import { ApiBasedRepositoryLoader } from "../../src/loaders/ApiBasedRepositoryLoader";
|
|
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
|
import { getAllSystemsResponse } from "../jsonSnapshots/getAllSystemsResponse";
|
|
|
|
function updateGlobalFetchMockJson(obj: any) {
|
|
// @ts-ignore
|
|
global.fetch = jest.fn(() => {
|
|
return Promise.resolve({
|
|
json: () => Promise.resolve(obj)
|
|
})
|
|
}) as jest.Mock;
|
|
}
|
|
|
|
/**
|
|
* Reset the global fetch function mock's JSON to return an empty object.
|
|
* @param obj
|
|
*/
|
|
function resetGlobalFetchMockJson() {
|
|
updateGlobalFetchMockJson({})
|
|
}
|
|
|
|
describe("ApiBasedRepositoryLoader", () => {
|
|
let loader: ApiBasedRepositoryLoader;
|
|
|
|
beforeEach(() => {
|
|
loader = new ApiBasedRepositoryLoader(new UnoptimizedInMemoryRepository());
|
|
resetGlobalFetchMockJson();
|
|
});
|
|
|
|
describe("fetchAndUpdateSystemData", () => {
|
|
it("updates system data in repository if response received", async () => {
|
|
const numberOfSystemsInResponse = getAllSystemsResponse.all.length;
|
|
updateGlobalFetchMockJson(getAllSystemsResponse);
|
|
|
|
await loader.fetchAndUpdateSystemData();
|
|
|
|
const systems = await loader.repository.getSystems();
|
|
if (loader.supportedSystemIds.length < numberOfSystemsInResponse) {
|
|
expect(systems).toHaveLength(loader.supportedSystemIds.length);
|
|
} else {
|
|
expect(systems).toHaveLength(numberOfSystemsInResponse);
|
|
}
|
|
});
|
|
|
|
it("throws the correct error if the API response contains no data", async () => {
|
|
|
|
});
|
|
});
|
|
|
|
describe("fetchAndUpdateRouteDataForExistingSystems", () => {
|
|
it("updates route data in repository if there are systems and response received", async () => {
|
|
|
|
});
|
|
|
|
it("throws the correct error if the API response contains no data", async () => {
|
|
|
|
});
|
|
});
|
|
|
|
describe("fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems", () => {
|
|
it("updates stop and polyline data if there are systems and response received", async () => {
|
|
|
|
});
|
|
|
|
it("throws the correct error if the API response contains no data", async () => {
|
|
|
|
})
|
|
});
|
|
|
|
describe("fetchAndUpdateShuttleDataForExistingSystems", () => {
|
|
it("updates shuttle data in repository if there are systems and response received", async () => {
|
|
|
|
});
|
|
|
|
it("throws the correct error if the API response contains no data", async () => {
|
|
|
|
});
|
|
});
|
|
|
|
describe("fetchAndUpdateEtaDataForExistingSystems", () => {
|
|
it("updates shuttle data in repository if there are systems and response received", async () => {
|
|
|
|
});
|
|
|
|
it("throws the correct error if the API response contains no data", async () => {
|
|
|
|
});
|
|
});
|
|
});
|
|
|