[ARVADOS-WORKBENCH2] created: 1.1.4-224-gb2fd743
Git user
git at public.curoverse.com
Fri Jul 6 10:01:29 EDT 2018
at b2fd743a3acb8d301adab2d1bf2cb0eca573f31a (commit)
commit b2fd743a3acb8d301adab2d1bf2cb0eca573f31a
Author: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
Date: Fri Jul 6 16:01:01 2018 +0200
Fix common resource service create method
Feature #13747
Arvados-DCO-1.1-Signed-off-by: Michal Klobukowski <michal.klobukowski at contractors.roche.com>
diff --git a/src/common/api/common-resource-service.test.ts b/src/common/api/common-resource-service.test.ts
index d28abc4..7093b59 100644
--- a/src/common/api/common-resource-service.test.ts
+++ b/src/common/api/common-resource-service.test.ts
@@ -7,19 +7,36 @@ import axios from "axios";
import MockAdapter from "axios-mock-adapter";
describe("CommonResourceService", () => {
-
- const axiosMock = new MockAdapter(axios);
+ const axiosInstance = axios.create();
+ const axiosMock = new MockAdapter(axiosInstance);
beforeEach(() => {
axiosMock.reset();
});
+ it("#create", async () => {
+ axiosMock
+ .onPost("/resource/")
+ .reply(200, { owner_uuid: "ownerUuidValue" });
+
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
+ 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");
+ await commonResourceService.create({ ownerUuid: "ownerUuidValue" });
+ expect(axiosInstance.post).toHaveBeenCalledWith("/resource/", {owner_uuid: "ownerUuidValue"});
+ });
+
it("#delete", async () => {
axiosMock
.onDelete("/resource/uuid")
.reply(200, { deleted_at: "now" });
- const commonResourceService = new CommonResourceService(axios, "resource");
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
const resource = await commonResourceService.delete("uuid");
expect(resource).toEqual({ deletedAt: "now" });
});
@@ -29,7 +46,7 @@ describe("CommonResourceService", () => {
.onGet("/resource/uuid")
.reply(200, { modified_at: "now" });
- const commonResourceService = new CommonResourceService(axios, "resource");
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
const resource = await commonResourceService.get("uuid");
expect(resource).toEqual({ modifiedAt: "now" });
});
@@ -47,7 +64,7 @@ describe("CommonResourceService", () => {
items_available: 20
});
- const commonResourceService = new CommonResourceService(axios, "resource");
+ const commonResourceService = new CommonResourceService(axiosInstance, "resource");
const resource = await commonResourceService.list({ limit: 10, offset: 1 });
expect(resource).toEqual({
kind: "kind",
diff --git a/src/common/api/common-resource-service.ts b/src/common/api/common-resource-service.ts
index fe6c752..8df179c 100644
--- a/src/common/api/common-resource-service.ts
+++ b/src/common/api/common-resource-service.ts
@@ -70,7 +70,7 @@ export default class CommonResourceService<T extends Resource> {
create(data: Partial<T>) {
return this.serverApi
- .post<T>(this.resourceType, data)
+ .post<T>(this.resourceType, CommonResourceService.mapKeys(_.snakeCase)(data))
.then(CommonResourceService.mapResponseKeys);
}
-----------------------------------------------------------------------
hooks/post-receive
--
More information about the arvados-commits
mailing list