import AuthRequestBuilder from "../authRequestBuilder"; let authRequestInstance; let myOptions; beforeAll(() => { myOptions = { host: "https://connect.test.com", options: { clientId: "000123", redirectUri: "https://connect.test.com/sso", scope: [ "openid", "profile", "op:users:self:social-accounts:*:d", ], } }; authRequestInstance = new AuthRequestBuilder(myOptions); }); describe("AuthRequestBuilder", () => { it("it creates an authentication url", () => { const authUrl = authRequestInstance.getLoginUrl("twitter", "www.lp.com", { claimsLocales: [ "test", "test2" ], }); expect(authUrl).toEqual("https://connect.test.com/oauth/authorize?client_id=000123&redirect_uri=https%3A%2F%2Fconnect.test.com%2Fsso&scope=openid%20profile%20op%3Ausers%3Aself%3Asocial-accounts%3A*%3Ad&auth_method=twitter&target_link_uri=www.lp.com&response_type=code&prompt=login&claims_locales=test%20test2"); }); it("it creates an auth url for passwordless login", () => { const authUrl = authRequestInstance.getLoginUrl("passwordless", "www.lp.com", { "login_hint": "test@test.com" }); expect(authUrl).toEqual("https://connect.test.com/oauth/authorize?client_id=000123&redirect_uri=https%3A%2F%2Fconnect.test.com%2Fsso&scope=openid%20profile%20op%3Ausers%3Aself%3Asocial-accounts%3A*%3Ad&auth_method=passwordless&target_link_uri=www.lp.com&response_type=code&prompt=login&login_hint=test%40test.com"); }); it("it creates a refresh url", () => { const authUrl = authRequestInstance.getRefreshUrl("twitter", "www.lp.com"); expect(authUrl).toEqual("https://connect.test.com/oauth/authorize?client_id=000123&redirect_uri=https%3A%2F%2Fconnect.test.com%2Fsso&scope=openid%20profile%20op%3Ausers%3Aself%3Asocial-accounts%3A*%3Ad&auth_method=twitter&target_link_uri=www.lp.com&response_type=ajax"); }); it("it allows you to build all auth links at once", () => { const expedtedRoot = "https://connect.test.com/oauth/authorize"; const expectedQueryString = (method) => `client_id=000123&redirect_uri=https%3A%2F%2Fconnect.test.com%2Fsso&scope=openid%20profile%20op%3Ausers%3Aself%3Asocial-accounts%3A*%3Ad&target_link_uri=www.lp.com&auth_method=${method}&response_type=code&prompt=login`; const expectedFacebookLink = `${expedtedRoot}?${expectedQueryString("facebook")}`; const expectedTwitterLink = `${expedtedRoot}?${expectedQueryString("twitter")}`; const expectedGoogleLink = `${expedtedRoot}?${expectedQueryString("google")}`; const expectedPasswordLink = `${expedtedRoot}?${expectedQueryString("password")}`; const expectedPasswordlessLink = `${expedtedRoot}?${expectedQueryString("passwordless")}&login_hint=${encodeURIComponent("test@test.com")}`; const { facebookLink, twitterLink, googleLink, passwordLink, passwordlessLink, builder } = AuthRequestBuilder.build({ host: "https://connect.test.com", options: { clientId: "000123", redirectUri: "https://connect.test.com/sso", scope: [ "openid", "profile", "op:users:self:social-accounts:*:d", ], targetLinkUri: "www.lp.com", } }); const finalPasswordlessLink = passwordlessLink("test@test.com"); expect(facebookLink).toEqual(expectedFacebookLink); expect(twitterLink).toEqual(expectedTwitterLink); expect(googleLink).toEqual(expectedGoogleLink); expect(passwordLink).toEqual(expectedPasswordLink); expect(finalPasswordlessLink).toEqual(expectedPasswordlessLink); expect(builder).toBeInstanceOf(AuthRequestBuilder); }); });