Skip to content

Commit a1b51f3

Browse files
authored
feat(arcgis-rest-portal): add removeItemThumbnail() to delete item thumbnails (#1202)
1 parent 6c61bf4 commit a1b51f3

File tree

2 files changed

+53
-1
lines changed

2 files changed

+53
-1
lines changed

packages/arcgis-rest-portal/src/items/remove.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -138,3 +138,31 @@ export function removeFolder(requestOptions: IFolderIdOptions): Promise<{
138138
return request(url, requestOptions);
139139
});
140140
}
141+
142+
/**
143+
* Delete an item's thumbnail. See the [REST Documentation](https://developers.arcgis.com/rest/users-groups-and-items/delete-item-thumbnail.htm) for more information.
144+
*
145+
* ```js
146+
* import { removeItemThumbnail } from "@esri/arcgis-rest-portal";
147+
*
148+
* removeItemThumbnail({
149+
* id: "3ef",
150+
* owner: "c@sey",
151+
* authentication
152+
* })
153+
* .then(response)
154+
* ```
155+
*
156+
* @param requestOptions - Options for the request
157+
* @returns A Promise that deletes a thumbnail.
158+
*/
159+
export function removeItemThumbnail(
160+
requestOptions: IUserItemOptions
161+
): Promise<{ success: boolean }> {
162+
return determineOwner(requestOptions).then((owner) => {
163+
const url = `${getPortalUrl(requestOptions)}/content/users/${owner}/items/${
164+
requestOptions.id
165+
}/deleteThumbnail`;
166+
return request(url, requestOptions);
167+
});
168+
}

packages/arcgis-rest-portal/test/items/remove.test.ts

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,8 @@ import {
66
removeFolder,
77
removeItem,
88
removeItemResource,
9-
removeItemRelationship
9+
removeItemRelationship,
10+
removeItemThumbnail
1011
} from "../../src/items/remove.js";
1112

1213
import { ItemSuccessResponse } from "../mocks/items/item.js";
@@ -255,5 +256,28 @@ describe("search", () => {
255256
fail(e);
256257
});
257258
});
259+
260+
it("should delete an item's thumbnail successfully", (done) => {
261+
fetchMock.once("*", { success: true });
262+
263+
removeItemThumbnail({
264+
id: "3ef",
265+
owner: "dbouwman",
266+
...MOCK_USER_REQOPTS
267+
})
268+
.then((response) => {
269+
const [url, options] = fetchMock.lastCall("*");
270+
expect(url).toEqual(
271+
"https://myorg.maps.arcgis.com/sharing/rest/content/users/dbouwman/items/3ef/deleteThumbnail"
272+
);
273+
expect(options.method).toBe("POST");
274+
expect(options.body).toContain(encodeParam("f", "json"));
275+
expect(options.body).toContain(encodeParam("token", "fake-token"));
276+
done();
277+
})
278+
.catch((e) => {
279+
fail(e);
280+
});
281+
});
258282
}); // auth requests
259283
});

0 commit comments

Comments
 (0)