From 1b0f4e9d24b3a3d5ed6a9137ebce577aa2cbd562 Mon Sep 17 00:00:00 2001 From: Mike Tschudi Date: Wed, 5 Sep 2018 13:26:52 -0700 Subject: [PATCH 1/2] Make moveItem's folder parameter optional --- packages/arcgis-rest-items/src/update.ts | 8 +- .../arcgis-rest-items/test/update.test.ts | 85 +++++++++++++++++++ 2 files changed, 91 insertions(+), 2 deletions(-) diff --git a/packages/arcgis-rest-items/src/update.ts b/packages/arcgis-rest-items/src/update.ts index 14e49d5f26..a274845cbb 100644 --- a/packages/arcgis-rest-items/src/update.ts +++ b/packages/arcgis-rest-items/src/update.ts @@ -27,7 +27,7 @@ export interface IItemMoveRequestOptions extends IItemCrudRequestOptions { * Alphanumeric id of folder to house moved item. If null, empty, or "/", the destination is the * root folder. */ - folder: string; + folder?: string; } /** @@ -113,8 +113,12 @@ export function moveItem( requestOptions.itemId }/move`; + let folder = requestOptions.folder; + if (!folder) { + folder = "/"; + } requestOptions.params = { - folder: requestOptions.folder, + folder, ...requestOptions.params }; diff --git a/packages/arcgis-rest-items/test/update.test.ts b/packages/arcgis-rest-items/test/update.test.ts index df7224b44b..79628a68e4 100644 --- a/packages/arcgis-rest-items/test/update.test.ts +++ b/packages/arcgis-rest-items/test/update.test.ts @@ -262,5 +262,90 @@ describe("search", () => { fail(e); }); }); + + it("should move an item to the root folder 1", done => { + fetchMock.once("*", ItemSuccessResponse); + const itemId = "3ef"; + moveItem({ + itemId, + ...MOCK_USER_REQOPTS + }) + .then(response => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/" + + itemId + + "/move" + ); + expect(options.method).toBe("POST"); + expect(options.body).toContain("f=json"); + expect(options.body).toContain("folder=%2F&"); + expect(options.body).toContain(encodeParam("token", "fake-token")); + + done(); + }) + .catch(e => { + fail(e); + }); + }); + + it("should move an item to the root folder 2", done => { + fetchMock.once("*", ItemSuccessResponse); + const itemId = "3ef"; + const folder = ""; + moveItem({ + itemId, + folder, + ...MOCK_USER_REQOPTS + }) + .then(response => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/" + + itemId + + "/move" + ); + expect(options.method).toBe("POST"); + expect(options.body).toContain("f=json"); + expect(options.body).toContain("folder=%2F&"); + expect(options.body).toContain(encodeParam("token", "fake-token")); + + done(); + }) + .catch(e => { + fail(e); + }); + }); + + it("should move an item to the root folder 3", done => { + fetchMock.once("*", ItemSuccessResponse); + const itemId = "3ef"; + const folder = "/"; + moveItem({ + itemId, + folder, + ...MOCK_USER_REQOPTS + }) + .then(response => { + expect(fetchMock.called()).toEqual(true); + const [url, options]: [string, RequestInit] = fetchMock.lastCall("*"); + expect(url).toEqual( + "https://myorg.maps.arcgis.com/sharing/rest/content/users/casey/items/" + + itemId + + "/move" + ); + expect(options.method).toBe("POST"); + expect(options.body).toContain("f=json"); + expect(options.body).toContain("folder=%2F&"); + expect(options.body).toContain(encodeParam("token", "fake-token")); + + done(); + }) + .catch(e => { + fail(e); + }); + }); }); // auth requests }); From 682593a528d3cec02508ccff64620647870c1d3e Mon Sep 17 00:00:00 2001 From: Mike Tschudi Date: Thu, 6 Sep 2018 09:07:53 -0700 Subject: [PATCH 2/2] De-footgunned moveItem parameter --- packages/arcgis-rest-items/src/update.ts | 12 ++++++------ packages/arcgis-rest-items/test/update.test.ts | 14 +++++++------- 2 files changed, 13 insertions(+), 13 deletions(-) diff --git a/packages/arcgis-rest-items/src/update.ts b/packages/arcgis-rest-items/src/update.ts index a274845cbb..acaaaeea42 100644 --- a/packages/arcgis-rest-items/src/update.ts +++ b/packages/arcgis-rest-items/src/update.ts @@ -27,7 +27,7 @@ export interface IItemMoveRequestOptions extends IItemCrudRequestOptions { * Alphanumeric id of folder to house moved item. If null, empty, or "/", the destination is the * root folder. */ - folder?: string; + folderId?: string; } /** @@ -98,7 +98,7 @@ export function updateItemResource( * * moveItem({ * itemId: "3ef", - * folder: "7c5", + * folderId: "7c5", * authentication: userSession * }) ``` * @@ -113,12 +113,12 @@ export function moveItem( requestOptions.itemId }/move`; - let folder = requestOptions.folder; - if (!folder) { - folder = "/"; + let folderId = requestOptions.folderId; + if (!folderId) { + folderId = "/"; } requestOptions.params = { - folder, + folder: folderId, ...requestOptions.params }; diff --git a/packages/arcgis-rest-items/test/update.test.ts b/packages/arcgis-rest-items/test/update.test.ts index 79628a68e4..80531b9ae8 100644 --- a/packages/arcgis-rest-items/test/update.test.ts +++ b/packages/arcgis-rest-items/test/update.test.ts @@ -237,10 +237,10 @@ describe("search", () => { it("should move an item to a folder", done => { fetchMock.once("*", ItemSuccessResponse); const itemId = "3ef"; - const folder = "7c5"; + const folderId = "7c5"; moveItem({ itemId, - folder, + folderId, ...MOCK_USER_REQOPTS }) .then(response => { @@ -253,7 +253,7 @@ describe("search", () => { ); expect(options.method).toBe("POST"); expect(options.body).toContain("f=json"); - expect(options.body).toContain("folder=" + folder); + expect(options.body).toContain("folder=" + folderId); expect(options.body).toContain(encodeParam("token", "fake-token")); done(); @@ -293,10 +293,10 @@ describe("search", () => { it("should move an item to the root folder 2", done => { fetchMock.once("*", ItemSuccessResponse); const itemId = "3ef"; - const folder = ""; + const folderId = ""; moveItem({ itemId, - folder, + folderId, ...MOCK_USER_REQOPTS }) .then(response => { @@ -322,10 +322,10 @@ describe("search", () => { it("should move an item to the root folder 3", done => { fetchMock.once("*", ItemSuccessResponse); const itemId = "3ef"; - const folder = "/"; + const folderId = "/"; moveItem({ itemId, - folder, + folderId, ...MOCK_USER_REQOPTS }) .then(response => {