From 0f41ff1868994e185bdf99cb9bab74c4416dc830 Mon Sep 17 00:00:00 2001 From: Brendan Chen Date: Wed, 22 Jan 2025 13:35:39 -0800 Subject: [PATCH] add test cases --- .../ApiBasedRepositoryLoaderTests.test.ts | 80 +++++++++++++++++++ 1 file changed, 80 insertions(+) create mode 100644 test/loaders/ApiBasedRepositoryLoaderTests.test.ts 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 () => { + + }); + }); +}); +