Skip to content

Commit

Permalink
fix(arcgis-rest-request): pass referer
Browse files Browse the repository at this point in the history
added test
  • Loading branch information
gavinr-maps committed Jan 9, 2023
1 parent 5af0c3b commit 57de1f6
Showing 1 changed file with 38 additions and 0 deletions.
38 changes: 38 additions & 0 deletions packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3317,5 +3317,43 @@ describe("ArcGISIdentityManager", () => {
expect(session.tokenExpires).toEqual(TOMORROW);
});
});

it("should initialize a session from a username and password and pass a referer", () => {
// we intentionally only mock one response
fetchMock.once(
"https://www.arcgis.com/sharing/rest/community/self?f=json&token=token",
{
username: "jsmith",
fullName: "John Smith",
role: "org_publisher"
}
);

fetchMock.postOnce("https://www.arcgis.com/sharing/rest/generateToken", {
token: "token",
expires: TOMORROW.getTime(),
username: " c@sey"
});

return ArcGISIdentityManager.signIn({
username: "c@sey",
password: "123456",
referer: "testreferer"
}).then((session) => {
const [url, options]: [string, RequestInit] = fetchMock.lastCall(
"https://fakeserver.com/arcgis/tokens/generateToken"
);

if (isNode) {
expect(options.body).toContain("referer=testreferer");
}

if (isBrowser) {
expect(options.body).toContain(`referer=testreferer`);
}

done();
});
});
});
});

0 comments on commit 57de1f6

Please sign in to comment.