Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Universal Insomnia/Git Sync for all files (documents/collections) #5945

Merged
merged 28 commits into from
Jul 5, 2023
Merged
Show file tree
Hide file tree
Changes from 27 commits
Commits
Show all changes
28 commits
Select commit Hold shift + click to select a range
4dd6c4a
share design documents and tests with insomnia sync
gatzjames May 4, 2023
63bd527
share collection and documents with insomnia/git sync
gatzjames May 8, 2023
48140a3
checkpoint
gatzjames May 12, 2023
eaec095
redirect when cloning (pulling) a new remote project
gatzjames May 15, 2023
963ed19
backend workspace card
gatzjames May 15, 2023
f72f31c
redirect logic
gatzjames May 15, 2023
58b448f
local changes styles
gatzjames May 15, 2023
b801fe1
loading indicator
gatzjames May 24, 2023
5caa0b5
fix sync button styles
gatzjames Jun 2, 2023
33d211c
use interval to refetch git
gatzjames Jun 2, 2023
158299f
open the repo modal first before switching to git sync
gatzjames Jun 2, 2023
1ea0377
use gitRepositoryId from metadata
gatzjames Jul 5, 2023
34dfb08
fix sync option update
gatzjames Jul 5, 2023
78364d9
cleanup fetcher check
gatzjames Jul 5, 2023
675ce3c
fixes
gatzjames Jul 5, 2023
a702ba2
cleanup pull-push
gatzjames Jul 5, 2023
c666d5d
undo logo change
gatzjames Jul 5, 2023
f50746f
clean git-vcs
gatzjames Jul 5, 2023
3f2649b
use cloud icon for insomnia sync
gatzjames Jul 5, 2023
4b3f96a
cleanup card
gatzjames Jul 5, 2023
a1f30e0
more cleanup
gatzjames Jul 5, 2023
7f53204
better return type for fetchfetcher
gatzjames Jul 5, 2023
fa9fa2c
update git tests
gatzjames Jul 5, 2023
5ea7d9c
fix tests
gatzjames Jul 5, 2023
8fbe4b4
fix some prerelease tests
gatzjames Jul 5, 2023
1230ae6
fix cloning without an api spec
gatzjames Jul 5, 2023
96eae90
fix some more tests that expect a file to exist
gatzjames Jul 5, 2023
871290b
fix lint error
gatzjames Jul 5, 2023
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ test.describe('Cookie editor', async () => {
await page.getByRole('menuitem', { name: 'Import' }).click();
await page.getByText('Clipboard').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('button', { name: 'Import' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('Collectionsimplejust now').click();
});

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,8 @@ test.describe('Dashboard', async () => {
test.slow(process.platform === 'darwin' || process.platform === 'win32', 'Slow app start on these platforms');
test.describe('Projects', async () => {
test('Can create, rename and delete new project', async ({ page }) => {
await expect(page.locator('.app')).toContainText('All Files (1)');
await expect(page.locator('.app')).toContainText('All Files (0)');
await expect(page.locator('.app')).not.toContainText('Git Sync');
await expect(page.locator('.app')).not.toContainText('Setup Git Sync');

// Create new project
Expand Down Expand Up @@ -41,14 +42,15 @@ test.describe('Dashboard', async () => {
await expect(page.locator('.app')).toContainText('Insomnia');
await expect(page.locator('.app')).not.toContainText('My Project123');
await expect(page.locator('.app')).toContainText('New Document');
await expect(page.locator('.app')).toContainText('All Files (1)');
await expect(page.locator('.app')).toContainText('All Files (0)');
await expect(page.locator('.app')).not.toContainText('Setup Git Sync');
});
});
test.describe('Interactions', async () => { // Not sure about the name here
// TODO(INS-2504) - we don't support importing multiple collections at this time
test.skip('Can filter through multiple collections', async ({ app, page }) => {
await expect(page.locator('.app')).toContainText('All Files (1)');
await expect(page.locator('.app')).toContainText('All Files (0)');
await expect(page.locator('.app')).not.toContainText('Git Sync');
await expect(page.locator('.app')).not.toContainText('Setup Git Sync');

await page.getByRole('button', { name: 'Create' }).click();
Expand All @@ -57,7 +59,7 @@ test.describe('Dashboard', async () => {
await page.getByRole('menuitem', { name: 'Import' }).click();
await page.getByText('Clipboard').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('button', { name: 'Import' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('CollectionSmoke testsjust now').click();
// Check that 10 new workspaces are imported besides the default one
const workspaceCards = page.locator('.card-badge');
Expand Down Expand Up @@ -85,18 +87,19 @@ test.describe('Dashboard', async () => {
});

test('Can create, rename and delete a document', async ({ page }) => {
await expect(page.locator('.app')).toContainText('All Files (1)');
await expect(page.locator('.app')).toContainText('All Files (0)');
await expect(page.locator('.app')).not.toContainText('Git Sync');
await expect(page.locator('.app')).not.toContainText('Setup Git Sync');

// Create new document
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('menuitem', { name: 'Design Document' }).click();
await page.locator('text=Create').nth(1).click();

// Return to dashboardawait expect(page.locator('.app')).toContainText('My Document');
await page.getByTestId('proj_default-project').getByRole('link', { name: 'Insomnia' }).click();

// Rename document
await page.click('text=DocumentMy Documentjust now >> button');
await page.click('text=DocumentNew Documentjust now >> button');
await page.getByRole('menuitem', { name: 'Rename' }).click();
await page.locator('text=Rename DocumentName Rename >> input[type="text"]').fill('test123');
await page.click('#root button:has-text("Rename")');
Expand All @@ -108,28 +111,29 @@ test.describe('Dashboard', async () => {
await page.locator('input[name="name"]').fill('test123-duplicate');
await page.click('[role="dialog"] button:has-text("Duplicate")');

// Return to dashboardawait expect(page.locator('.app')).toContainText('test123-duplicate');
await page.getByTestId('proj_default-project').getByRole('link', { name: 'Insomnia' }).click();

const workspaceCards = page.locator('.card-badge');
await expect(workspaceCards).toHaveCount(3);
await expect(workspaceCards).toHaveCount(2);

// Delete document
await page.click('text=Documenttest123just now >> button');
await page.getByRole('menuitem', { name: 'Delete' }).click();
await page.locator('text=Yes').click();
await expect(workspaceCards).toHaveCount(2);
await expect(workspaceCards).toHaveCount(1);
});

test('Can create, rename and delete a collection', async ({ page }) => {
await expect(page.locator('.app')).toContainText('All Files (1)');
await expect(page.locator('.app')).toContainText('All Files (0)');
await expect(page.locator('.app')).not.toContainText('Git Sync');
await expect(page.locator('.app')).not.toContainText('Setup Git Sync');

// Create new collection
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('menuitem', { name: 'Request Collection' }).click();
await page.locator('text=Create').nth(1).click();

// Return to dashboardawait expect(page.locator('.app')).toContainText('My Collection');
await page.getByTestId('proj_default-project').getByRole('link', { name: 'Insomnia' }).click();

// Rename collection
await page.click('text=CollectionMy Collectionjust now >> button');
Expand All @@ -144,15 +148,15 @@ test.describe('Dashboard', async () => {
await page.locator('input[name="name"]').fill('test123-duplicate');
await page.click('[role="dialog"] button:has-text("Duplicate")');

// Return to dashboardawait expect(page.locator('.app')).toContainText('test123-duplicate');
await page.getByTestId('proj_default-project').getByRole('link', { name: 'Insomnia' }).click();
const workspaceCards = page.locator('.card-badge');
await expect(workspaceCards).toHaveCount(3);
await expect(workspaceCards).toHaveCount(2);

// Delete collection
await page.click('text=Collectiontest123just now >> button');
await page.getByRole('menuitem', { name: 'Delete' }).click();
await page.locator('text=Yes').click();
await expect(workspaceCards).toHaveCount(2);
await expect(workspaceCards).toHaveCount(1);
});
});
});
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ test.describe('Debug-Sidebar', async () => {
await page.getByRole('menuitem', { name: 'Import' }).click();
await page.getByText('Clipboard').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('button', { name: 'Import' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('Collectionsimplejust now').click();
});

Expand Down Expand Up @@ -61,9 +61,9 @@ test.describe('Debug-Sidebar', async () => {
});

test('Open properties of the collection', async ({ page }) => {
await page.getByRole('button', { name: 'Untitled' }).click();
await page.getByRole('menuitem', { name: 'Document Settings' }).click();
await page.getByText('Document Settings').click();
await page.getByRole('button', { name: 'simple' }).click();
await page.getByRole('menuitem', { name: 'Collection Settings' }).click();
await page.getByText('Collection Settings').click();
});

test('Filter by request name', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,8 @@ test.describe('Design interactions', async () => {
await page.getByRole('menuitem', { name: 'Import' }).click();
await page.getByText('Clipboard').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('button', { name: 'Import' }).click();
await page.getByText('CollectionSmoke testsjust now').click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('unit-test.yaml').click();
// Switch to Test tab
await page.click('a:has-text("Test")');

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,8 @@ test.describe('Environment Editor', async () => {
await page.getByRole('menuitem', { name: 'Import' }).click();
await page.getByText('Clipboard').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('button', { name: 'Import' }).click();
await page.getByText('CollectionSmoke testsjust now').click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('Collectionenvironments').click();
});

test('create a new environment', async ({ page }) => {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,7 +13,7 @@ test('Clone Repo with bad values', async ({ page }) => {
await page.getByText('Author Email').fill('test');
await page.getByText('Username').fill('test');
await page.getByText('Authentication Token').fill('test');
await page.getByRole('button', { name: 'Clone' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Clone' }).click();

// Basic check repository data is loaded
// Design doc
Expand Down Expand Up @@ -50,31 +50,6 @@ test('Clone Repo with bad values', async ({ page }) => {
await expect(page.locator('.app')).toContainText('Error Pushing Repository');
});

test('Clone Bitbucket Repo with bad values', async ({ page }) => {
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('menuitem', { name: 'Git Clone' }).click();
await page.getByRole('tab', { name: 'Git' }).nth(2).click();

// Fill in Git Sync details and clone repository
await page.getByText('Git URI (https)').fill('https://bitbucket.org/atlassian/bitbucket-example-plugin.git');
await page.getByText('Author Name').fill('test');
await page.getByText('Author Email').fill('test');
await page.getByText('Username').fill('test');
await page.getByText('Authentication Token').fill('test');
await page.getByRole('button', { name: 'Clone' }).click();

// Create a branch and try to push with bad Git token
await page.getByRole('button', { name: 'master' }).click();
await page.getByRole('menuitem', { name: 'Branches' }).click();
await page.getByPlaceholder('testing-branch').fill('test123');
await page.getByRole('button', { name: '+ Create' }).click();
await page.getByRole('cell', { name: 'test123(current)' }).click();
await page.getByRole('button', { name: 'Done' }).click();
await page.getByRole('button', { name: 'test123' }).click();
await page.getByRole('menuitem', { name: 'Push' }).click();
await expect(page.locator('.app')).toContainText('Error Pushing Repository');
});

test('Clone Gitlab Repo with bad values', async ({ page }) => {
await page.getByRole('button', { name: 'Create' }).click();
await page.getByRole('menuitem', { name: 'Git Clone' }).click();
Expand All @@ -86,7 +61,7 @@ test('Clone Gitlab Repo with bad values', async ({ page }) => {
await page.getByText('Author Email').fill('test');
await page.getByText('Username').fill('test');
await page.getByText('Authentication Token').fill('test');
await page.getByRole('button', { name: 'Clone' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Clone' }).click();

// Create a branch and try to push with bad Git token
await page.getByRole('button', { name: 'master' }).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ test.describe('gRPC interactions', () => {
await page.getByRole('menuitem', { name: 'Import' }).click();
await page.getByText('Clipboard').click();
await page.getByRole('button', { name: 'Scan' }).click();
await page.getByRole('button', { name: 'Import' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Import' }).click();
await page.getByText('CollectionPreRelease gRPCjust now').click();
statusTag = page.locator('[data-testid="response-status-tag"]:visible');
responseBody = page.locator('[data-testid="response-pane"] >> [data-testid="CodeEditor"]:visible', {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,8 +18,8 @@ test.describe('Plugins', async () => {
});

test('Check Declarative Config and Kong Kubernetes config', async ({ page }) => {
// Switch to design tab
await page.click('text=Design');
await page.getByRole('button', { name: 'New Document' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click();

// Set example OpenAPI spec
await page.click('text=start from an example');
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,13 @@
import { test } from '../../playwright/test';

test.beforeEach(async ({ page }) => {
await page.getByRole('button', { name: 'New Collection' }).click();
await page.getByRole('dialog').getByRole('button', { name: 'Create' }).click();

await page.getByRole('button', { name: ' ' }).press('ArrowDown');
await page.getByRole('menuitem', { name: 'HTTP Request' }).press('Enter');
});

test('Select body dropdown', async ({ page }) => {
await page.getByRole('button', { name: 'Body' }).click();
await page.getByRole('menuitem', { name: 'JSON' }).click();
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia-smoke-test/tests/smoke/git-sync.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ 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: 'Git Sync' }).click();
await page.getByRole('button', { name: 'Setup Git Sync' }).click();

await page.getByRole('tab', { name: 'Github' }).click();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ import { test } from '../../playwright/test';
test('Sign in with Gitlab', 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: 'Git Sync' }).click();
await page.getByRole('button', { name: 'Setup Git Sync' }).click();
await page.getByRole('tab', { name: 'GitLab' }).click();

Expand Down
2 changes: 1 addition & 1 deletion packages/insomnia/src/models/api-spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ export const prefix = 'spc';

export const canDuplicate = true;

export const canSync = false;
export const canSync = true;

export interface BaseApiSpec {
fileName: string;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,24 +9,6 @@ import { VCS } from '../vcs';
describe('initialize-backend-project', () => {
beforeEach(globalBeforeEach);

describe('initializeLocalBackendProjectAndMarkForSync()', () => {
it('should do nothing if not request collection', async () => {
// Arrange
const workspace = await models.workspace.create({ scope: 'design' });
const vcs = new VCS(new MemoryDriver());
const switchAndCreateBackendProjectIfNotExistSpy = jest.spyOn(vcs, 'switchAndCreateBackendProjectIfNotExist');

// Act
await initializeLocalBackendProjectAndMarkForSync({ workspace, vcs });

// Assert
expect(switchAndCreateBackendProjectIfNotExistSpy).not.toHaveBeenCalled();
// const workspaceMeta = await models.workspaceMeta.getByParentId(workspace._id);
// expect(workspaceMeta?.pushSnapshotOnInitialize).toBe(false);
switchAndCreateBackendProjectIfNotExistSpy.mockClear();
});
});

describe('pushSnapshotOnInitialize()', () => {
const vcs = new VCS(new MemoryDriver());

Expand Down
7 changes: 1 addition & 6 deletions packages/insomnia/src/sync/vcs/initialize-backend-project.ts
Original file line number Diff line number Diff line change
Expand Up @@ -2,18 +2,13 @@ import { database } from '../../common/database';
import * as models from '../../models';
import { getStatusCandidates } from '../../models/helpers/get-status-candidates';
import { Project } from '../../models/project';
import { isCollection, Workspace } from '../../models/workspace';
import { Workspace } from '../../models/workspace';
import { WorkspaceMeta } from '../../models/workspace-meta';
import { VCS } from './vcs';

const blankStage = {};

export const initializeLocalBackendProjectAndMarkForSync = async ({ vcs, workspace }: { vcs: VCS; workspace: Workspace }) => {
if (!isCollection(workspace)) {
// Don't initialize and mark for sync unless we're in a collection
return;
}

// Create local project
await vcs.switchAndCreateBackendProjectIfNotExist(workspace._id, workspace.name);

Expand Down
4 changes: 2 additions & 2 deletions packages/insomnia/src/sync/vcs/migrate-collections.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
import { isLoggedIn } from '../../account/session';
import { asyncFilter } from '../../common/async-array-helpers';
import { database } from '../../common/database';
import { isNotNullOrUndefined } from '../../common/misc';
import * as models from '../../models';
import { isRemoteProject, RemoteProject } from '../../models/project';
import { isCollection, Workspace } from '../../models/workspace';
Expand Down Expand Up @@ -36,7 +36,7 @@ export const migrateCollectionsIntoRemoteProject = async (vcs: VCS) => {
const isNotInRemoteProject = (collection: Workspace) => !Boolean(remoteProjects.find(project => project._id === collection.parentId));
const hasLocalProject = (collection: Workspace) => vcs.hasBackendProjectForRootDocument(collection._id);

const needsMigration = await asyncFilter(collections, async coll => await hasLocalProject(coll) && isNotInRemoteProject(coll));
const needsMigration = (await Promise.all(collections.map(async coll => await hasLocalProject(coll) && isNotInRemoteProject(coll) ? coll : null))).filter(isNotNullOrUndefined);

// If nothing to migrate, exit
if (!needsMigration.length) {
Expand Down