mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add test cases for fetchANdUpdateRouteDataForSystemId
This commit is contained in:
@@ -3,6 +3,7 @@ import { ApiBasedRepositoryLoader, ApiResponseError } from "../../src/loaders/Ap
|
|||||||
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
import { UnoptimizedInMemoryRepository } from "../../src/repositories/UnoptimizedInMemoryRepository";
|
||||||
import { fetchSystemDataSuccessfulResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse";
|
import { fetchSystemDataSuccessfulResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataSuccessfulResponse";
|
||||||
import { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
|
import { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
|
||||||
|
import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse";
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Function to update behavior of the global `fetch` function.
|
* Function to update behavior of the global `fetch` function.
|
||||||
@@ -76,13 +77,40 @@ describe("ApiBasedRepositoryLoader", () => {
|
|||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
describe("fetchAndUpdateRouteDataForExistingSystems", () => {
|
|
||||||
it("updates route data in repository if there are systems and response received", async () => {
|
|
||||||
|
|
||||||
|
describe("fetchAndUpdateRouteDataForExistingSystemsInRepository", () => {
|
||||||
|
// TODO
|
||||||
|
// Add a test case to ensure that fetchAndUpdateRouteDataForSystemId
|
||||||
|
// was called for every available system ID
|
||||||
|
});
|
||||||
|
|
||||||
|
describe("fetchAndUpdateRouteDataForSystemId", () => {
|
||||||
|
it("updates route data in repository if there are systems and response received", async () => {
|
||||||
|
updateGlobalFetchMockJson(fetchRouteDataSuccessfulResponse);
|
||||||
|
|
||||||
|
await loader.fetchAndUpdateRouteDataForSystemId("263");
|
||||||
|
|
||||||
|
const routes = await loader.repository.getRoutesBySystemId("263");
|
||||||
|
|
||||||
|
expect(routes.length).toEqual(fetchRouteDataSuccessfulResponse.all.length)
|
||||||
});
|
});
|
||||||
|
|
||||||
it("throws the correct error if the API response contains no data", async () => {
|
it("throws the correct error if the API response contains no data", async () => {
|
||||||
|
// The Passio API returns some invalid JSON if there is no data,
|
||||||
|
// so simulate a JSON parsing error
|
||||||
|
|
||||||
|
// @ts-ignore
|
||||||
|
global.fetch = jest.fn(() => {
|
||||||
|
return Promise.resolve({
|
||||||
|
json: () => Promise.reject(new SyntaxError("Unable to parse JSON")),
|
||||||
|
status: 200,
|
||||||
|
ok: true,
|
||||||
|
})
|
||||||
|
}) as jest.Mock;
|
||||||
|
|
||||||
|
await assertAsyncCallbackThrowsApiResponseError(async () => {
|
||||||
|
await loader.fetchAndUpdateRouteDataForSystemId("263");
|
||||||
|
});
|
||||||
});
|
});
|
||||||
});
|
});
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user