X-Git-Url: https://git.arvados.org/arvados.git/blobdiff_plain/6f8e509988756deb7e05a760e718d1ade164fd19..ea54fb82c3a59ca8a959643f8bec4776635433e0:/src/services/common-service/common-resource-service.test.ts diff --git a/src/services/common-service/common-resource-service.test.ts b/src/services/common-service/common-resource-service.test.ts index 385485dbca..5a3bae25fd 100644 --- a/src/services/common-service/common-resource-service.test.ts +++ b/src/services/common-service/common-resource-service.test.ts @@ -6,13 +6,18 @@ import { CommonResourceService } from "./common-resource-service"; import axios, { AxiosInstance } from "axios"; import MockAdapter from "axios-mock-adapter"; import { Resource } from "src/models/resource"; -import { ProgressFn } from "~/services/api/api-progress"; +import { ApiActions } from "~/services/api/api-actions"; + +const actions: ApiActions = { + progressFn: (id: string, working: boolean) => {}, + errorFn: (id: string, message: string) => {} +}; export const mockResourceService = >( - Service: new (client: AxiosInstance, progressFn: ProgressFn) => C) => { + Service: new (client: AxiosInstance, actions: ApiActions) => C) => { const axiosInstance = axios.create(); const axiosMock = new MockAdapter(axiosInstance); - const service = new Service(axiosInstance, (id, working) => {}); + const service = new Service(axiosInstance, actions); Object.keys(service).map(key => service[key] = jest.fn()); return service; }; @@ -20,7 +25,6 @@ export const mockResourceService = { const axiosInstance = axios.create(); const axiosMock = new MockAdapter(axiosInstance); - const progressFn = (id: string, working: boolean) => {}; beforeEach(() => { axiosMock.reset(); @@ -31,14 +35,14 @@ describe("CommonResourceService", () => { .onPost("/resource/") .reply(200, { owner_uuid: "ownerUuidValue" }); - const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn); + const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions); const resource = await commonResourceService.create({ ownerUuid: "ownerUuidValue" }); expect(resource).toEqual({ ownerUuid: "ownerUuidValue" }); }); it("#create maps request params to snake case", async () => { axiosInstance.post = jest.fn(() => Promise.resolve({data: {}})); - const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn); + const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions); await commonResourceService.create({ ownerUuid: "ownerUuidValue" }); expect(axiosInstance.post).toHaveBeenCalledWith("/resource/", {owner_uuid: "ownerUuidValue"}); }); @@ -48,7 +52,7 @@ describe("CommonResourceService", () => { .onDelete("/resource/uuid") .reply(200, { deleted_at: "now" }); - const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn); + const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions); const resource = await commonResourceService.delete("uuid"); expect(resource).toEqual({ deletedAt: "now" }); }); @@ -58,7 +62,7 @@ describe("CommonResourceService", () => { .onGet("/resource/uuid") .reply(200, { modified_at: "now" }); - const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn); + const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions); const resource = await commonResourceService.get("uuid"); expect(resource).toEqual({ modifiedAt: "now" }); }); @@ -76,7 +80,7 @@ describe("CommonResourceService", () => { items_available: 20 }); - const commonResourceService = new CommonResourceService(axiosInstance, "resource", progressFn); + const commonResourceService = new CommonResourceService(axiosInstance, "resource", actions); const resource = await commonResourceService.list({ limit: 10, offset: 1 }); expect(resource).toEqual({ kind: "kind",