mirror of
https://github.com/brendan-ch/project-inter-server.git
synced 2026-04-17 07:50:31 +00:00
add json snapshot and test cases for method
This commit is contained in:
@@ -5,6 +5,9 @@ import { fetchSystemDataSuccessfulResponse } from "../jsonSnapshots/fetchSystemD
|
||||
import { fetchSystemDataFailedResponse } from "../jsonSnapshots/fetchSystemData/fetchSystemDataFailedResponse";
|
||||
import { fetchRouteDataSuccessfulResponse } from "../jsonSnapshots/fetchRouteData/fetchRouteDataSuccessfulResponse";
|
||||
import { ISystem } from "../../src/entities/entities";
|
||||
import {
|
||||
fetchStopAndPolylineDataSuccessfulResponse
|
||||
} from "../jsonSnapshots/fetchStopAndPolylineData/fetchStopAndPolylineDataSuccessfulResponse";
|
||||
|
||||
/**
|
||||
* Function to update behavior of the global `fetch` function.
|
||||
@@ -134,13 +137,41 @@ describe("ApiBasedRepositoryLoader", () => {
|
||||
});
|
||||
});
|
||||
|
||||
describe("fetchAndUpdateStopAndPolylineDataForRoutesInExistingSystems", () => {
|
||||
describe("fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId", () => {
|
||||
it("updates stop and polyline data if there are systems and response received", async () => {
|
||||
updateGlobalFetchMockJson(fetchStopAndPolylineDataSuccessfulResponse);
|
||||
|
||||
const stopsArray = Object.values(fetchStopAndPolylineDataSuccessfulResponse.stops);
|
||||
|
||||
await loader.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId("263");
|
||||
|
||||
const stops = await loader.repository.getStopsBySystemId("263");
|
||||
expect(stops.length).toEqual(stopsArray.length);
|
||||
|
||||
await Promise.all(stops.map(async (stop) => {
|
||||
const orderedStops = await loader.repository.getOrderedStopsByStopId(stop.id)
|
||||
expect(orderedStops.length).toBeGreaterThan(0);
|
||||
}));
|
||||
|
||||
const routes = await loader.repository.getRoutesBySystemId("263");
|
||||
routes.forEach((route) => {
|
||||
expect(route.polylineCoordinates.length).toBeGreaterThan(0);
|
||||
});
|
||||
});
|
||||
|
||||
it("throws the correct error if the API response contains no data", async () => {
|
||||
// @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.fetchAndUpdateStopAndPolylineDataForRoutesWithSystemId("263");
|
||||
});
|
||||
})
|
||||
});
|
||||
|
||||
|
||||
Reference in New Issue
Block a user