Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix(getPortalUrl): make getPortalUrl use portal in request options if passed in #181

Merged
merged 1 commit into from
May 2, 2018
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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");
});
});