Skip to content

Commit

Permalink
feat(util): add getUserUrl method to auth package
Browse files Browse the repository at this point in the history
AFFECTS PACKAGES:
@esri/arcgis-rest-auth
  • Loading branch information
jgravois committed Mar 21, 2019
1 parent 785f5aa commit d742b34
Show file tree
Hide file tree
Showing 3 changed files with 56 additions and 0 deletions.
17 changes: 17 additions & 0 deletions packages/arcgis-rest-auth/src/get-user-url.ts
@@ -0,0 +1,17 @@
/* Copyright (c) 2019 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { getPortalUrl } from "@esri/arcgis-rest-request";
import { UserSession } from "./UserSession";

/**
* Helper that returns the [user](https://developers.arcgis.com/rest/users-groups-and-items/user.htm) for a given portal.
*
* @param session
* @returns User url to be used in API requests.
*/
export function getUserUrl(session: UserSession): string {
return `${getPortalUrl(session)}/community/users/${encodeURIComponent(
session.username
)}`;
}
1 change: 1 addition & 0 deletions packages/arcgis-rest-auth/src/index.ts
Expand Up @@ -6,3 +6,4 @@ export * from "./UserSession";
export * from "./fetch-token";
export * from "./generate-token";
export * from "./authenticated-request-options";
export * from "./get-user-url";
38 changes: 38 additions & 0 deletions packages/arcgis-rest-auth/test/getUserUrl.test.ts
@@ -0,0 +1,38 @@
/* Copyright (c) 2018 Environmental Systems Research Institute, Inc.
* Apache-2.0 */

import { UserSession, getUserUrl } from "../src/index";

describe("getUserUrl", () => {
it("should encode special characters", () => {
const session = new UserSession({
username: "c@sey"
});

expect(getUserUrl(session)).toEqual(
"https://www.arcgis.com/sharing/rest/community/users/c%40sey"
);
});

it("should recognize an explicit ArcGIS Online organization", () => {
const session = new UserSession({
username: "c@sey",
portal: "https://custom.maps.arcgis.com/sharing/rest"
});

expect(getUserUrl(session)).toEqual(
"https://custom.maps.arcgis.com/sharing/rest/community/users/c%40sey"
);
});

it("should recognize ArcGIS Enterprise", () => {
const session = new UserSession({
username: "c@sey",
portal: "https://gis.city.gov/sharing/rest"
});

expect(getUserUrl(session)).toEqual(
"https://gis.city.gov/sharing/rest/community/users/c%40sey"
);
});
});

0 comments on commit d742b34

Please sign in to comment.