1 // Copyright (C) The Arvados Authors. All rights reserved.
3 // SPDX-License-Identifier: AGPL-3.0
5 import CommonResourceService from "./common-resource-service";
6 import axios from "axios";
7 import MockAdapter from "axios-mock-adapter";
9 describe("CommonResourceService", () => {
10 const axiosInstance = axios.create();
11 const axiosMock = new MockAdapter(axiosInstance);
17 it("#create", async () => {
20 .reply(200, { owner_uuid: "ownerUuidValue" });
22 const commonResourceService = new CommonResourceService(axiosInstance, "resource");
23 const resource = await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
24 expect(resource).toEqual({ ownerUuid: "ownerUuidValue" });
27 it("#create maps request params to snake case", async () => {
28 axiosInstance.post = jest.fn(() => Promise.resolve({data: {}}));
29 const commonResourceService = new CommonResourceService(axiosInstance, "resource");
30 await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
31 expect(axiosInstance.post).toHaveBeenCalledWith("/resource/", {owner_uuid: "ownerUuidValue"});
34 it("#delete", async () => {
36 .onDelete("/resource/uuid")
37 .reply(200, { deleted_at: "now" });
39 const commonResourceService = new CommonResourceService(axiosInstance, "resource");
40 const resource = await commonResourceService.delete("uuid");
41 expect(resource).toEqual({ deletedAt: "now" });
44 it("#get", async () => {
46 .onGet("/resource/uuid")
47 .reply(200, { modified_at: "now" });
49 const commonResourceService = new CommonResourceService(axiosInstance, "resource");
50 const resource = await commonResourceService.get("uuid");
51 expect(resource).toEqual({ modifiedAt: "now" });
54 it("#list", async () => {
67 const commonResourceService = new CommonResourceService(axiosInstance, "resource");
68 const resource = await commonResourceService.list({ limit: 10, offset: 1 });
69 expect(resource).toEqual({