diff --git a/test/loaders/ApiBasedRepositoryLoaderTests.test.ts b/test/loaders/ApiBasedRepositoryLoaderTests.test.ts new file mode 100644 index 0000000..f14a794 --- /dev/null +++ b/test/loaders/ApiBasedRepositoryLoaderTests.test.ts @@ -0,0 +1,80 @@ +import { beforeEach, describe, it, jest, test } from "@jest/globals"; +import { ApiBasedRepositoryLoader } from "../../src/loaders/ApiBasedRepositoryLoader"; +import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository"; + +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 () => { + + }); + + 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 () => { + + }); + }); +}); +