From 57de1f64d0f86bdfeed89e09ddcb7af50c2ad4c4 Mon Sep 17 00:00:00 2001 From: Gavin Rehkemper Date: Mon, 9 Jan 2023 12:11:49 -0600 Subject: [PATCH] fix(arcgis-rest-request): pass referer added test --- .../test/ArcGISIdentityManager.test.ts | 38 +++++++++++++++++++ 1 file changed, 38 insertions(+) diff --git a/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts b/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts index 884542596..c666b4ded 100644 --- a/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts +++ b/packages/arcgis-rest-request/test/ArcGISIdentityManager.test.ts @@ -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(); + }); + }); }); });