Skip to content

Commit

Permalink
fix(getPortalUrl): make getPortalUrl use portal in request options if…
Browse files Browse the repository at this point in the history
… passed in

AFFECTS PACKAGES:
@esri/arcgis-rest-request

ISSUES CLOSED: #180
  • Loading branch information
Noah Mulfinger authored and noahmulfinger committed May 2, 2018
1 parent 1307329 commit 6103101
Show file tree
Hide file tree
Showing 2 changed files with 26 additions and 8 deletions.
20 changes: 12 additions & 8 deletions packages/arcgis-rest-request/src/utils/get-portal-url.ts
Original file line number Diff line number Diff line change
Expand Up @@ -5,17 +5,21 @@ import { IRequestOptions } from "../request";
/**
* Helper that returns the portalUrl - either defaulting to www.arcgis.com or using
* the passed in auth manager's .portal property
*
*
* @param requestOptions - Request options that may have authentication manager
* @returns Portal url to be used in API requests
*/
export function getPortalUrl(requestOptions?: IRequestOptions): string {
// default to arcgis.com
let portalUrl = "https://www.arcgis.com/sharing/rest";
// but if the auth was passed, use that portal...
if (requestOptions && requestOptions.authentication) {
portalUrl = requestOptions.authentication.portal;
export function getPortalUrl(requestOptions: IRequestOptions = {}): string {
// use portal in options if specified
if (requestOptions.portal) {
return requestOptions.portal;
}

// if the auth was passed, use that portal
if (requestOptions.authentication) {
return requestOptions.authentication.portal;
}

return portalUrl;
// default to arcgis.com
return "https://www.arcgis.com/sharing/rest";
}
14 changes: 14 additions & 0 deletions packages/arcgis-rest-request/test/utils/get-portal-url.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -17,4 +17,18 @@ describe("getPortalUrl", () => {
const url = getPortalUrl(requestOptions);
expect(url).toEqual("https://foo.com/arcgis/sharing/rest");
});

it("should use the portal in the requestOptions if passed", () => {
const requestOptions = {
authentication: {
portal: "https://foo.com/arcgis/sharing/rest",
getToken() {
return Promise.resolve("fake");
}
},
portal: "https://bar.com/arcgis/sharing/rest"
};
const url = getPortalUrl(requestOptions);
expect(url).toEqual("https://bar.com/arcgis/sharing/rest");
});
});

0 comments on commit 6103101

Please sign in to comment.