mirror of
https://github.com/Kong/insomnia.git
synced 2026-04-23 15:49:42 -04:00
fix tests
This commit is contained in:
@@ -2,7 +2,7 @@ import path from 'node:path';
|
||||
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { type Cookie, models, type Request, type Response } from '~/insomnia-data';
|
||||
import { type Cookie, models, type Request, type Response, services } from '~/insomnia-data';
|
||||
|
||||
import { database as db } from '../../common/database';
|
||||
import { exportHar, exportHarResponse, exportHarWithRequest } from '../har';
|
||||
@@ -11,17 +11,17 @@ import { getRenderedRequestAndContext } from '../render';
|
||||
describe('export', () => {
|
||||
beforeEach(async () => {
|
||||
await db.init({ inMemoryOnly: true }, true);
|
||||
await models.project.all();
|
||||
await services.project.all();
|
||||
await services.settings.getOrCreate();
|
||||
});
|
||||
|
||||
describe('exportHar()', () => {
|
||||
it('exports single requests', async () => {
|
||||
const wrk = await models.workspace.create({
|
||||
const wrk = await services.workspace.create({
|
||||
_id: 'wrk_1',
|
||||
name: 'Workspace',
|
||||
});
|
||||
const req1 = await models.request.create({
|
||||
const req1 = await services.request.create({
|
||||
_id: 'req_1',
|
||||
name: 'Request 1',
|
||||
parentId: wrk._id,
|
||||
@@ -48,7 +48,7 @@ describe('export', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
await models.response.create({
|
||||
await services.response.create({
|
||||
parentId: req1._id,
|
||||
statusCode: 200,
|
||||
statusMessage: 'OK',
|
||||
@@ -141,11 +141,11 @@ describe('export', () => {
|
||||
});
|
||||
|
||||
it('exports multiple requests', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_1',
|
||||
name: 'Workspace',
|
||||
});
|
||||
const baseReq = await models.request.create({
|
||||
const baseReq = await services.request.create({
|
||||
_id: 'req_0',
|
||||
type: models.request.type,
|
||||
name: 'Request',
|
||||
@@ -160,37 +160,37 @@ describe('export', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
const req1 = await models.request.duplicate(baseReq);
|
||||
const req1 = await services.request.duplicate(baseReq);
|
||||
req1._id = 'req_1';
|
||||
req1.name = 'Request 1';
|
||||
req1.headers.push({
|
||||
name: 'X-Request',
|
||||
value: '1',
|
||||
});
|
||||
await models.request.create(req1);
|
||||
const req2 = await models.request.duplicate(baseReq);
|
||||
await services.request.create(req1);
|
||||
const req2 = await services.request.duplicate(baseReq);
|
||||
req2._id = 'req_2';
|
||||
req2.name = 'Request 2';
|
||||
req2.headers.push({
|
||||
name: 'X-Request',
|
||||
value: '2',
|
||||
});
|
||||
await models.request.create(req2);
|
||||
const req3 = await models.request.duplicate(baseReq);
|
||||
await services.request.create(req2);
|
||||
const req3 = await services.request.duplicate(baseReq);
|
||||
req3._id = 'req_3';
|
||||
req3.name = 'Request 3';
|
||||
req3.headers.push({
|
||||
name: 'X-Request',
|
||||
value: '3',
|
||||
});
|
||||
await models.request.create(req3);
|
||||
const envBase = await models.environment.getOrCreateForParentId(workspace._id);
|
||||
await models.environment.update(envBase, {
|
||||
await services.request.create(req3);
|
||||
const envBase = await services.environment.getOrCreateForParentId(workspace._id);
|
||||
await services.environment.update(envBase, {
|
||||
data: {
|
||||
envvalue: '',
|
||||
},
|
||||
});
|
||||
const envPublic = await models.environment.create({
|
||||
const envPublic = await services.environment.create({
|
||||
_id: 'env_1',
|
||||
name: 'Public',
|
||||
parentId: envBase._id,
|
||||
@@ -198,7 +198,7 @@ describe('export', () => {
|
||||
envvalue: 'public',
|
||||
},
|
||||
});
|
||||
const envPrivate = await models.environment.create({
|
||||
const envPrivate = await services.environment.create({
|
||||
_id: 'env_2',
|
||||
name: 'Private',
|
||||
isPrivate: true,
|
||||
@@ -207,17 +207,17 @@ describe('export', () => {
|
||||
envvalue: 'private',
|
||||
},
|
||||
});
|
||||
await models.response.create({
|
||||
await services.response.create({
|
||||
_id: 'res_1',
|
||||
parentId: req1._id,
|
||||
statusCode: 204,
|
||||
});
|
||||
await models.response.create({
|
||||
await services.response.create({
|
||||
_id: 'res_2',
|
||||
parentId: req2._id,
|
||||
statusCode: 404,
|
||||
});
|
||||
await models.response.create({
|
||||
await services.response.create({
|
||||
_id: 'res_3',
|
||||
parentId: req3._id,
|
||||
statusCode: 500,
|
||||
@@ -390,7 +390,7 @@ describe('export', () => {
|
||||
|
||||
describe('exportHarWithRequest()', () => {
|
||||
it('renders does it correctly', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const cookies: Cookie[] = [
|
||||
{
|
||||
id: '',
|
||||
@@ -406,8 +406,8 @@ describe('export', () => {
|
||||
lastAccessed: new Date('2096-10-05T04:40:49.505Z'),
|
||||
},
|
||||
];
|
||||
const cookieJar = await models.cookieJar.getOrCreateForParentId(workspace._id);
|
||||
await models.cookieJar.update(cookieJar, {
|
||||
const cookieJar = await services.cookieJar.getOrCreateForParentId(workspace._id);
|
||||
await services.cookieJar.update(cookieJar, {
|
||||
parentId: workspace._id,
|
||||
cookies,
|
||||
});
|
||||
@@ -483,7 +483,7 @@ describe('export', () => {
|
||||
});
|
||||
|
||||
it('export multipart request with file', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const request: Request = {
|
||||
...models.request.init(),
|
||||
_id: 'req_123',
|
||||
|
||||
@@ -276,7 +276,7 @@ describe('importRaw()', () => {
|
||||
data: {
|
||||
from: 'baseEnv',
|
||||
},
|
||||
environmentType: services.environment.EnvironmentType.KVPAIR,
|
||||
environmentType: models.environment.EnvironmentType.KVPAIR,
|
||||
kvPairData: baseEnvironmentPair,
|
||||
});
|
||||
|
||||
@@ -346,7 +346,7 @@ describe('importRaw()', () => {
|
||||
data: {
|
||||
from: 'baseEnv',
|
||||
},
|
||||
environmentType: services.environment.EnvironmentType.KVPAIR,
|
||||
environmentType: models.environment.EnvironmentType.KVPAIR,
|
||||
kvPairData: baseEnvironmentPair,
|
||||
});
|
||||
|
||||
|
||||
@@ -26,12 +26,12 @@ describe('Insomnia v5 Import/Export - Comprehensive Tests', () => {
|
||||
await db.init({ inMemoryOnly: true });
|
||||
|
||||
// Create a basic project and workspace
|
||||
await models.project.create({
|
||||
await services.project.create({
|
||||
_id: 'proj_test',
|
||||
name: 'Test Project',
|
||||
});
|
||||
|
||||
await models.workspace.create({
|
||||
await services.workspace.create({
|
||||
_id: 'wrk_test',
|
||||
name: 'Test Workspace',
|
||||
parentId: 'proj_test',
|
||||
@@ -156,7 +156,7 @@ collection: []
|
||||
|
||||
describe('getInsomniaV5DataExport', () => {
|
||||
it('exports workspace with requests correctly', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_export_test',
|
||||
name: 'Export Test Workspace',
|
||||
parentId: 'proj_test',
|
||||
@@ -166,7 +166,7 @@ collection: []
|
||||
scope: 'collection',
|
||||
});
|
||||
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_export_test',
|
||||
name: 'Export Test Request',
|
||||
parentId: workspace._id,
|
||||
@@ -178,7 +178,7 @@ collection: []
|
||||
});
|
||||
|
||||
// Add base environment (required)
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'env_export_test',
|
||||
name: 'Base Environment',
|
||||
parentId: workspace._id,
|
||||
@@ -202,7 +202,7 @@ collection: []
|
||||
});
|
||||
|
||||
it('handles empty workspace gracefully', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_empty_test',
|
||||
name: 'Empty Workspace',
|
||||
parentId: 'proj_test',
|
||||
@@ -210,7 +210,7 @@ collection: []
|
||||
});
|
||||
|
||||
// must add a base environment
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'env_empty',
|
||||
name: 'Base Env',
|
||||
parentId: workspace._id,
|
||||
@@ -228,21 +228,21 @@ collection: []
|
||||
});
|
||||
|
||||
it('filters requests when requestIds are provided', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_filter_test',
|
||||
name: 'Filter Workspace',
|
||||
parentId: 'proj_test',
|
||||
scope: 'collection',
|
||||
});
|
||||
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'env_filter',
|
||||
name: 'Base Env',
|
||||
parentId: workspace._id,
|
||||
data: {},
|
||||
});
|
||||
|
||||
const req1 = await models.request.create({
|
||||
const req1 = await services.request.create({
|
||||
_id: 'req_filter_1',
|
||||
name: 'Request 1',
|
||||
parentId: workspace._id,
|
||||
@@ -250,7 +250,7 @@ collection: []
|
||||
method: 'GET',
|
||||
});
|
||||
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_filter_2',
|
||||
name: 'Request 2',
|
||||
parentId: workspace._id,
|
||||
@@ -270,21 +270,21 @@ collection: []
|
||||
});
|
||||
|
||||
it('handles design workspace correctly', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_design_test',
|
||||
name: 'Design Workspace',
|
||||
parentId: 'proj_test',
|
||||
scope: 'design',
|
||||
});
|
||||
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'env_design',
|
||||
name: 'Base Env',
|
||||
parentId: workspace._id,
|
||||
data: {},
|
||||
});
|
||||
|
||||
await models.apiSpec.getOrCreateForParentId(workspace._id, {
|
||||
await services.apiSpec.getOrCreateForParentId(workspace._id, {
|
||||
_id: 'spec_design',
|
||||
contents: '{"openapi": "3.0.0"}',
|
||||
contentType: 'json',
|
||||
@@ -301,14 +301,14 @@ collection: []
|
||||
});
|
||||
|
||||
it('handles mock server scope', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_mock',
|
||||
name: 'Mock Workspace',
|
||||
parentId: 'proj_test',
|
||||
scope: 'mock-server',
|
||||
});
|
||||
|
||||
await models.mockServer.create({
|
||||
await services.mockServer.create({
|
||||
_id: 'mock_1',
|
||||
name: 'Test Server',
|
||||
parentId: workspace._id,
|
||||
@@ -326,14 +326,14 @@ collection: []
|
||||
});
|
||||
|
||||
it('handles mcp client scope', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'wrk_mcp',
|
||||
name: 'MCP Workspace',
|
||||
parentId: 'proj_test',
|
||||
scope: 'mcp',
|
||||
});
|
||||
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'env_mcp',
|
||||
name: 'Base Env',
|
||||
parentId: workspace._id,
|
||||
|
||||
@@ -1,8 +1,7 @@
|
||||
import { afterEach, assert, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { type BaseModel, models } from '~/insomnia-data';
|
||||
|
||||
import type { ChangeBufferEvent } from '../..';
|
||||
import { type BaseModel, models, services } from '../..';
|
||||
import { database as db } from '../..';
|
||||
import { repairDatabase } from './repair-database';
|
||||
|
||||
@@ -35,8 +34,8 @@ describe('onChange()', () => {
|
||||
};
|
||||
|
||||
db.onChange(callback);
|
||||
const newDoc = await models.request.create(doc);
|
||||
const updatedDoc = await models.request.update(newDoc, {
|
||||
const newDoc = await services.request.create(doc);
|
||||
const updatedDoc = await services.request.update(newDoc, {
|
||||
name: 'bar',
|
||||
});
|
||||
expect(changesSeen).toEqual([[['insert', newDoc, []]], [['update', updatedDoc, [{ name: 'bar' }]]]]);
|
||||
@@ -58,9 +57,9 @@ describe('bufferChanges()', () => {
|
||||
|
||||
db.onChange(callback);
|
||||
await db.bufferChanges();
|
||||
const newDoc = await models.request.create(doc);
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
const updatedDoc = await models.request.update(newDoc);
|
||||
const updatedDoc = await services.request.update(newDoc);
|
||||
// Assert no change seen before flush
|
||||
expect(changesSeen.length).toBe(0);
|
||||
// Assert changes seen after flush
|
||||
@@ -95,9 +94,9 @@ describe('bufferChanges()', () => {
|
||||
|
||||
db.onChange(callback);
|
||||
await db.bufferChanges();
|
||||
const newDoc = await models.request.create(doc);
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
const updatedDoc = await models.request.update(newDoc);
|
||||
const updatedDoc = await services.request.update(newDoc);
|
||||
// Default flush timeout is 1000ms after starting buffering
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
expect(changesSeen).toEqual([
|
||||
@@ -122,9 +121,9 @@ describe('bufferChanges()', () => {
|
||||
|
||||
db.onChange(callback);
|
||||
await db.bufferChanges(500);
|
||||
const newDoc = await models.request.create(doc);
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
const updatedDoc = await models.request.update(newDoc);
|
||||
const updatedDoc = await services.request.update(newDoc);
|
||||
await new Promise(resolve => setTimeout(resolve, 1000));
|
||||
expect(changesSeen).toEqual([
|
||||
[
|
||||
@@ -150,9 +149,9 @@ describe('bufferChangesIndefinitely()', () => {
|
||||
|
||||
db.onChange(callback);
|
||||
await db.bufferChangesIndefinitely();
|
||||
const newDoc = await models.request.create(doc);
|
||||
const newDoc = await services.request.create(doc);
|
||||
// @ts-expect-error -- TSCONVERSION appears to be genuine
|
||||
const updatedDoc = await models.request.update(newDoc);
|
||||
const updatedDoc = await services.request.update(newDoc);
|
||||
// Default flush timeout is 1000ms after starting buffering
|
||||
await new Promise(resolve => setTimeout(resolve, 1500));
|
||||
// Assert no change seen before flush
|
||||
@@ -175,7 +174,7 @@ describe('requestCreate()', () => {
|
||||
name: 'My Request',
|
||||
parentId: 'wrk_123',
|
||||
};
|
||||
const r = await models.request.create(patch);
|
||||
const r = await services.request.create(patch);
|
||||
expect(Object.keys(r).length).toBe(24);
|
||||
expect(r._id).toMatch(/^req_[a-zA-Z0-9]{32}$/);
|
||||
expect(r.created).toBeGreaterThanOrEqual(now);
|
||||
@@ -194,7 +193,7 @@ describe('requestCreate()', () => {
|
||||
|
||||
it('throws when missing parentID', () => {
|
||||
const fn = () =>
|
||||
models.request.create({
|
||||
services.request.create({
|
||||
name: 'My Request',
|
||||
});
|
||||
|
||||
@@ -209,13 +208,13 @@ describe('_repairDatabase()', async () => {
|
||||
|
||||
it('fixes duplicate environments', async () => {
|
||||
// Create Workspace with no children
|
||||
const project = await models.project.create();
|
||||
const workspace = await models.workspace.create({
|
||||
const project = await services.project.create();
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'w1',
|
||||
parentId: project._id,
|
||||
});
|
||||
// Create one set of sub environments
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'b1',
|
||||
parentId: 'w1',
|
||||
data: {
|
||||
@@ -223,14 +222,14 @@ describe('_repairDatabase()', async () => {
|
||||
b1: true,
|
||||
},
|
||||
});
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'b1_sub1',
|
||||
parentId: 'b1',
|
||||
data: {
|
||||
foo: '1',
|
||||
},
|
||||
});
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'b1_sub2',
|
||||
parentId: 'b1',
|
||||
data: {
|
||||
@@ -238,7 +237,7 @@ describe('_repairDatabase()', async () => {
|
||||
},
|
||||
});
|
||||
// Create second set of sub environments
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'b2',
|
||||
parentId: 'w1',
|
||||
data: {
|
||||
@@ -246,14 +245,14 @@ describe('_repairDatabase()', async () => {
|
||||
b2: true,
|
||||
},
|
||||
});
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'b2_sub1',
|
||||
parentId: 'b2',
|
||||
data: {
|
||||
foo: '3',
|
||||
},
|
||||
});
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'b2_sub2',
|
||||
parentId: 'b2',
|
||||
data: {
|
||||
@@ -379,14 +378,14 @@ describe('_repairDatabase()', async () => {
|
||||
|
||||
it('fixes duplicate cookie jars', async () => {
|
||||
// Create Workspace with no children
|
||||
const project = await models.project.create();
|
||||
const workspace = await models.workspace.create({
|
||||
const project = await services.project.create();
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'w1',
|
||||
parentId: project._id,
|
||||
});
|
||||
expect((await db.getWithDescendants(workspace)).length).toBe(1);
|
||||
// Create one set of sub environments
|
||||
await models.cookieJar.create({
|
||||
await services.cookieJar.create({
|
||||
_id: 'j1',
|
||||
parentId: 'w1',
|
||||
cookies: [
|
||||
@@ -404,7 +403,7 @@ describe('_repairDatabase()', async () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
await models.cookieJar.create({
|
||||
await services.cookieJar.create({
|
||||
_id: 'j2',
|
||||
parentId: 'w1',
|
||||
cookies: [
|
||||
@@ -508,52 +507,52 @@ describe('_repairDatabase()', async () => {
|
||||
|
||||
it('fixes the filename on an apiSpec', async () => {
|
||||
// Create Workspace with apiSpec child (migration in workspace will automatically create this as it is not mocked)
|
||||
const w1 = await models.workspace.create({
|
||||
const w1 = await services.workspace.create({
|
||||
_id: 'w1',
|
||||
name: 'Workspace 1',
|
||||
});
|
||||
const w2 = await models.workspace.create({
|
||||
const w2 = await services.workspace.create({
|
||||
_id: 'w2',
|
||||
name: 'Workspace 2',
|
||||
});
|
||||
const w3 = await models.workspace.create({
|
||||
const w3 = await services.workspace.create({
|
||||
_id: 'w3',
|
||||
name: 'Workspace 3',
|
||||
});
|
||||
await models.apiSpec.updateOrCreateForParentId(w1._id, {
|
||||
await services.apiSpec.updateOrCreateForParentId(w1._id, {
|
||||
fileName: '',
|
||||
});
|
||||
await models.apiSpec.updateOrCreateForParentId(w2._id, {
|
||||
await services.apiSpec.updateOrCreateForParentId(w2._id, {
|
||||
fileName: models.apiSpec.init().fileName,
|
||||
});
|
||||
await models.apiSpec.updateOrCreateForParentId(w3._id, {
|
||||
await services.apiSpec.updateOrCreateForParentId(w3._id, {
|
||||
fileName: 'Unique name',
|
||||
});
|
||||
// Make sure we have everything
|
||||
expect((await models.apiSpec.getByParentId(w1._id))?.fileName).toBe('');
|
||||
expect((await models.apiSpec.getByParentId(w2._id))?.fileName).toBe('New Document');
|
||||
expect((await models.apiSpec.getByParentId(w3._id))?.fileName).toBe('Unique name');
|
||||
expect((await services.apiSpec.getByParentId(w1._id))?.fileName).toBe('');
|
||||
expect((await services.apiSpec.getByParentId(w2._id))?.fileName).toBe('New Document');
|
||||
expect((await services.apiSpec.getByParentId(w3._id))?.fileName).toBe('Unique name');
|
||||
// Run the fix algorithm
|
||||
await repairDatabase();
|
||||
// Make sure things get adjusted
|
||||
expect((await models.apiSpec.getByParentId(w1._id))?.fileName).toBe('Workspace 1'); // Should fix
|
||||
expect((await models.apiSpec.getByParentId(w2._id))?.fileName).toBe('Workspace 2'); // Should fix
|
||||
expect((await models.apiSpec.getByParentId(w3._id))?.fileName).toBe('Unique name'); // should not fix
|
||||
expect((await services.apiSpec.getByParentId(w1._id))?.fileName).toBe('Workspace 1'); // Should fix
|
||||
expect((await services.apiSpec.getByParentId(w2._id))?.fileName).toBe('Workspace 2'); // Should fix
|
||||
expect((await services.apiSpec.getByParentId(w3._id))?.fileName).toBe('Unique name'); // should not fix
|
||||
});
|
||||
|
||||
it('fixes old git uris', async () => {
|
||||
const oldRepoWithSuffix = await models.gitRepository.create({
|
||||
const oldRepoWithSuffix = await services.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
uriNeedsMigration: true,
|
||||
});
|
||||
const oldRepoWithoutSuffix = await models.gitRepository.create({
|
||||
const oldRepoWithoutSuffix = await services.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar',
|
||||
uriNeedsMigration: true,
|
||||
});
|
||||
const newRepoWithSuffix = await models.gitRepository.create({
|
||||
const newRepoWithSuffix = await services.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar.git',
|
||||
});
|
||||
const newRepoWithoutSuffix = await models.gitRepository.create({
|
||||
const newRepoWithoutSuffix = await services.gitRepository.create({
|
||||
uri: 'https://github.com/foo/bar',
|
||||
});
|
||||
await repairDatabase();
|
||||
@@ -590,7 +589,7 @@ describe('duplicate()', () => {
|
||||
it('should overwrite appropriate fields on the parent when duplicating', async () => {
|
||||
const date = 1_478_795_580_200;
|
||||
Date.now = vi.fn().mockReturnValue(date);
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
name: 'Test Workspace',
|
||||
});
|
||||
const newDescription = 'test';
|
||||
@@ -611,7 +610,7 @@ describe('duplicate()', () => {
|
||||
});
|
||||
|
||||
it('should should not call migrate when duplicating', async () => {
|
||||
const workspace = await models.workspace.create({
|
||||
const workspace = await services.workspace.create({
|
||||
name: 'Test Workspace',
|
||||
});
|
||||
const spy = vi.spyOn(models.workspace, 'migrate');
|
||||
@@ -620,14 +619,14 @@ describe('duplicate()', () => {
|
||||
});
|
||||
|
||||
it('should rewrite chained request references when duplicating a folder', async () => {
|
||||
const workspace = await models.workspace.create({ name: 'Workspace' });
|
||||
const folder = await models.requestGroup.create({ parentId: workspace._id, name: 'Folder' });
|
||||
const req1 = await models.request.create({
|
||||
const workspace = await services.workspace.create({ name: 'Workspace' });
|
||||
const folder = await services.requestGroup.create({ parentId: workspace._id, name: 'Folder' });
|
||||
const req1 = await services.request.create({
|
||||
parentId: folder._id,
|
||||
name: 'Request 1',
|
||||
url: 'https://example.com/first',
|
||||
});
|
||||
const req2 = await models.request.create({
|
||||
const req2 = await services.request.create({
|
||||
parentId: folder._id,
|
||||
name: 'Request 2',
|
||||
url: `https://example.com/{% response 'body', '${req1._id}', 'b64::JC5pZA==::46b', 'never', 60 %}`,
|
||||
@@ -672,23 +671,23 @@ describe('docCreate()', () => {
|
||||
|
||||
describe('withAncestors()', () => {
|
||||
it('should return itself and all parents but exclude siblings', async () => {
|
||||
const spc = await models.project.create();
|
||||
const wrk = await models.workspace.create({
|
||||
const spc = await services.project.create();
|
||||
const wrk = await services.workspace.create({
|
||||
parentId: spc._id,
|
||||
});
|
||||
const wrkReq = await models.request.create({
|
||||
const wrkReq = await services.request.create({
|
||||
parentId: wrk._id,
|
||||
});
|
||||
const wrkGrpcReq = await models.grpcRequest.create({
|
||||
const wrkGrpcReq = await services.grpcRequest.create({
|
||||
parentId: wrk._id,
|
||||
});
|
||||
const grp = await models.requestGroup.create({
|
||||
const grp = await services.requestGroup.create({
|
||||
parentId: wrk._id,
|
||||
});
|
||||
const grpReq = await models.request.create({
|
||||
const grpReq = await services.request.create({
|
||||
parentId: grp._id,
|
||||
});
|
||||
const grpGrpcReq = await models.grpcRequest.create({
|
||||
const grpGrpcReq = await services.grpcRequest.create({
|
||||
parentId: grp._id,
|
||||
});
|
||||
// Workspace child searching for ancestors
|
||||
@@ -712,12 +711,12 @@ describe('withAncestors()', () => {
|
||||
|
||||
describe('getWithDescendants()', () => {
|
||||
it('should return specified model and all children', async () => {
|
||||
const project = await models.project.create();
|
||||
const workspace = await models.workspace.create({
|
||||
const project = await services.project.create();
|
||||
const workspace = await services.workspace.create({
|
||||
_id: 'w1',
|
||||
parentId: project._id,
|
||||
});
|
||||
const cookieJar1 = await models.cookieJar.create({
|
||||
const cookieJar1 = await services.cookieJar.create({
|
||||
_id: 'j1',
|
||||
parentId: workspace._id,
|
||||
cookies: [
|
||||
@@ -735,7 +734,7 @@ describe('getWithDescendants()', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
const cookieJar2 = await models.cookieJar.create({
|
||||
const cookieJar2 = await services.cookieJar.create({
|
||||
_id: 'j2',
|
||||
parentId: workspace._id,
|
||||
cookies: [
|
||||
@@ -753,41 +752,41 @@ describe('getWithDescendants()', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
const folder1 = await models.requestGroup.create({
|
||||
const folder1 = await services.requestGroup.create({
|
||||
_id: 'grp1',
|
||||
parentId: workspace._id,
|
||||
});
|
||||
const folder2 = await models.requestGroup.create({
|
||||
const folder2 = await services.requestGroup.create({
|
||||
_id: 'grp2',
|
||||
parentId: folder1._id,
|
||||
});
|
||||
const request1 = await models.request.create({
|
||||
const request1 = await services.request.create({
|
||||
_id: 'req1',
|
||||
parentId: workspace._id,
|
||||
});
|
||||
const request2 = await models.request.create({
|
||||
const request2 = await services.request.create({
|
||||
_id: 'req2',
|
||||
parentId: folder1._id,
|
||||
});
|
||||
const grpcRequest1 = await models.grpcRequest.create({
|
||||
const grpcRequest1 = await services.grpcRequest.create({
|
||||
_id: 'grpc1',
|
||||
parentId: workspace._id,
|
||||
});
|
||||
const websocketRequest1 = await models.webSocketRequest.create({
|
||||
const websocketRequest1 = await services.webSocketRequest.create({
|
||||
_id: 'ws1',
|
||||
parentId: workspace._id,
|
||||
});
|
||||
const socketIORequest1 = await models.socketIORequest.create({
|
||||
const socketIORequest1 = await services.socketIORequest.create({
|
||||
_id: 'socket1',
|
||||
parentId: workspace._id,
|
||||
});
|
||||
|
||||
const environment1 = await models.environment.create({
|
||||
const environment1 = await services.environment.create({
|
||||
_id: 'env1',
|
||||
parentId: workspace._id,
|
||||
});
|
||||
|
||||
const environment2 = await models.environment.create({
|
||||
const environment2 = await services.environment.create({
|
||||
_id: 'env2',
|
||||
parentId: environment1._id,
|
||||
});
|
||||
|
||||
@@ -1,6 +1,6 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { replaceIdsInFields } from '../replace-ids-in-fields';
|
||||
import { replaceIdsInFields } from './replace-ids-in-fields';
|
||||
|
||||
describe('replaceIdsInFields', () => {
|
||||
const idMapping = new Map([
|
||||
@@ -1,6 +1,6 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { models } from '~/insomnia-data';
|
||||
import { services } from '~/insomnia-data';
|
||||
|
||||
import {
|
||||
clearActiveBackend,
|
||||
@@ -12,7 +12,7 @@ import {
|
||||
} from '../llm-config-service';
|
||||
|
||||
vi.mock('~/insomnia-data', () => ({
|
||||
models: {
|
||||
services: {
|
||||
pluginData: {
|
||||
getByKey: vi.fn(),
|
||||
upsertByKey: vi.fn(),
|
||||
@@ -46,7 +46,7 @@ describe('llm-config-service', () => {
|
||||
|
||||
describe('getBackendConfig()', () => {
|
||||
it('should retrieve url field from storage', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([
|
||||
mockPluginData('url.model', 'gpt-4'),
|
||||
mockPluginData('url.url', 'https://api.example.com/v1'),
|
||||
]);
|
||||
@@ -61,7 +61,7 @@ describe('llm-config-service', () => {
|
||||
});
|
||||
|
||||
it('should retrieve baseURL field from storage', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([
|
||||
mockPluginData('url.model', 'claude-3'),
|
||||
mockPluginData('url.baseURL', 'https://custom-llm.com'),
|
||||
]);
|
||||
@@ -76,7 +76,7 @@ describe('llm-config-service', () => {
|
||||
});
|
||||
|
||||
it('should handle both url and baseURL fields', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([
|
||||
mockPluginData('url.url', 'https://api.example.com/v1'),
|
||||
mockPluginData('url.baseURL', 'https://base.example.com'),
|
||||
mockPluginData('url.model', 'test-model'),
|
||||
@@ -90,7 +90,7 @@ describe('llm-config-service', () => {
|
||||
});
|
||||
|
||||
it('should return empty config for unconfigured backend', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([]);
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([]);
|
||||
|
||||
const config = await getBackendConfig('url');
|
||||
|
||||
@@ -107,12 +107,12 @@ describe('llm-config-service', () => {
|
||||
model: 'gpt-4',
|
||||
});
|
||||
|
||||
expect(models.pluginData.upsertByKey).toHaveBeenCalledWith(
|
||||
expect(services.pluginData.upsertByKey).toHaveBeenCalledWith(
|
||||
'insomnia-llm',
|
||||
'url.url',
|
||||
'https://api.example.com/v1',
|
||||
);
|
||||
expect(models.pluginData.upsertByKey).toHaveBeenCalledWith('insomnia-llm', 'url.model', 'gpt-4');
|
||||
expect(services.pluginData.upsertByKey).toHaveBeenCalledWith('insomnia-llm', 'url.model', 'gpt-4');
|
||||
});
|
||||
|
||||
it('should save baseURL field to storage', async () => {
|
||||
@@ -121,7 +121,7 @@ describe('llm-config-service', () => {
|
||||
model: 'claude-3',
|
||||
});
|
||||
|
||||
expect(models.pluginData.upsertByKey).toHaveBeenCalledWith(
|
||||
expect(services.pluginData.upsertByKey).toHaveBeenCalledWith(
|
||||
'insomnia-llm',
|
||||
'url.baseURL',
|
||||
'https://custom-llm.com',
|
||||
@@ -133,8 +133,8 @@ describe('llm-config-service', () => {
|
||||
url: 'https://new-url.com/v1',
|
||||
});
|
||||
|
||||
expect(models.pluginData.upsertByKey).toHaveBeenCalledWith('insomnia-llm', 'url.url', 'https://new-url.com/v1');
|
||||
expect(models.pluginData.upsertByKey).toHaveBeenCalledTimes(1);
|
||||
expect(services.pluginData.upsertByKey).toHaveBeenCalledWith('insomnia-llm', 'url.url', 'https://new-url.com/v1');
|
||||
expect(services.pluginData.upsertByKey).toHaveBeenCalledTimes(1);
|
||||
});
|
||||
|
||||
it('should not save backend field', async () => {
|
||||
@@ -143,7 +143,7 @@ describe('llm-config-service', () => {
|
||||
url: 'https://api.example.com/v1',
|
||||
});
|
||||
|
||||
const calls = vi.mocked(models.pluginData.upsertByKey).mock.calls;
|
||||
const calls = vi.mocked(services.pluginData.upsertByKey).mock.calls;
|
||||
const backendFieldCall = calls.find(call => call[1] === 'url.backend');
|
||||
expect(backendFieldCall).toBeUndefined();
|
||||
});
|
||||
@@ -151,7 +151,7 @@ describe('llm-config-service', () => {
|
||||
|
||||
describe('getAllConfigurations()', () => {
|
||||
it('should include url backend in configurations', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([
|
||||
mockPluginData('url.model', 'gpt-4'),
|
||||
mockPluginData('url.url', 'https://api.example.com/v1'),
|
||||
mockPluginData('gguf.model', 'llama-3'),
|
||||
@@ -166,7 +166,7 @@ describe('llm-config-service', () => {
|
||||
});
|
||||
|
||||
it('should filter out unconfigured backends', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([
|
||||
mockPluginData('claude.model', 'claude-3-opus'),
|
||||
mockPluginData('claude.apiKey', 'sk-ant-123'),
|
||||
]);
|
||||
@@ -179,7 +179,7 @@ describe('llm-config-service', () => {
|
||||
});
|
||||
|
||||
it('should include backend with only url field set', async () => {
|
||||
vi.mocked(models.pluginData.all).mockResolvedValue([mockPluginData('url.url', 'https://api.example.com/v1')]);
|
||||
vi.mocked(services.pluginData.all).mockResolvedValue([mockPluginData('url.url', 'https://api.example.com/v1')]);
|
||||
|
||||
const configs = await getAllConfigurations();
|
||||
|
||||
@@ -193,11 +193,11 @@ describe('llm-config-service', () => {
|
||||
it('should set url as active backend', async () => {
|
||||
await setActiveBackend('url');
|
||||
|
||||
expect(models.pluginData.upsertByKey).toHaveBeenCalledWith('insomnia-llm', 'model.active', 'url');
|
||||
expect(services.pluginData.upsertByKey).toHaveBeenCalledWith('insomnia-llm', 'model.active', 'url');
|
||||
});
|
||||
|
||||
it('should get url as active backend', async () => {
|
||||
vi.mocked(models.pluginData.getByKey).mockResolvedValue({ value: 'url' } as any);
|
||||
vi.mocked(services.pluginData.getByKey).mockResolvedValue({ value: 'url' } as any);
|
||||
|
||||
const active = await getActiveBackend();
|
||||
|
||||
@@ -205,7 +205,7 @@ describe('llm-config-service', () => {
|
||||
});
|
||||
|
||||
it('should return null when no active backend', async () => {
|
||||
vi.mocked(models.pluginData.getByKey).mockResolvedValue(undefined as any);
|
||||
vi.mocked(services.pluginData.getByKey).mockResolvedValue(undefined as any);
|
||||
|
||||
const active = await getActiveBackend();
|
||||
|
||||
@@ -215,7 +215,7 @@ describe('llm-config-service', () => {
|
||||
it('should clear active backend', async () => {
|
||||
await clearActiveBackend();
|
||||
|
||||
expect(models.pluginData.removeByKey).toHaveBeenCalledWith('insomnia-llm', 'model.active');
|
||||
expect(services.pluginData.removeByKey).toHaveBeenCalledWith('insomnia-llm', 'model.active');
|
||||
});
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,13 +1,8 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import { models } from '~/insomnia-data';
|
||||
|
||||
import { generateId } from '../../../common/misc';
|
||||
import { isGrpcRequest, isGrpcRequestId } from '../../grpc-request';
|
||||
import * as models from '../../index';
|
||||
import { isProtoDirectory } from '../../proto-directory';
|
||||
import { isProtoFile } from '../../proto-file';
|
||||
import { isRequest } from '../../request';
|
||||
import { isRequestGroup } from '../../request-group';
|
||||
import { isDesign, isWorkspace, WorkspaceScopeKeys } from '../../workspace';
|
||||
|
||||
const allTypes = models.types();
|
||||
const allPrefixes = models.all().map(model => model.prefix);
|
||||
@@ -18,7 +13,7 @@ describe('isGrpcRequest', () => {
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
expect(
|
||||
isGrpcRequest({
|
||||
models.grpcRequest.isGrpcRequest({
|
||||
type,
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -26,7 +21,7 @@ describe('isGrpcRequest', () => {
|
||||
|
||||
it.each(unsupported)('should return false: "%s"', type => {
|
||||
expect(
|
||||
isGrpcRequest({
|
||||
models.grpcRequest.isGrpcRequest({
|
||||
type,
|
||||
}),
|
||||
).toBe(false);
|
||||
@@ -38,11 +33,11 @@ describe('isGrpcRequestId', () => {
|
||||
const unsupported = allPrefixes.filter(x => !supported.includes(x));
|
||||
|
||||
it.each(supported)('should return true if id is prefixed by "%s_"', prefix => {
|
||||
expect(isGrpcRequestId(generateId(prefix))).toBe(true);
|
||||
expect(models.grpcRequest.isGrpcRequestId(generateId(prefix))).toBe(true);
|
||||
});
|
||||
|
||||
it.each(unsupported)('should return false if id is prefixed by "%s_"', prefix => {
|
||||
expect(isGrpcRequestId(generateId(prefix))).toBe(false);
|
||||
expect(models.grpcRequest.isGrpcRequestId(generateId(prefix))).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -52,7 +47,7 @@ describe('isRequest', () => {
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
expect(
|
||||
isRequest({
|
||||
models.request.isRequest({
|
||||
type,
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -60,7 +55,7 @@ describe('isRequest', () => {
|
||||
|
||||
it.each(unsupported)('should return false: "%s"', type => {
|
||||
expect(
|
||||
isRequest({
|
||||
models.request.isRequest({
|
||||
type,
|
||||
}),
|
||||
).toBe(false);
|
||||
@@ -73,7 +68,7 @@ describe('isRequestGroup', () => {
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
expect(
|
||||
isRequestGroup({
|
||||
models.requestGroup.isRequestGroup({
|
||||
type,
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -81,7 +76,7 @@ describe('isRequestGroup', () => {
|
||||
|
||||
it.each(unsupported)('should return false: "%s"', type => {
|
||||
expect(
|
||||
isRequestGroup({
|
||||
models.requestGroup.isRequestGroup({
|
||||
type,
|
||||
}),
|
||||
).toBe(false);
|
||||
@@ -94,7 +89,7 @@ describe('isProtoFile', () => {
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
expect(
|
||||
isProtoFile({
|
||||
models.protoFile.isProtoFile({
|
||||
type,
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -102,7 +97,7 @@ describe('isProtoFile', () => {
|
||||
|
||||
it.each(unsupported)('should return false: "%s"', type => {
|
||||
expect(
|
||||
isProtoFile({
|
||||
models.protoFile.isProtoFile({
|
||||
type,
|
||||
}),
|
||||
).toBe(false);
|
||||
@@ -115,7 +110,7 @@ describe('isProtoDirectory', () => {
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
expect(
|
||||
isProtoDirectory({
|
||||
models.protoDirectory.isProtoDirectory({
|
||||
type,
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -123,7 +118,7 @@ describe('isProtoDirectory', () => {
|
||||
|
||||
it.each(unsupported)('should return false: "%s"', type => {
|
||||
expect(
|
||||
isProtoDirectory({
|
||||
models.protoDirectory.isProtoDirectory({
|
||||
type,
|
||||
}),
|
||||
).toBe(false);
|
||||
@@ -136,7 +131,7 @@ describe('isWorkspace', () => {
|
||||
|
||||
it.each(supported)('should return true: "%s"', type => {
|
||||
expect(
|
||||
isWorkspace({
|
||||
models.workspace.isWorkspace({
|
||||
type,
|
||||
}),
|
||||
).toBe(true);
|
||||
@@ -144,7 +139,7 @@ describe('isWorkspace', () => {
|
||||
|
||||
it.each(unsupported)('should return false: "%s"', type => {
|
||||
expect(
|
||||
isWorkspace({
|
||||
models.workspace.isWorkspace({
|
||||
type,
|
||||
}),
|
||||
).toBe(false);
|
||||
@@ -154,13 +149,13 @@ describe('isWorkspace', () => {
|
||||
describe('isDesign', () => {
|
||||
it('should be true', () => {
|
||||
const w = models.workspace.init();
|
||||
w.scope = WorkspaceScopeKeys.design;
|
||||
expect(isDesign(w)).toBe(true);
|
||||
w.scope = models.workspace.WorkspaceScopeKeys.design;
|
||||
expect(models.workspace.isDesign(w)).toBe(true);
|
||||
});
|
||||
|
||||
it('should be false', () => {
|
||||
const w = models.workspace.init();
|
||||
w.scope = WorkspaceScopeKeys.collection;
|
||||
expect(isDesign(w)).toBe(false);
|
||||
w.scope = models.workspace.WorkspaceScopeKeys.collection;
|
||||
expect(models.workspace.isDesign(w)).toBe(false);
|
||||
});
|
||||
});
|
||||
|
||||
@@ -1,11 +1,12 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import * as models from '../../index';
|
||||
import { models, services } from '~/insomnia-data';
|
||||
|
||||
import { queryAllWorkspaceUrls } from '../query-all-workspace-urls';
|
||||
|
||||
describe('queryAllWorkspaceUrls', () => {
|
||||
it('should return empty array when no requests exist', async () => {
|
||||
const w = await models.workspace.create({
|
||||
const w = await services.workspace.create({
|
||||
name: 'Workspace',
|
||||
});
|
||||
await expect(queryAllWorkspaceUrls(w._id, models.request.type)).resolves.toHaveLength(0);
|
||||
@@ -13,63 +14,63 @@ describe('queryAllWorkspaceUrls', () => {
|
||||
});
|
||||
|
||||
it('should return urls and exclude that of the selected request', async () => {
|
||||
const w = await models.workspace.create({
|
||||
const w = await services.workspace.create({
|
||||
name: 'Workspace',
|
||||
});
|
||||
const r1 = await models.request.create({
|
||||
const r1 = await services.request.create({
|
||||
name: 'Request 1',
|
||||
parentId: w._id,
|
||||
url: 'r1.url',
|
||||
});
|
||||
const gr1 = await models.grpcRequest.create({
|
||||
const gr1 = await services.grpcRequest.create({
|
||||
name: 'Grpc Request 1',
|
||||
parentId: w._id,
|
||||
url: 'gr1.url',
|
||||
});
|
||||
const gr2 = await models.grpcRequest.create({
|
||||
const gr2 = await services.grpcRequest.create({
|
||||
name: 'Grpc Request 2',
|
||||
parentId: w._id,
|
||||
url: 'gr2.url',
|
||||
});
|
||||
const f2 = await models.requestGroup.create({
|
||||
const f2 = await services.requestGroup.create({
|
||||
name: 'Folder 2',
|
||||
parentId: w._id,
|
||||
});
|
||||
const r2 = await models.request.create({
|
||||
const r2 = await services.request.create({
|
||||
name: 'Request 2',
|
||||
parentId: f2._id,
|
||||
url: 'r2.url',
|
||||
});
|
||||
// Should ignore all of the following
|
||||
await models.grpcRequest.create({
|
||||
await services.grpcRequest.create({
|
||||
name: 'Duplicate grpc url',
|
||||
parentId: w._id,
|
||||
url: gr2.url,
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
name: 'Duplicate url',
|
||||
parentId: f2._id,
|
||||
url: r2.url,
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
name: 'Undefined url',
|
||||
parentId: f2._id,
|
||||
url: undefined,
|
||||
});
|
||||
await models.grpcRequest.create({
|
||||
await services.grpcRequest.create({
|
||||
name: 'Undefined url',
|
||||
parentId: w._id,
|
||||
url: undefined,
|
||||
});
|
||||
const w2 = await models.workspace.create({
|
||||
const w2 = await services.workspace.create({
|
||||
name: 'Workspace 2',
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
name: 'Different workspace',
|
||||
parentId: w2._id,
|
||||
url: 'diff.url',
|
||||
});
|
||||
await models.grpcRequest.create({
|
||||
await services.grpcRequest.create({
|
||||
name: 'Different workspace',
|
||||
parentId: w2._id,
|
||||
url: 'diff.url',
|
||||
|
||||
@@ -4,6 +4,8 @@ import nodePath from 'node:path';
|
||||
import { CurlHttpVersion, CurlNetrc } from '@getinsomnia/node-libcurl';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { models, services } from '~/insomnia-data';
|
||||
|
||||
import { CONTENT_TYPE_FILE, CONTENT_TYPE_FORM_DATA, CONTENT_TYPE_FORM_URLENCODED } from '../../common/constants';
|
||||
import { filterHeaders } from '../../common/misc';
|
||||
import { getRenderedRequestAndContext } from '../../common/render';
|
||||
@@ -11,7 +13,6 @@ import { HttpVersions } from '../../common/settings';
|
||||
import { _parseHeaders, getHttpVersion } from '../../main/network/libcurl-promise';
|
||||
import { DEFAULT_BOUNDARY } from '../../main/network/multipart';
|
||||
import { _getAwsAuthHeaders } from '../../main/network/parse-header-strings';
|
||||
import * as models from '../../models';
|
||||
import { getBodyBuffer } from '../../models/helpers/response-operations';
|
||||
import * as networkUtils from '../network';
|
||||
import { getSetCookiesFromResponseHeaders } from '../network';
|
||||
@@ -21,11 +22,11 @@ const getRenderedRequest = async (args: Parameters<typeof getRenderedRequestAndC
|
||||
|
||||
describe('sendCurlAndWriteTimeline()', () => {
|
||||
beforeEach(async () => {
|
||||
await models.project.all();
|
||||
await services.project.all();
|
||||
});
|
||||
|
||||
it('sends a generic request', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const cookies = [
|
||||
{
|
||||
@@ -49,8 +50,8 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
lastAccessed: new Date('2096-10-05T04:40:49.505Z'),
|
||||
},
|
||||
];
|
||||
const cookieJar = await models.cookieJar.getOrCreateForParentId(workspace._id);
|
||||
await models.cookieJar.update(cookieJar, {
|
||||
const cookieJar = await services.cookieJar.getOrCreateForParentId(workspace._id);
|
||||
await services.cookieJar.update(cookieJar, {
|
||||
parentId: workspace._id,
|
||||
cookies,
|
||||
});
|
||||
@@ -138,7 +139,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('sends a urlencoded', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const request = Object.assign(models.request.init(), {
|
||||
_id: 'req_123',
|
||||
@@ -211,7 +212,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('skips sending and storing cookies with setting', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const cookies = [
|
||||
{
|
||||
@@ -235,7 +236,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
lastAccessed: new Date('2096-10-05T04:40:49.505Z'),
|
||||
},
|
||||
];
|
||||
await models.cookieJar.create({
|
||||
await services.cookieJar.create({
|
||||
parentId: workspace._id,
|
||||
cookies,
|
||||
});
|
||||
@@ -315,10 +316,10 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('sends a file', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
let settings = await services.settings.getOrCreate();
|
||||
settings = await models.settings.update(settings, { dataFolders: [nodePath.resolve(__dirname)] });
|
||||
await models.cookieJar.create({
|
||||
settings = await services.settings.update(settings, { dataFolders: [nodePath.resolve(__dirname)] });
|
||||
await services.cookieJar.create({
|
||||
parentId: workspace._id,
|
||||
});
|
||||
const fileName = nodePath.resolve(nodePath.join(__dirname, './testfile.txt'));
|
||||
@@ -383,9 +384,9 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('sends multipart form data', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
await models.cookieJar.create({
|
||||
await services.cookieJar.create({
|
||||
parentId: workspace._id,
|
||||
});
|
||||
const fileName = nodePath.resolve(nodePath.join(__dirname, './testfile.txt'));
|
||||
@@ -479,7 +480,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('uses unix socket', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const request = Object.assign(models.request.init(), {
|
||||
_id: 'req_123',
|
||||
@@ -523,7 +524,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('uses works with HEAD', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const request = Object.assign(models.request.init(), {
|
||||
_id: 'req_123',
|
||||
@@ -566,7 +567,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('uses works with "unix" host', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const request = Object.assign(models.request.init(), {
|
||||
_id: 'req_123',
|
||||
@@ -609,7 +610,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('uses netrc', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const request = Object.assign(models.request.init(), {
|
||||
_id: 'req_123',
|
||||
@@ -658,7 +659,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
// skipped this test, due to SSL_VERIFYHOST being disabled for MacOS on libcurl-promise.ts
|
||||
return;
|
||||
}
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const cookies = [
|
||||
{
|
||||
@@ -682,8 +683,8 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
lastAccessed: new Date('2096-10-05T04:40:49.505Z'),
|
||||
},
|
||||
];
|
||||
const cookieJar = await models.cookieJar.getOrCreateForParentId(workspace._id);
|
||||
await models.cookieJar.update(cookieJar, {
|
||||
const cookieJar = await services.cookieJar.getOrCreateForParentId(workspace._id);
|
||||
await services.cookieJar.update(cookieJar, {
|
||||
parentId: workspace._id,
|
||||
cookies,
|
||||
});
|
||||
@@ -773,7 +774,7 @@ describe('sendCurlAndWriteTimeline()', () => {
|
||||
});
|
||||
|
||||
it('sets HTTP version', async () => {
|
||||
const workspace = await models.workspace.create();
|
||||
const workspace = await services.workspace.create();
|
||||
const settings = await services.settings.getOrCreate();
|
||||
const request = Object.assign(models.request.init(), {
|
||||
_id: 'req_123',
|
||||
|
||||
@@ -4,7 +4,8 @@ import path from 'node:path';
|
||||
|
||||
import { afterEach, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import * as models from '../../../models';
|
||||
import { services } from '~/insomnia-data';
|
||||
|
||||
import { writeProtoFile } from '../write-proto-file';
|
||||
|
||||
describe('writeProtoFile', () => {
|
||||
@@ -43,8 +44,8 @@ describe('writeProtoFile', () => {
|
||||
describe('individual files', () => {
|
||||
it('can write individual file', async () => {
|
||||
// Arrange
|
||||
const w = await models.workspace.create();
|
||||
const pf = await models.protoFile.create({
|
||||
const w = await services.workspace.create();
|
||||
const pf = await services.protoFile.create({
|
||||
parentId: w._id,
|
||||
protoText: 'text',
|
||||
});
|
||||
@@ -66,8 +67,8 @@ describe('writeProtoFile', () => {
|
||||
|
||||
it('doesnt write individual file if it already exists', async () => {
|
||||
// Arrange
|
||||
const w = await models.workspace.create();
|
||||
const pf = await models.protoFile.create({
|
||||
const w = await services.workspace.create();
|
||||
const pf = await services.protoFile.create({
|
||||
parentId: w._id,
|
||||
protoText: 'text',
|
||||
});
|
||||
@@ -91,12 +92,12 @@ describe('writeProtoFile', () => {
|
||||
describe('nested files', () => {
|
||||
it('can write file contained in a single folder', async () => {
|
||||
// Arrange
|
||||
const w = await models.workspace.create();
|
||||
const pd = await models.protoDirectory.create({
|
||||
const w = await services.workspace.create();
|
||||
const pd = await services.protoDirectory.create({
|
||||
parentId: w._id,
|
||||
name: 'dirName',
|
||||
});
|
||||
const pf = await models.protoFile.create({
|
||||
const pf = await services.protoFile.create({
|
||||
parentId: pd._id,
|
||||
name: 'hello.proto',
|
||||
protoText: 'text',
|
||||
@@ -119,21 +120,21 @@ describe('writeProtoFile', () => {
|
||||
|
||||
it('can write files contained in nested folders', async () => {
|
||||
// Arrange
|
||||
const w = await models.workspace.create();
|
||||
const pdRoot = await models.protoDirectory.create({
|
||||
const w = await services.workspace.create();
|
||||
const pdRoot = await services.protoDirectory.create({
|
||||
parentId: w._id,
|
||||
name: 'rootDir',
|
||||
});
|
||||
const pdNested = await models.protoDirectory.create({
|
||||
const pdNested = await services.protoDirectory.create({
|
||||
parentId: pdRoot._id,
|
||||
name: 'nestedDir',
|
||||
});
|
||||
const pfRoot = await models.protoFile.create({
|
||||
const pfRoot = await services.protoFile.create({
|
||||
parentId: pdRoot._id,
|
||||
name: 'root.proto',
|
||||
protoText: 'root',
|
||||
});
|
||||
const pfNested = await models.protoFile.create({
|
||||
const pfNested = await services.protoFile.create({
|
||||
parentId: pdNested._id,
|
||||
name: 'nested.proto',
|
||||
protoText: 'nested',
|
||||
@@ -167,21 +168,21 @@ describe('writeProtoFile', () => {
|
||||
|
||||
it('should not write file if it already exists', async () => {
|
||||
// Arrange
|
||||
const w = await models.workspace.create();
|
||||
const pdRoot = await models.protoDirectory.create({
|
||||
const w = await services.workspace.create();
|
||||
const pdRoot = await services.protoDirectory.create({
|
||||
parentId: w._id,
|
||||
name: 'rootDir',
|
||||
});
|
||||
const pdNested = await models.protoDirectory.create({
|
||||
const pdNested = await services.protoDirectory.create({
|
||||
parentId: pdRoot._id,
|
||||
name: 'nestedDir',
|
||||
});
|
||||
const pfRoot = await models.protoFile.create({
|
||||
const pfRoot = await services.protoFile.create({
|
||||
parentId: pdRoot._id,
|
||||
name: 'root.proto',
|
||||
protoText: 'root',
|
||||
});
|
||||
const pfNested = await models.protoFile.create({
|
||||
const pfNested = await services.protoFile.create({
|
||||
parentId: pdNested._id,
|
||||
name: 'nested.proto',
|
||||
protoText: 'nested',
|
||||
|
||||
@@ -1,8 +1,9 @@
|
||||
import { beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
|
||||
import { services } from '~/insomnia-data';
|
||||
|
||||
import { CONTENT_TYPE_FORM_URLENCODED } from '../../../common/constants';
|
||||
import { database as db } from '../../../common/database';
|
||||
import * as models from '../../../models';
|
||||
import * as plugin from '../request';
|
||||
const CONTEXT = {
|
||||
user_key: 'my_user_key',
|
||||
@@ -19,11 +20,11 @@ describe('init()', () => {
|
||||
beforeEach(async () => {
|
||||
await db.init({ inMemoryOnly: true }, true, () => {});
|
||||
|
||||
await models.workspace.create({
|
||||
await services.workspace.create({
|
||||
_id: 'wrk_1',
|
||||
name: 'My Workspace',
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_1',
|
||||
parentId: 'wrk_1',
|
||||
name: 'My Request',
|
||||
@@ -31,7 +32,7 @@ describe('init()', () => {
|
||||
});
|
||||
|
||||
it('initializes correctly', async () => {
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT);
|
||||
const result = plugin.init(await services.request.getById('req_1'), CONTEXT);
|
||||
expect(Object.keys(result)).toEqual(['request']);
|
||||
expect(Object.keys(result.request).sort()).toEqual([
|
||||
'addHeader',
|
||||
@@ -70,7 +71,7 @@ describe('init()', () => {
|
||||
});
|
||||
|
||||
it('initializes correctly in read-only mode', async () => {
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT, true);
|
||||
const result = plugin.init(await services.request.getById('req_1'), CONTEXT, true);
|
||||
expect(Object.keys(result)).toEqual(['request']);
|
||||
expect(Object.keys(result.request).sort()).toEqual([
|
||||
'getAuthentication',
|
||||
@@ -100,11 +101,11 @@ describe('request.*', () => {
|
||||
beforeEach(async () => {
|
||||
await db.init({ inMemoryOnly: true }, true, () => {});
|
||||
|
||||
await models.workspace.create({
|
||||
await services.workspace.create({
|
||||
_id: 'wrk_1',
|
||||
name: 'My Workspace',
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_1',
|
||||
parentId: 'wrk_1',
|
||||
name: 'My Request',
|
||||
@@ -139,7 +140,7 @@ describe('request.*', () => {
|
||||
|
||||
it('works for basic getters', async () => {
|
||||
const consoleWarnSpy = vi.spyOn(console, 'warn').mockImplementation(() => {});
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT);
|
||||
const result = plugin.init(await services.request.getById('req_1'), CONTEXT);
|
||||
expect(result.request.getId()).toBe('req_1');
|
||||
expect(result.request.getName()).toBe('My Request');
|
||||
expect(result.request.getUrl()).toBe('');
|
||||
@@ -152,7 +153,7 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for parameters', async () => {
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT);
|
||||
const result = plugin.init(await services.request.getById('req_1'), CONTEXT);
|
||||
// getParameters()
|
||||
expect(result.request.getParameters()).toEqual([
|
||||
{
|
||||
@@ -184,7 +185,7 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for headers', async () => {
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT);
|
||||
const result = plugin.init(await services.request.getById('req_1'), CONTEXT);
|
||||
// getHeaders()
|
||||
expect(result.request.getHeaders()).toEqual([
|
||||
{
|
||||
@@ -216,7 +217,7 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for cookies', async () => {
|
||||
const request = await models.request.getById('req_1');
|
||||
const request = await services.request.getById('req_1');
|
||||
request.cookies = []; // Because the plugin technically needs a RenderedRequest
|
||||
|
||||
const result = plugin.init(request, CONTEXT);
|
||||
@@ -231,7 +232,7 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for environment', async () => {
|
||||
const request = await models.request.getById('req_1');
|
||||
const request = await services.request.getById('req_1');
|
||||
request.cookies = []; // Because the plugin technically needs a RenderedRequest
|
||||
|
||||
const result = plugin.init(request, CONTEXT);
|
||||
@@ -259,7 +260,7 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for authentication', async () => {
|
||||
const request = await models.request.getById('req_1');
|
||||
const request = await services.request.getById('req_1');
|
||||
request.authentication = {}; // Because the plugin technically needs a RenderedRequest
|
||||
|
||||
const result = plugin.init(request, CONTEXT);
|
||||
@@ -274,7 +275,7 @@ describe('request.*', () => {
|
||||
});
|
||||
|
||||
it('works for request body', async () => {
|
||||
const result = plugin.init(await models.request.getById('req_1'), CONTEXT);
|
||||
const result = plugin.init(await services.request.getById('req_1'), CONTEXT);
|
||||
expect(result.request.getBody()).toEqual({
|
||||
text: 'body',
|
||||
});
|
||||
|
||||
@@ -4,7 +4,8 @@ import path from 'node:path';
|
||||
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import * as models from '../../../models/index';
|
||||
import { models } from '~/insomnia-data';
|
||||
|
||||
import * as plugin from '../response';
|
||||
|
||||
describe('init()', () => {
|
||||
|
||||
@@ -11,8 +11,8 @@ import { createBuilder } from '@develohpanda/fluent-builder';
|
||||
import { afterAll, beforeEach, describe, expect, it, vi } from 'vitest';
|
||||
import YAML from 'yaml';
|
||||
|
||||
import { database as db } from '../../../common/database';
|
||||
import * as models from '../../../models';
|
||||
import { database as db, models, services } from '~/insomnia-data';
|
||||
|
||||
import { workspaceModelSchema } from '../../../models/__schemas__/model-schemas';
|
||||
import { GIT_CLONE_DIR, GIT_INSOMNIA_DIR, GIT_INSOMNIA_DIR_NAME } from '../git-vcs';
|
||||
import { NeDBClient } from '../ne-db-client';
|
||||
@@ -32,13 +32,13 @@ describe('NeDBClient', () => {
|
||||
await db.init({ inMemoryOnly: true }, true);
|
||||
|
||||
// Create test project
|
||||
await models.project.create({
|
||||
await services.project.create({
|
||||
_id: 'proj_test',
|
||||
name: 'Test Project',
|
||||
});
|
||||
|
||||
// Create test workspace
|
||||
await models.workspace.create({
|
||||
await services.workspace.create({
|
||||
_id: 'wrk_test',
|
||||
name: 'Test Workspace',
|
||||
parentId: 'proj_test',
|
||||
@@ -46,7 +46,7 @@ describe('NeDBClient', () => {
|
||||
});
|
||||
|
||||
// Create test requests
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_test_1',
|
||||
name: 'Test Request 1',
|
||||
parentId: 'wrk_test',
|
||||
@@ -55,7 +55,7 @@ describe('NeDBClient', () => {
|
||||
metaSortKey: 0,
|
||||
});
|
||||
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_test_2',
|
||||
name: 'Test Request 2',
|
||||
parentId: 'wrk_test',
|
||||
@@ -65,7 +65,7 @@ describe('NeDBClient', () => {
|
||||
});
|
||||
|
||||
// Create private request (should not be accessible)
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_private',
|
||||
name: 'Private Request',
|
||||
parentId: 'wrk_test',
|
||||
@@ -76,7 +76,7 @@ describe('NeDBClient', () => {
|
||||
});
|
||||
|
||||
// Create environment
|
||||
await models.environment.create({
|
||||
await services.environment.create({
|
||||
_id: 'env_test',
|
||||
name: 'Test Environment',
|
||||
parentId: 'wrk_test',
|
||||
|
||||
@@ -1,6 +1,7 @@
|
||||
import { describe, expect, it } from 'vitest';
|
||||
|
||||
import * as models from '../../../models';
|
||||
import { models } from '~/insomnia-data';
|
||||
|
||||
import { GIT_INSOMNIA_DIR } from '../git-vcs';
|
||||
import parseGitPath from '../parse-git-path';
|
||||
|
||||
|
||||
@@ -1,22 +1,21 @@
|
||||
import { exportRequestsHAR, exportWorkspacesHAR } from 'insomnia/src/common/har';
|
||||
import { beforeEach, describe, expect, it } from 'vitest';
|
||||
|
||||
import { database as db } from '../../../../common/database';
|
||||
import * as models from '../../../../models';
|
||||
import { database as db, services } from '~/insomnia-data';
|
||||
|
||||
// @vitest-environment jsdom
|
||||
describe('exportWorkspacesHAR() and exportRequestsHAR()', () => {
|
||||
beforeEach(async () => {
|
||||
await models.project.all();
|
||||
await services.project.all();
|
||||
await services.settings.getOrCreate();
|
||||
});
|
||||
|
||||
it('exports a single workspace and some requests only as an HTTP Archive', async () => {
|
||||
const wrk1 = await models.workspace.create({
|
||||
const wrk1 = await services.workspace.create({
|
||||
_id: 'wrk_1',
|
||||
name: 'Workspace 1',
|
||||
});
|
||||
const req1 = await models.request.create({
|
||||
const req1 = await services.request.create({
|
||||
_id: 'req_1',
|
||||
name: 'Request 1',
|
||||
parentId: wrk1._id,
|
||||
@@ -28,34 +27,34 @@ describe('exportWorkspacesHAR() and exportRequestsHAR()', () => {
|
||||
],
|
||||
metaSortKey: 0,
|
||||
});
|
||||
const req2 = await models.request.create({
|
||||
const req2 = await services.request.create({
|
||||
_id: 'req_2',
|
||||
name: 'Request 2',
|
||||
parentId: wrk1._id,
|
||||
metaSortKey: 1,
|
||||
});
|
||||
let env1Base = await models.environment.getOrCreateForParentId(wrk1._id);
|
||||
env1Base = await models.environment.update(env1Base, {
|
||||
let env1Base = await services.environment.getOrCreateForParentId(wrk1._id);
|
||||
env1Base = await services.environment.update(env1Base, {
|
||||
data: {
|
||||
envvalue: 'base1',
|
||||
},
|
||||
});
|
||||
const env1Private = await models.environment.create({
|
||||
const env1Private = await services.environment.create({
|
||||
name: 'Private',
|
||||
parentId: env1Base._id,
|
||||
data: {
|
||||
envvalue: 'private1',
|
||||
},
|
||||
});
|
||||
await models.workspaceMeta.create({
|
||||
await services.workspaceMeta.create({
|
||||
parentId: wrk1._id,
|
||||
activeEnvironmentId: env1Private._id,
|
||||
});
|
||||
const wrk2 = await models.workspace.create({
|
||||
const wrk2 = await services.workspace.create({
|
||||
_id: 'wrk_2',
|
||||
name: 'Workspace 2',
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_3',
|
||||
name: 'Request 3',
|
||||
parentId: wrk2._id,
|
||||
@@ -111,15 +110,15 @@ describe('exportWorkspacesHAR() and exportRequestsHAR()', () => {
|
||||
it('exports all workspaces as an HTTP Archive', async () => {
|
||||
await db.init({ inMemoryOnly: true }, true);
|
||||
|
||||
const wrk1 = await models.workspace.create({
|
||||
const wrk1 = await services.workspace.create({
|
||||
_id: 'wrk_1',
|
||||
name: 'Workspace 1',
|
||||
});
|
||||
const wrk2 = await models.workspace.create({
|
||||
const wrk2 = await services.workspace.create({
|
||||
_id: 'wrk_2',
|
||||
name: 'Workspace 2',
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_1',
|
||||
name: 'Request 1',
|
||||
parentId: wrk1._id,
|
||||
@@ -130,7 +129,7 @@ describe('exportWorkspacesHAR() and exportRequestsHAR()', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
await models.request.create({
|
||||
await services.request.create({
|
||||
_id: 'req_2',
|
||||
name: 'Request 2',
|
||||
parentId: wrk2._id,
|
||||
@@ -141,26 +140,26 @@ describe('exportWorkspacesHAR() and exportRequestsHAR()', () => {
|
||||
},
|
||||
],
|
||||
});
|
||||
let env1Base = await models.environment.getOrCreateForParentId(wrk1._id);
|
||||
env1Base = await models.environment.update(env1Base, {
|
||||
let env1Base = await services.environment.getOrCreateForParentId(wrk1._id);
|
||||
env1Base = await services.environment.update(env1Base, {
|
||||
data: {
|
||||
envvalue: 'base1',
|
||||
},
|
||||
});
|
||||
const env1Public = await models.environment.create({
|
||||
const env1Public = await services.environment.create({
|
||||
name: 'Public',
|
||||
parentId: env1Base._id,
|
||||
data: {
|
||||
envvalue: 'public1',
|
||||
},
|
||||
});
|
||||
const env2Base = await models.environment.getOrCreateForParentId(wrk2._id);
|
||||
await models.environment.update(env2Base, {
|
||||
const env2Base = await services.environment.getOrCreateForParentId(wrk2._id);
|
||||
await services.environment.update(env2Base, {
|
||||
data: {
|
||||
envvalue: 'base2',
|
||||
},
|
||||
});
|
||||
const env2Private = await models.environment.create({
|
||||
const env2Private = await services.environment.create({
|
||||
name: 'Private',
|
||||
isPrivate: true,
|
||||
parentId: env1Base._id,
|
||||
@@ -168,11 +167,11 @@ describe('exportWorkspacesHAR() and exportRequestsHAR()', () => {
|
||||
envvalue: 'private2',
|
||||
},
|
||||
});
|
||||
await models.workspaceMeta.create({
|
||||
await services.workspaceMeta.create({
|
||||
parentId: wrk1._id,
|
||||
activeEnvironmentId: env1Public._id,
|
||||
});
|
||||
await models.workspaceMeta.create({
|
||||
await services.workspaceMeta.create({
|
||||
parentId: wrk2._id,
|
||||
activeEnvironmentId: env2Private._id,
|
||||
});
|
||||
|
||||
Reference in New Issue
Block a user