aboutsummaryrefslogtreecommitdiffstats
path: root/src/tests/pages/CallbackPage.test.tsx
blob: d251772162bab32a5492c05840df06d56deed01b (plain) (blame)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
import React from "react";
import {act, render} from "@testing-library/react";

import CallbackPage from "../../pages/CallbackPage";

test("callback page sends provided code", () => {
    global.opener = {
        postMessage: jest.fn()
    };

    const mockLocation = new URL("https://forms.pythondiscord.com/authorize?code=abcde_code&state=abcde_state");

    act(() => {
        Object.defineProperty(global, "location", {value: mockLocation});
        render(<CallbackPage/>);
    });

    expect(global.opener.postMessage).toBeCalledTimes(1);
    expect(global.opener.postMessage).toBeCalledWith({
        code: "abcde_code",
        state: "abcde_state"
    });
});