mirror of
https://github.com/Azure/cosmos-explorer.git
synced 2025-12-20 17:30:46 +00:00
Use postRobot to listen for GitHub OAuth messages (#729)
This commit is contained in:
@@ -1,12 +1,12 @@
|
||||
import ko from "knockout";
|
||||
import { HttpStatusCodes } from "../Common/Constants";
|
||||
import * as DataModels from "../Contracts/DataModels";
|
||||
import { JunoClient } from "../Juno/JunoClient";
|
||||
import { GitHubConnector, IGitHubConnectorParams } from "./GitHubConnector";
|
||||
import { GitHubOAuthService } from "./GitHubOAuthService";
|
||||
import Explorer from "../Explorer/Explorer";
|
||||
import { ConsoleDataType } from "../Explorer/Menus/NotificationConsole/NotificationConsoleComponent";
|
||||
import NotebookManager from "../Explorer/Notebook/NotebookManager";
|
||||
import Explorer from "../Explorer/Explorer";
|
||||
import { JunoClient } from "../Juno/JunoClient";
|
||||
import { IGitHubConnectorParams } from "./GitHubConnector";
|
||||
import { GitHubOAuthService } from "./GitHubOAuthService";
|
||||
|
||||
const sampleDatabaseAccount: DataModels.DatabaseAccount = {
|
||||
id: "id",
|
||||
@@ -85,25 +85,6 @@ describe("GitHubOAuthService", () => {
|
||||
expect(newParams.get("state")).not.toEqual(initialParams.get("state"));
|
||||
});
|
||||
|
||||
it("finishOAuth is called whenever GitHubConnector is started", async () => {
|
||||
const finishOAuthCallback = jest.fn().mockImplementation();
|
||||
gitHubOAuthService.finishOAuth = finishOAuthCallback;
|
||||
|
||||
const params: IGitHubConnectorParams = {
|
||||
state: "state",
|
||||
code: "code",
|
||||
};
|
||||
const searchParams = new URLSearchParams({ ...params });
|
||||
|
||||
const gitHubConnector = new GitHubConnector();
|
||||
gitHubConnector.start(searchParams, window);
|
||||
|
||||
// GitHubConnector uses Window.postMessage and there's no good way to know when the message has received
|
||||
await new Promise((resolve) => setTimeout(resolve, 100));
|
||||
|
||||
expect(finishOAuthCallback).toBeCalledWith(params);
|
||||
});
|
||||
|
||||
it("finishOAuth updates token", async () => {
|
||||
const data = { key: "value" };
|
||||
const getGitHubTokenCallback = jest.fn().mockReturnValue({ status: HttpStatusCodes.OK, data });
|
||||
|
||||
Reference in New Issue
Block a user