Skip to content

Commit

Permalink
feat(arcgis-rest-portal): add documentation
Browse files Browse the repository at this point in the history
  • Loading branch information
juliannaeapicella committed Jan 11, 2023
1 parent b668b15 commit 826e7fd
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 11 deletions.
21 changes: 14 additions & 7 deletions packages/arcgis-rest-portal/src/users/get-user-properties.ts
Original file line number Diff line number Diff line change
Expand Up @@ -23,10 +23,10 @@ export interface IUserProperties {
}

/**
* Helper that returns the properties attribute for a user.
*
* @param IGetUserPropertiesOptions - options to pass through in the request
* @returns User properties object
* Fetches the properties for a user
* @param username The user whose properties to fetch
* @param requestOptions An IRequestOptions object
* @returns a promise that resolves an IUserProperties object
*/
export async function getUserProperties(
username: string,
Expand All @@ -42,11 +42,18 @@ export async function getUserProperties(
return response.properties;
}

/**
* Updates the properties for a user
* @param username The user whose properties to update
* @param properties IUserProperties object with properties to update
* @param requestOptions An IRequestOptions object
* @returns a promise that resolves to { success: boolean }
*/
export async function setUserProperties(
username: string,
properties: IUserProperties,
requestOptions: IUserRequestOptions
): Promise<void> {
const username = requestOptions.authentication.username;
requestOptions: IRequestOptions
): Promise<{ success: boolean }> {
const url = `${getPortalUrl(
requestOptions
)}/community/users/${encodeURIComponent(username)}/setProperties`;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -38,7 +38,7 @@ describe("users", () => {
userPropertiesResponse
);

getUserProperties("c@sey", { authentication: session })
getUserProperties(session.username, { authentication: session })
.then(() => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall();
Expand All @@ -59,7 +59,7 @@ describe("users", () => {
{ properties: {} }
);

getUserProperties("c@sey", { authentication: session })
getUserProperties(session.username, { authentication: session })
.then((response) => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall();
Expand Down Expand Up @@ -89,10 +89,13 @@ describe("users", () => {
mapViewer: "modern"
};

setUserProperties(properties, { authentication: session })
setUserProperties(session.username, properties, {
authentication: session
})
.then(() => {
expect(fetchMock.called()).toEqual(true);
const [url, options]: [string, RequestInit] = fetchMock.lastCall();
console.log("options:", options);
expect(url).toEqual(
"https://myorg.maps.arcgis.com/sharing/rest/community/users/c%40sey/setProperties"
);
Expand All @@ -116,7 +119,9 @@ describe("users", () => {
mapViewer: "modern"
};

setUserProperties(properties, { authentication: session })
setUserProperties(session.username, properties, {
authentication: session
})
.then(() => {
fail(new Error("API did not serve error response"));
})
Expand Down

0 comments on commit 826e7fd

Please sign in to comment.