insomnia/packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts
Jack Kavanagh 90b9516d55
make all migration functions non-async (#6043)
* make all migration functions non-async

* migrate is not a promise

* simplify scope migration

* remove apispec and fix test

* fix tests

* fix tests, for real this time

* removed api spec from collection

* default doc name to my-spec.yaml again

* fix apispec typing

* remove pointless generic

* fix type

* Create an api spec on first launch

* Remove flaky firstLaunch data creation

* fix test

* create apispec only when scope is deisgn

* oauth test left

* gitlab test

---------

Co-authored-by: gatzjames <jamesgatzos@gmail.com>
2023-06-27 20:46:43 +02:00

50 lines
2.1 KiB
TypeScript

import { test } from '../../playwright/test';
test('Sign in with GitHub', async ({ app, page }) => {
await page.getByRole('button', { name: 'New Document' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click();
await page.getByRole('button', { name: 'Setup Git Sync' }).click();
await page.getByRole('tab', { name: 'Github' }).click();
// Prevent the app from opening the browser to the authorization page
// and return the url that would be created by following the GitHub OAuth flow.
// https://docs.github.com/en/developers/apps/building-oauth-apps/authorizing-oauth-apps#web-application-flow
const fakeGitHubOAuthWebFlow = app.evaluate(electron => {
return new Promise<{ redirectUrl: string }>(resolve => {
const webContents = electron.BrowserWindow.getAllWindows()[0].webContents;
// Remove all navigation listeners so that only the one we inject will run
webContents.removeAllListeners('will-navigate');
webContents.on('will-navigate', (event: Event, url: string) => {
event.preventDefault();
const parsedUrl = new URL(url);
// We use the same state parameter that the app created to assert that we prevent CSRF
const stateSearchParam = parsedUrl.searchParams.get('state') || '';
const redirectUrl = `insomnia://oauth/github/authenticate?state=${stateSearchParam}&code=12345`;
resolve({ redirectUrl });
});
});
});
const [{ redirectUrl }] = await Promise.all([
fakeGitHubOAuthWebFlow,
page.getByText('Authenticate with GitHub').click({
// When playwright clicks a link it waits for navigation to finish.
// In our case we are stubbing the navigation and we don't want to wait for it.
noWaitAfter: true,
}),
]);
await page.locator('input[name="link"]').click();
await page.locator('input[name="link"]').fill(redirectUrl);
await page.getByRole('button', { name: 'Add' }).click();
await page
.locator('input[name="uri"]')
.fill('https://github.com/insomnia/example-repo');
await page.locator('data-testid=git-repository-settings-modal__sync-btn').click();
});