Skip to content

Commit

Permalink
Merge pull request #306 from Esri/mkt-moveItem-to-root
Browse files Browse the repository at this point in the history
Make moveItem's folder parameter optional
  • Loading branch information
MikeTschudi authored Sep 6, 2018
2 parents 984f76b + 682593a commit da410d3
Show file tree
Hide file tree
Showing 2 changed files with 95 additions and 6 deletions.
10 changes: 7 additions & 3 deletions packages/arcgis-rest-items/src/update.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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;
}

/**
Expand Down Expand Up @@ -98,7 +98,7 @@ export function updateItemResource(
*
* moveItem({
* itemId: "3ef",
* folder: "7c5",
* folderId: "7c5",
* authentication: userSession
* }) ```
*
Expand All @@ -113,8 +113,12 @@ export function moveItem(
requestOptions.itemId
}/move`;

let folderId = requestOptions.folderId;
if (!folderId) {
folderId = "/";
}
requestOptions.params = {
folder: requestOptions.folder,
folder: folderId,
...requestOptions.params
};

Expand Down
91 changes: 88 additions & 3 deletions packages/arcgis-rest-items/test/update.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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 => {
Expand All @@ -253,7 +253,92 @@ 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();
})
.catch(e => {
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 folderId = "";
moveItem({
itemId,
folderId,
...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 folderId = "/";
moveItem({
itemId,
folderId,
...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();
Expand Down

0 comments on commit da410d3

Please sign in to comment.