mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add test cases
This commit is contained in:
80
test/loaders/ApiBasedRepositoryLoaderTests.test.ts
Normal file
80
test/loaders/ApiBasedRepositoryLoaderTests.test.ts
Normal file
@@ -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 () => {
|
||||||
|
|
||||||
|
});
|
||||||
|
});
|
||||||
|
});
|
||||||
|
|
||||||
Reference in New Issue
Block a user