From e4ad8954ba5d102a6c577e682088748b49a66e63 Mon Sep 17 00:00:00 2001 From: Filipe Freire Date: Wed, 9 Nov 2022 13:48:04 +0000 Subject: [PATCH] [INS-2125] Fix workspaces without parentId missing (#5397) * [INS-2125] Fix workspaces without parentId missing * Fix tests? * fix lint --- packages/insomnia/src/models/workspace.ts | 2 ++ .../vcs/__tests__/migrate-collections.test.ts | 22 --------------- .../nunjucks/__tests__/use-nunjucks.test.ts | 28 ------------------- 3 files changed, 2 insertions(+), 50 deletions(-) diff --git a/packages/insomnia/src/models/workspace.ts b/packages/insomnia/src/models/workspace.ts index 04b6db7aa..2a54c8d76 100644 --- a/packages/insomnia/src/models/workspace.ts +++ b/packages/insomnia/src/models/workspace.ts @@ -160,7 +160,9 @@ function _migrateScope(workspace: MigrationWorkspace) { function _migrateIntoDefaultProject(workspace: Workspace) { if (!workspace.parentId) { + console.log(`No workspace parentId found for ${workspace._id} setting default ${DEFAULT_PROJECT_ID}`); workspace.parentId = DEFAULT_PROJECT_ID; + models.workspace.update(workspace, { parentId: DEFAULT_PROJECT_ID }); } return workspace; diff --git a/packages/insomnia/src/sync/vcs/__tests__/migrate-collections.test.ts b/packages/insomnia/src/sync/vcs/__tests__/migrate-collections.test.ts index c4ac3457c..92113ad0a 100644 --- a/packages/insomnia/src/sync/vcs/__tests__/migrate-collections.test.ts +++ b/packages/insomnia/src/sync/vcs/__tests__/migrate-collections.test.ts @@ -6,7 +6,6 @@ import { globalBeforeEach } from '../../../__jest__/before-each'; import { isLoggedIn as _isLoggedIn } from '../../../account/session'; import { database } from '../../../common/database'; import * as models from '../../../models'; -import { DEFAULT_PROJECT_ID } from '../../../models/project'; import { backendProjectWithTeamSchema, teamSchema } from '../../__schemas__/type-schemas'; import MemoryDriver from '../../store/drivers/memory-driver'; import { initializeProjectFromTeam } from '../initialize-model-from'; @@ -46,27 +45,6 @@ describe('migrateCollectionsIntoRemoteProject', () => { expect(vcs.remoteBackendProjectsInAnyTeam).not.toHaveBeenCalled(); }); - it('does not migrate if collection is in non-remote project but no local backend project exists', async () => { - // Arrange - const vcs = newMockedVcs(); - - const defaultProject = await models.project.getById(DEFAULT_PROJECT_ID); - const workspaceInBase = await models.workspace.create({ parentId: defaultProject?._id }); - - const localProject = await models.project.create(); - const workspaceInLocal = await models.workspace.create({ parentId: localProject._id }); - - vcs.hasBackendProjectForRootDocument.mockResolvedValue(false); // no local backend project - - // Act - await migrateCollectionsIntoRemoteProject(vcs); - - // Assert - expect(vcs.remoteBackendProjectsInAnyTeam).not.toHaveBeenCalled(); - await expect(models.workspace.getById(workspaceInBase._id)).resolves.toStrictEqual(workspaceInBase); - await expect(models.workspace.getById(workspaceInLocal._id)).resolves.toStrictEqual(workspaceInLocal); - }); - it('does not migrate if all collections are in a remote project already', async () => { // Arrange const vcs = newMockedVcs(); diff --git a/packages/insomnia/src/ui/context/nunjucks/__tests__/use-nunjucks.test.ts b/packages/insomnia/src/ui/context/nunjucks/__tests__/use-nunjucks.test.ts index 4296d03ac..f4a2dea79 100644 --- a/packages/insomnia/src/ui/context/nunjucks/__tests__/use-nunjucks.test.ts +++ b/packages/insomnia/src/ui/context/nunjucks/__tests__/use-nunjucks.test.ts @@ -87,34 +87,6 @@ describe('useNunjucks', () => { ancestors: mockAncestors, }); }); - - it('should get context using the active entities - no request', async () => { - // Arrange - const workspace = await models.workspace.create(); - await models.workspaceMeta.getOrCreateByParentId(workspace._id); - const environment = await models.environment.getOrCreateForParentId(workspace._id); - - await models.workspaceMeta.updateByParentId(workspace._id, { - activeEnvironmentId: environment._id, - }); - - const store = mockStore(await reduxStateForTest({ - activeActivity: ACTIVITY_DEBUG, - activeWorkspaceId: workspace._id, - })); - - // Act - const { result } = renderHook(useNunjucks, { wrapper: withReduxStore(store) }); - await result.current.handleGetRenderContext(); - - // Assert - expect(getRenderContextAncestorsMock).toBeCalledWith(workspace); - expect(getRenderContextMock).toBeCalledWith({ - request: undefined, - environmentId: environment._id, - ancestors: mockAncestors, - }); - }); }); describe('handleRender', () => {