mirror of
https://github.com/Kong/insomnia
synced 2024-11-08 06:39:48 +00:00
Always generate base environment id when importing (#4378)
* Always generate base environment id when importing * add unit test * fix lint Co-authored-by: Filipe Freire <livrofubia@gmail.com>
This commit is contained in:
parent
3fe9981531
commit
fe4df702dd
@ -9,6 +9,7 @@ test.describe('Cookie editor', async () => {
|
||||
const text = await loadFixture('simple.yaml');
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=Collectionsimplejust now');
|
||||
});
|
||||
|
||||
|
@ -25,6 +25,9 @@ test.describe('Dashboard', async () => {
|
||||
await page.click('[placeholder="My Project"]');
|
||||
await page.locator('[placeholder="My Project"]').fill('My Project123');
|
||||
|
||||
// Check that the project name is updated on modal
|
||||
await expect(page.locator('.app')).toContainText('My Project123');
|
||||
|
||||
// Close project settings modal
|
||||
await page.locator('.app').press('Escape');
|
||||
await expect(page.locator('.app')).toContainText('My Project123');
|
||||
@ -54,6 +57,7 @@ test.describe('Dashboard', async () => {
|
||||
const text = await loadFixture('multiple-workspaces.yaml');
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
|
||||
// Check that 10 new workspaces are imported besides the default one
|
||||
const workspaceCards = page.locator('.card-badge');
|
||||
|
@ -11,6 +11,7 @@ test.describe('Debug-Sidebar', async () => {
|
||||
const text = await loadFixture('simple.yaml');
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=Collectionsimplejust now');
|
||||
});
|
||||
|
||||
|
@ -57,6 +57,7 @@ test.describe('Design interactions', async () => {
|
||||
const text = await loadFixture('unit-test.yaml');
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=unit-test.yamljust now');
|
||||
|
||||
// Switch to Test tab
|
||||
|
@ -17,6 +17,7 @@ test('can send requests', async ({ app, page }) => {
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=CollectionSmoke testsjust now');
|
||||
|
||||
await page.click('button:has-text("GETsend JSON request")');
|
||||
@ -69,6 +70,7 @@ test('can cancel requests', async ({ app, page }) => {
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=CollectionSmoke testsjust now');
|
||||
|
||||
await page.click('button:has-text("GETdelayed request")');
|
||||
|
@ -16,6 +16,8 @@ test('can render schema and send GraphQL requests', async ({ app, page }) => {
|
||||
|
||||
// Import from clipboard
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
// Import as new collection
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
// Open the new collection workspace
|
||||
await page.click('text=CollectionSmoke GraphQLjust now');
|
||||
// Open the graphql request
|
||||
|
@ -17,6 +17,7 @@ test('can send gRPC requests', async ({ app, page }) => {
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=CollectionSmoke gRPCjust now');
|
||||
|
||||
await page.click('button:has-text("gRPCsay hi!")');
|
||||
|
@ -24,6 +24,7 @@ test('can make oauth2 requests', async ({ app, page }) => {
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
|
||||
await page.locator('button:has-text("Clipboard")').click();
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.locator('text=CollectionOauth Testingjust now').click();
|
||||
|
||||
// Authorization code
|
||||
|
@ -17,6 +17,7 @@ test('can make websocket connection', async ({ app, page }) => {
|
||||
await app.evaluate(async ({ clipboard }, text) => clipboard.writeText(text), text);
|
||||
|
||||
await page.click('button:has-text("Clipboard")');
|
||||
await page.click('div[role="dialog"] button:has-text("New")');
|
||||
await page.click('text=CollectionWebSocketsjust now');
|
||||
|
||||
await page.click('button:has-text("localhost:4010")');
|
||||
|
@ -0,0 +1,70 @@
|
||||
_type: export
|
||||
__export_format: 4
|
||||
__export_date: 2022-11-29T16:27:19.066Z
|
||||
__export_source: insomnia.desktop.app:v2022.7.0-beta.5
|
||||
resources:
|
||||
- _id: req_123
|
||||
parentId: wrk_123
|
||||
modified: 1669739211182
|
||||
created: 1669739179867
|
||||
url: mockbin.org/request/any/{{ _.base }}/{{ _.sub }}
|
||||
name: New Request
|
||||
description: ""
|
||||
method: GET
|
||||
body: {}
|
||||
parameters: []
|
||||
headers: []
|
||||
authentication: {}
|
||||
metaSortKey: -1669739179868
|
||||
isPrivate: false
|
||||
settingStoreCookies: true
|
||||
settingSendCookies: true
|
||||
settingDisableRenderRequestBody: false
|
||||
settingEncodeUrl: true
|
||||
settingRebuildPath: true
|
||||
settingFollowRedirects: global
|
||||
_type: request
|
||||
- _id: wrk_123
|
||||
parentId: null
|
||||
modified: 1669739177487
|
||||
created: 1669739177487
|
||||
name: Example
|
||||
description: ""
|
||||
scope: collection
|
||||
_type: workspace
|
||||
- _id: env_123_from_export
|
||||
parentId: wrk_123
|
||||
modified: 1669739193740
|
||||
created: 1669739177493
|
||||
name: Base Environment
|
||||
data:
|
||||
base: 123
|
||||
dataPropertyOrder:
|
||||
"&":
|
||||
- base
|
||||
color: null
|
||||
isPrivate: false
|
||||
metaSortKey: 1669739177493
|
||||
_type: environment
|
||||
- _id: spc_5c1a165d02d34d228374d37566154a4a
|
||||
parentId: wrk_123
|
||||
modified: 1669739177487
|
||||
created: 1669739177487
|
||||
fileName: Example
|
||||
contents: ""
|
||||
contentType: yaml
|
||||
_type: api_spec
|
||||
- _id: env_sub123
|
||||
parentId: env_123_from_export
|
||||
modified: 1669739204645
|
||||
created: 1669739194224
|
||||
name: sub
|
||||
data:
|
||||
sub: 456
|
||||
dataPropertyOrder:
|
||||
"&":
|
||||
- sub
|
||||
color: null
|
||||
isPrivate: false
|
||||
metaSortKey: 1669739194224
|
||||
_type: environment
|
@ -3,7 +3,7 @@ import fs from 'fs';
|
||||
import path from 'path';
|
||||
|
||||
import { globalBeforeEach } from '../../__jest__/before-each';
|
||||
import { apiSpec, request, requestGroup, workspace } from '../../models';
|
||||
import { apiSpec, environment, request, requestGroup, workspace } from '../../models';
|
||||
import { DEFAULT_PROJECT_ID } from '../../models/project';
|
||||
import * as importUtil from '../import';
|
||||
|
||||
@ -198,4 +198,33 @@ describe('importRaw()', () => {
|
||||
|
||||
expect(createdApiSpec?.contents).toContain('openapi: \'3.0.2\'');
|
||||
});
|
||||
|
||||
it('should not leave dangling environments when reimporting a collection', async () => {
|
||||
const fixturePath = path.join(__dirname, '..', '__fixtures__', 'insomnia', 'insomnia-example-input.yaml');
|
||||
const rawFixture = fs.readFileSync(fixturePath, 'utf8').toString();
|
||||
|
||||
const existingWorkspace = await workspace.create({ scope: 'collection', _id: 'wrk_123' });
|
||||
|
||||
// Simulate pre-existing base and sub environment
|
||||
await environment.create({ parentId: 'wrk_123', _id: 'env_123' });
|
||||
await environment.create({ parentId: 'env_123', _id: 'env_sub123' });
|
||||
|
||||
const importConfig: importUtil.ImportRawConfig = {
|
||||
getWorkspaceId: () => existingWorkspace._id,
|
||||
getProjectId: async () => DEFAULT_PROJECT_ID,
|
||||
getWorkspaceScope: () => 'collection',
|
||||
};
|
||||
|
||||
await importUtil.importRaw(
|
||||
rawFixture,
|
||||
importConfig
|
||||
);
|
||||
|
||||
const totalEnvironments = await environment.all();
|
||||
const baseEnvironmentsFound = await environment.findByParentId('wrk_123');
|
||||
const subEnvironmentsFound = await environment.findByParentId('env_123');
|
||||
expect(totalEnvironments).toHaveLength(2);
|
||||
expect(baseEnvironmentsFound).toHaveLength(1);
|
||||
expect(subEnvironmentsFound).toHaveLength(1);
|
||||
});
|
||||
});
|
||||
|
@ -15,6 +15,7 @@ import { convert, ConvertResultType } from '../utils/importers/convert';
|
||||
import {
|
||||
BASE_ENVIRONMENT_ID_KEY,
|
||||
CONTENT_TYPE_GRAPHQL,
|
||||
EXPORT_TYPE_ENVIRONMENT,
|
||||
EXPORT_TYPE_WORKSPACE,
|
||||
WORKSPACE_ID_KEY,
|
||||
} from './constants';
|
||||
@ -189,6 +190,15 @@ export async function importRaw(
|
||||
resource.parentId = WORKSPACE_ID_KEY;
|
||||
}
|
||||
|
||||
// Always generate base environment id, ensuring to not create another one
|
||||
if (resource._type === EXPORT_TYPE_ENVIRONMENT) {
|
||||
if (resource.parentId === WORKSPACE_ID_KEY || resource.parentId.match(`${models.workspace.prefix}_\w*`)) {
|
||||
resource._id = BASE_ENVIRONMENT_ID_KEY;
|
||||
} else {
|
||||
resource.parentId = BASE_ENVIRONMENT_ID_KEY;
|
||||
}
|
||||
}
|
||||
|
||||
// Replace ID placeholders (eg. __WORKSPACE_ID__) with generated values
|
||||
for (const key of Object.keys(generatedIds)) {
|
||||
const { parentId, _id } = resource;
|
||||
|
Loading…
Reference in New Issue
Block a user