import Auth from "../auth"; import { IGetAccessTokenResponse, IGetAccessTokenParams, IAuthParams, } from "../interfaces"; import { userSelfAll } from "../scopes"; const host = "http://connect.lonelyplanet.com"; const redirectUri = "/sso"; describe("auth", () => { it("should fetch an access token", async () => { const mockFetch = jest.fn(() => new Promise((resolve => resolve({ access_token: "a token" })))); const auth = new Auth({ clientId: "1234", host, }); auth.http = { fetch: mockFetch, }; const token = await auth.getAccessToken({ scope: userSelfAll, headers: { Cookie: "lpSession=1234" } }); expect(token.accessToken).toEqual("a token"); expect(mockFetch).toHaveBeenCalledWith("http://connect.lonelyplanet.com/oauth/authorize?client_id=1234&scope=openid%20email%20profile%20op%3Ausers%3Aself%3Ar%20op%3Ausers%3Aself%3Au%20op%3Ausers%3Aself%3Ad%20op%3Ausers%3Aself%3Asocial-accounts%3A*%3Ar%20op%3Ausers%3Aself%3Asocial-accounts%3A*%3Ad%20op%3Ausers%3Aself%3Aassociated-roles%3A*%3Ar%20op%3Ausers%3Aself%3Aassociated-badges%3A*%3Ar%20op%3Ausers%3Aself%3Aemail%3Au&redirect_uri=https%3A%2F%2Fconnect.lonelyplanet.com%2Fsso&response_type=token%20id_token&response_mode=ajax&target_link_uri=https%3A%2F%2Fwww.lonelyplanet.com&auth_method=none&nonce=null", {"headers": {"Cookie": "lpSession=1234"}}); }); it("should have scopes", () => { expect(userSelfAll).toMatchSnapshot(); }); });