snapshot of https://github.com/mountain-loop/yaak.git (main, 2026-09-23; blobs > 131072B omitted)
This commit is contained in:
91
plugins/importer-insomnia/tests/body.test.ts
Normal file
91
plugins/importer-insomnia/tests/body.test.ts
Normal file
@@ -0,0 +1,91 @@
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import { importHttpBodyAndHeaders } from "../src/common";
|
||||
|
||||
describe("importHttpBodyAndHeaders", () => {
|
||||
test("imports XML text using the native XML body type", () => {
|
||||
const result = importHttpBodyAndHeaders({
|
||||
body: {
|
||||
mimeType: "application/soap+xml; charset=utf-8",
|
||||
text: "<soap:Envelope />",
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
bodyType: "text/xml",
|
||||
body: { text: "<soap:Envelope />" },
|
||||
headers: [
|
||||
{
|
||||
enabled: true,
|
||||
name: "Content-Type",
|
||||
value: "application/soap+xml; charset=utf-8",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("imports vendor JSON using the native JSON body type", () => {
|
||||
const result = importHttpBodyAndHeaders({
|
||||
body: {
|
||||
mimeType: "application/problem+json",
|
||||
text: '{"message":"Nope"}',
|
||||
},
|
||||
});
|
||||
|
||||
expect(result.bodyType).toBe("application/json");
|
||||
expect(result.body).toEqual({ text: '{"message":"Nope"}' });
|
||||
});
|
||||
|
||||
test("imports unknown text using the other body type", () => {
|
||||
const result = importHttpBodyAndHeaders({
|
||||
body: {
|
||||
mimeType: "application/yaml",
|
||||
text: "message: hello",
|
||||
},
|
||||
});
|
||||
|
||||
expect(result).toEqual({
|
||||
bodyType: "other",
|
||||
body: { text: "message: hello" },
|
||||
headers: [
|
||||
{
|
||||
enabled: true,
|
||||
name: "Content-Type",
|
||||
value: "application/yaml",
|
||||
},
|
||||
],
|
||||
});
|
||||
});
|
||||
|
||||
test("preserves an explicit content type instead of adding a duplicate", () => {
|
||||
const result = importHttpBodyAndHeaders({
|
||||
body: {
|
||||
mimeType: "application/yaml",
|
||||
text: "message: hello",
|
||||
},
|
||||
headers: [
|
||||
{
|
||||
name: "content-type",
|
||||
value: "application/x-yaml",
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
expect(result.headers).toEqual([
|
||||
{
|
||||
enabled: true,
|
||||
name: "content-type",
|
||||
value: "application/x-yaml",
|
||||
},
|
||||
]);
|
||||
});
|
||||
|
||||
test("imports text without inventing a content type", () => {
|
||||
const result = importHttpBodyAndHeaders({ body: { text: "hello" } });
|
||||
|
||||
expect(result).toEqual({
|
||||
bodyType: "other",
|
||||
body: { text: "hello" },
|
||||
headers: [],
|
||||
});
|
||||
});
|
||||
});
|
||||
187
plugins/importer-insomnia/tests/fixtures/basic.input.json
vendored
Normal file
187
plugins/importer-insomnia/tests/fixtures/basic.input.json
vendored
Normal file
@@ -0,0 +1,187 @@
|
||||
{
|
||||
"_type": "export",
|
||||
"__export_format": 4,
|
||||
"__export_date": "2025-01-13T15:19:18.330Z",
|
||||
"__export_source": "insomnia.desktop.app:v10.3.0",
|
||||
"resources": [
|
||||
{
|
||||
"_id": "req_84cd9ae4bd034dd8bb730e856a665cbb",
|
||||
"parentId": "fld_859d1df78261463480b6a3a1419517e3",
|
||||
"modified": 1736781473176,
|
||||
"created": 1736781406672,
|
||||
"url": "{{ _.BASE_URL }}/foo/:id",
|
||||
"name": "New Request",
|
||||
"description": "My description of the request",
|
||||
"method": "GET",
|
||||
"body": {
|
||||
"mimeType": "multipart/form-data",
|
||||
"params": [
|
||||
{
|
||||
"id": "pair_7c86036ae8ef499dbbc0b43d0800c5a3",
|
||||
"name": "form",
|
||||
"value": "data",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
]
|
||||
},
|
||||
"parameters": [
|
||||
{
|
||||
"id": "pair_b22f6ff611cd4250a6e405ca7b713d09",
|
||||
"name": "query",
|
||||
"value": "qqq",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"headers": [
|
||||
{
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data",
|
||||
"id": "pair_4af845963bd14256b98716617971eecd"
|
||||
},
|
||||
{
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/10.3.0",
|
||||
"id": "pair_535ffd00ce48462cb1b7258832ade65a"
|
||||
},
|
||||
{
|
||||
"id": "pair_ab4b870278e943cba6babf5a73e213e3",
|
||||
"name": "X-Header",
|
||||
"value": "xxxx",
|
||||
"description": "",
|
||||
"disabled": false
|
||||
}
|
||||
],
|
||||
"authentication": {
|
||||
"type": "basic",
|
||||
"useISO88591": false,
|
||||
"disabled": false,
|
||||
"username": "user",
|
||||
"password": "pass"
|
||||
},
|
||||
"metaSortKey": -1736781406672,
|
||||
"isPrivate": false,
|
||||
"pathParameters": [
|
||||
{
|
||||
"name": "id",
|
||||
"value": "iii"
|
||||
}
|
||||
],
|
||||
"settingStoreCookies": true,
|
||||
"settingSendCookies": true,
|
||||
"settingDisableRenderRequestBody": false,
|
||||
"settingEncodeUrl": true,
|
||||
"settingRebuildPath": true,
|
||||
"settingFollowRedirects": "global",
|
||||
"_type": "request"
|
||||
},
|
||||
{
|
||||
"_id": "fld_859d1df78261463480b6a3a1419517e3",
|
||||
"parentId": "wrk_d4d92f7c0ee947b89159243506687019",
|
||||
"modified": 1736781404718,
|
||||
"created": 1736781404718,
|
||||
"name": "Top Level",
|
||||
"description": "",
|
||||
"environment": {},
|
||||
"environmentPropertyOrder": null,
|
||||
"metaSortKey": -1736781404718,
|
||||
"environmentType": "kv",
|
||||
"_type": "request_group"
|
||||
},
|
||||
{
|
||||
"_id": "wrk_d4d92f7c0ee947b89159243506687019",
|
||||
"parentId": null,
|
||||
"modified": 1736781343765,
|
||||
"created": 1736781343765,
|
||||
"name": "Dummy",
|
||||
"description": "",
|
||||
"scope": "collection",
|
||||
"_type": "workspace"
|
||||
},
|
||||
{
|
||||
"_id": "env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"parentId": "wrk_d4d92f7c0ee947b89159243506687019",
|
||||
"modified": 1736781355209,
|
||||
"created": 1736781343767,
|
||||
"name": "Base Environment",
|
||||
"data": {
|
||||
"BASE_VAR": "hello"
|
||||
},
|
||||
"dataPropertyOrder": null,
|
||||
"color": null,
|
||||
"isPrivate": false,
|
||||
"metaSortKey": 1736781343767,
|
||||
"environmentType": "kv",
|
||||
"kvPairData": [
|
||||
{
|
||||
"id": "envPair_61c1be66d42241b5a28306d2cd92d3e3",
|
||||
"name": "BASE_VAR",
|
||||
"value": "hello",
|
||||
"type": "str",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"_type": "environment"
|
||||
},
|
||||
{
|
||||
"_id": "jar_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"parentId": "wrk_d4d92f7c0ee947b89159243506687019",
|
||||
"modified": 1736781343768,
|
||||
"created": 1736781343768,
|
||||
"name": "Default Jar",
|
||||
"cookies": [],
|
||||
"_type": "cookie_jar"
|
||||
},
|
||||
{
|
||||
"_id": "env_799ae3d723ef44af91b4817e5d057e6d",
|
||||
"parentId": "env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"modified": 1736781394705,
|
||||
"created": 1736781358515,
|
||||
"name": "Production",
|
||||
"data": {
|
||||
"BASE_URL": "https://api.yaak.app"
|
||||
},
|
||||
"dataPropertyOrder": null,
|
||||
"color": "#f22c2c",
|
||||
"isPrivate": false,
|
||||
"metaSortKey": 1736781358515,
|
||||
"environmentType": "kv",
|
||||
"kvPairData": [
|
||||
{
|
||||
"id": "envPair_4d97b569b7e845ccbf488e1b26637cbc",
|
||||
"name": "BASE_URL",
|
||||
"value": "https://api.yaak.app",
|
||||
"type": "str",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"_type": "environment"
|
||||
},
|
||||
{
|
||||
"_id": "env_030fbfdbb274426ebd78e2e6518f8553",
|
||||
"parentId": "env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"modified": 1736781391078,
|
||||
"created": 1736781374707,
|
||||
"name": "Staging",
|
||||
"data": {
|
||||
"BASE_URL": "https://api.staging.yaak.app"
|
||||
},
|
||||
"dataPropertyOrder": null,
|
||||
"color": "#206fac",
|
||||
"isPrivate": false,
|
||||
"metaSortKey": 1736781358565,
|
||||
"environmentType": "kv",
|
||||
"kvPairData": [
|
||||
{
|
||||
"id": "envPair_4d97b569b7e845ccbf488e1b26637cbc",
|
||||
"name": "BASE_URL",
|
||||
"value": "https://api.staging.yaak.app",
|
||||
"type": "str",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"_type": "environment"
|
||||
}
|
||||
]
|
||||
}
|
||||
144
plugins/importer-insomnia/tests/fixtures/basic.output.json
vendored
Normal file
144
plugins/importer-insomnia/tests/fixtures/basic.output.json
vendored
Normal file
@@ -0,0 +1,144 @@
|
||||
{
|
||||
"resources": {
|
||||
"environments": [
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:43.767",
|
||||
"updatedAt": "2025-01-13T15:15:55.209",
|
||||
"sortPriority": 1736781343767,
|
||||
"parentId": null,
|
||||
"parentModel": "workspace",
|
||||
"id": "GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"model": "environment",
|
||||
"name": "Base Environment",
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "BASE_VAR",
|
||||
"value": "hello"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019"
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:58.515",
|
||||
"updatedAt": "2025-01-13T15:16:34.705",
|
||||
"sortPriority": 1736781358515,
|
||||
"parentId": null,
|
||||
"parentModel": "environment",
|
||||
"id": "GENERATE_ID::env_799ae3d723ef44af91b4817e5d057e6d",
|
||||
"model": "environment",
|
||||
"name": "Production",
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "BASE_URL",
|
||||
"value": "https://api.yaak.app"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019"
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-01-13T15:16:14.707",
|
||||
"updatedAt": "2025-01-13T15:16:31.078",
|
||||
"sortPriority": 1736781358565,
|
||||
"parentId": null,
|
||||
"parentModel": "environment",
|
||||
"id": "GENERATE_ID::env_030fbfdbb274426ebd78e2e6518f8553",
|
||||
"model": "environment",
|
||||
"name": "Staging",
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "BASE_URL",
|
||||
"value": "https://api.staging.yaak.app"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019"
|
||||
}
|
||||
],
|
||||
"folders": [
|
||||
{
|
||||
"createdAt": "2025-01-13T15:16:44.718",
|
||||
"updatedAt": "2025-01-13T15:16:44.718",
|
||||
"folderId": null,
|
||||
"id": "GENERATE_ID::fld_859d1df78261463480b6a3a1419517e3",
|
||||
"model": "folder",
|
||||
"name": "Top Level",
|
||||
"workspaceId": "GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019"
|
||||
}
|
||||
],
|
||||
"grpcRequests": [],
|
||||
"httpRequests": [
|
||||
{
|
||||
"authentication": {
|
||||
"password": "pass",
|
||||
"username": "user"
|
||||
},
|
||||
"authenticationType": "basic",
|
||||
"body": {
|
||||
"form": [
|
||||
{
|
||||
"enabled": true,
|
||||
"file": null,
|
||||
"name": "form",
|
||||
"value": "data"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bodyType": "multipart/form-data",
|
||||
"createdAt": "2025-01-13T15:16:46.672",
|
||||
"sortPriority": -1736781406672,
|
||||
"updatedAt": "2025-01-13T15:17:53.176",
|
||||
"description": "My description of the request",
|
||||
"folderId": "GENERATE_ID::fld_859d1df78261463480b6a3a1419517e3",
|
||||
"headers": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data"
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/10.3.0"
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "X-Header",
|
||||
"value": "xxxx"
|
||||
}
|
||||
],
|
||||
"id": "GENERATE_ID::req_84cd9ae4bd034dd8bb730e856a665cbb",
|
||||
"method": "GET",
|
||||
"model": "http_request",
|
||||
"name": "New Request",
|
||||
"url": "${[BASE_URL ]}/foo/:id",
|
||||
"urlParameters": [
|
||||
{
|
||||
"name": "query",
|
||||
"value": "qqq",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019"
|
||||
}
|
||||
],
|
||||
"websocketRequests": [],
|
||||
"workspaces": [
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:43.765",
|
||||
"id": "GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019",
|
||||
"model": "workspace",
|
||||
"name": "Dummy"
|
||||
}
|
||||
]
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::env_16c0dec5b77c414ae0e419b8f10c3701300c5900": "env_16c0dec5b77c414ae0e419b8f10c3701300c5900",
|
||||
"GENERATE_ID::env_799ae3d723ef44af91b4817e5d057e6d": "env_799ae3d723ef44af91b4817e5d057e6d",
|
||||
"GENERATE_ID::env_030fbfdbb274426ebd78e2e6518f8553": "env_030fbfdbb274426ebd78e2e6518f8553",
|
||||
"GENERATE_ID::fld_859d1df78261463480b6a3a1419517e3": "fld_859d1df78261463480b6a3a1419517e3",
|
||||
"GENERATE_ID::req_84cd9ae4bd034dd8bb730e856a665cbb": "req_84cd9ae4bd034dd8bb730e856a665cbb",
|
||||
"GENERATE_ID::wrk_d4d92f7c0ee947b89159243506687019": "wrk_d4d92f7c0ee947b89159243506687019"
|
||||
}
|
||||
}
|
||||
74
plugins/importer-insomnia/tests/fixtures/version-5-minimal.input.yaml
vendored
Normal file
74
plugins/importer-insomnia/tests/fixtures/version-5-minimal.input.yaml
vendored
Normal file
@@ -0,0 +1,74 @@
|
||||
type: collection.insomnia.rest/5.0
|
||||
name: Debugging
|
||||
meta:
|
||||
id: wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c
|
||||
created: 1747197924902
|
||||
modified: 1747197924902
|
||||
collection:
|
||||
- name: My Folder
|
||||
meta:
|
||||
id: fld_296933ea4ea84783a775d199997e9be7
|
||||
created: 1747414092298
|
||||
modified: 1747414142427
|
||||
sortKey: -1747414092298
|
||||
children:
|
||||
- url: https://httpbin.org/post
|
||||
name: New Request
|
||||
meta:
|
||||
id: req_9a80320365ac4509ade406359dbc6a71
|
||||
created: 1747197928502
|
||||
modified: 1747414129313
|
||||
isPrivate: false
|
||||
sortKey: -1747414129276
|
||||
method: GET
|
||||
headers:
|
||||
- name: User-Agent
|
||||
value: insomnia/11.1.0
|
||||
id: pair_6ae87d1620a9494f8e5b29cd9f92d087
|
||||
settings:
|
||||
renderRequestBody: true
|
||||
encodeUrl: true
|
||||
followRedirects: global
|
||||
cookies:
|
||||
send: true
|
||||
store: true
|
||||
rebuildPath: true
|
||||
headers:
|
||||
- id: pair_f2b330e3914f4c11b209318aef94325c
|
||||
name: foo
|
||||
value: bar
|
||||
disabled: false
|
||||
environment:
|
||||
folder_env_var: testing
|
||||
- name: New Request
|
||||
meta:
|
||||
id: req_e3f8cdbd58784a539dd4c1e127d73451
|
||||
created: 1747414160497
|
||||
modified: 1747414160497
|
||||
isPrivate: false
|
||||
sortKey: -1747414160498
|
||||
method: GET
|
||||
headers:
|
||||
- name: User-Agent
|
||||
value: insomnia/11.1.0
|
||||
settings:
|
||||
renderRequestBody: true
|
||||
encodeUrl: true
|
||||
followRedirects: global
|
||||
cookies:
|
||||
send: true
|
||||
store: true
|
||||
rebuildPath: true
|
||||
cookieJar:
|
||||
name: Default Jar
|
||||
meta:
|
||||
id: jar_e46dc73e8ccda30ca132153e8f11183bd08119ce
|
||||
created: 1747197924904
|
||||
modified: 1747197924904
|
||||
environments:
|
||||
name: Base Environment
|
||||
meta:
|
||||
id: env_e46dc73e8ccda30ca132153e8f11183bd08119ce
|
||||
created: 1747197924903
|
||||
modified: 1747197924903
|
||||
isPrivate: false
|
||||
128
plugins/importer-insomnia/tests/fixtures/version-5-minimal.output.json
vendored
Normal file
128
plugins/importer-insomnia/tests/fixtures/version-5-minimal.output.json
vendored
Normal file
@@ -0,0 +1,128 @@
|
||||
{
|
||||
"resources": {
|
||||
"environments": [
|
||||
{
|
||||
"createdAt": "2025-05-14T04:45:24.903",
|
||||
"id": "GENERATE_ID::env_e46dc73e8ccda30ca132153e8f11183bd08119ce",
|
||||
"model": "environment",
|
||||
"name": "Base Environment",
|
||||
"public": true,
|
||||
"updatedAt": "2025-05-14T04:45:24.903",
|
||||
"variables": [],
|
||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
||||
"parentId": null,
|
||||
"parentModel": "workspace"
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-05-16T16:48:12.298",
|
||||
"id": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7folder",
|
||||
"model": "environment",
|
||||
"name": "Folder Environment",
|
||||
"parentId": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7",
|
||||
"parentModel": "folder",
|
||||
"public": true,
|
||||
"updatedAt": "2025-05-16T16:49:02.427",
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "folder_env_var",
|
||||
"value": "testing"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
||||
}
|
||||
],
|
||||
"folders": [
|
||||
{
|
||||
"createdAt": "2025-05-16T16:48:12.298",
|
||||
"folderId": null,
|
||||
"id": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7",
|
||||
"model": "folder",
|
||||
"name": "My Folder",
|
||||
"sortPriority": -1747414092298,
|
||||
"updatedAt": "2025-05-16T16:49:02.427",
|
||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
||||
"authentication": {},
|
||||
"authenticationType": null,
|
||||
"headers": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "foo",
|
||||
"value": "bar"
|
||||
}
|
||||
]
|
||||
}
|
||||
],
|
||||
"grpcRequests": [],
|
||||
"httpRequests": [
|
||||
{
|
||||
"authentication": {},
|
||||
"authenticationType": null,
|
||||
"body": {},
|
||||
"bodyType": null,
|
||||
"createdAt": "2025-05-14T04:45:28.502",
|
||||
"folderId": "GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7",
|
||||
"headers": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/11.1.0"
|
||||
}
|
||||
],
|
||||
"id": "GENERATE_ID::req_9a80320365ac4509ade406359dbc6a71",
|
||||
"method": "GET",
|
||||
"model": "http_request",
|
||||
"name": "New Request",
|
||||
"sortPriority": -1747414129276,
|
||||
"updatedAt": "2025-05-16T16:48:49.313",
|
||||
"url": "https://httpbin.org/post",
|
||||
"urlParameters": [],
|
||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
||||
},
|
||||
{
|
||||
"authentication": {},
|
||||
"authenticationType": null,
|
||||
"body": {},
|
||||
"bodyType": null,
|
||||
"createdAt": "2025-05-16T16:49:20.497",
|
||||
"folderId": null,
|
||||
"headers": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/11.1.0"
|
||||
}
|
||||
],
|
||||
"id": "GENERATE_ID::req_e3f8cdbd58784a539dd4c1e127d73451",
|
||||
"method": "GET",
|
||||
"model": "http_request",
|
||||
"name": "New Request",
|
||||
"sortPriority": -1747414160498,
|
||||
"updatedAt": "2025-05-16T16:49:20.497",
|
||||
"urlParameters": [],
|
||||
"workspaceId": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
||||
}
|
||||
],
|
||||
"websocketRequests": [],
|
||||
"workspaces": [
|
||||
{
|
||||
"createdAt": "2025-05-14T04:45:24.902",
|
||||
"id": "GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c",
|
||||
"model": "workspace",
|
||||
"name": "Debugging",
|
||||
"updatedAt": "2025-05-14T04:45:24.902",
|
||||
"authentication": {},
|
||||
"authenticationType": null,
|
||||
"headers": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::env_e46dc73e8ccda30ca132153e8f11183bd08119ce": "env_e46dc73e8ccda30ca132153e8f11183bd08119ce",
|
||||
"GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7folder": "fld_296933ea4ea84783a775d199997e9be7folder",
|
||||
"GENERATE_ID::fld_296933ea4ea84783a775d199997e9be7": "fld_296933ea4ea84783a775d199997e9be7",
|
||||
"GENERATE_ID::req_9a80320365ac4509ade406359dbc6a71": "req_9a80320365ac4509ade406359dbc6a71",
|
||||
"GENERATE_ID::req_e3f8cdbd58784a539dd4c1e127d73451": "req_e3f8cdbd58784a539dd4c1e127d73451",
|
||||
"GENERATE_ID::wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c": "wrk_9717dd1c9e0c4b2e9ed6d2abcf3bd45c"
|
||||
}
|
||||
}
|
||||
146
plugins/importer-insomnia/tests/fixtures/version-5.input.yaml
vendored
Normal file
146
plugins/importer-insomnia/tests/fixtures/version-5.input.yaml
vendored
Normal file
@@ -0,0 +1,146 @@
|
||||
type: collection.insomnia.rest/5.0
|
||||
name: Dummy
|
||||
meta:
|
||||
id: wrk_c1eacfa750a04f3ea9985ef28043fa53
|
||||
created: 1746799305927
|
||||
modified: 1746843054272
|
||||
description: This is the description
|
||||
collection:
|
||||
- name: Top Level
|
||||
meta:
|
||||
id: fld_42eb2e2bb22b4cedacbd3d057634e80c
|
||||
created: 1736781404718
|
||||
modified: 1736781404718
|
||||
sortKey: -1736781404718
|
||||
children:
|
||||
- url: "{{ _.BASE_URL }}/foo/:id"
|
||||
name: New Request
|
||||
meta:
|
||||
id: req_d72fff2a6b104b91a2ebe9de9edd2785
|
||||
created: 1736781406672
|
||||
modified: 1736781473176
|
||||
isPrivate: false
|
||||
description: My description of the request
|
||||
sortKey: -1736781406672
|
||||
method: GET
|
||||
body:
|
||||
mimeType: multipart/form-data
|
||||
params:
|
||||
- id: pair_7c86036ae8ef499dbbc0b43d0800c5a3
|
||||
name: form
|
||||
value: data
|
||||
disabled: false
|
||||
parameters:
|
||||
- id: pair_b22f6ff611cd4250a6e405ca7b713d09
|
||||
name: query
|
||||
value: qqq
|
||||
disabled: false
|
||||
headers:
|
||||
- name: Content-Type
|
||||
value: multipart/form-data
|
||||
id: pair_4af845963bd14256b98716617971eecd
|
||||
- name: User-Agent
|
||||
value: insomnia/10.3.0
|
||||
id: pair_535ffd00ce48462cb1b7258832ade65a
|
||||
- id: pair_ab4b870278e943cba6babf5a73e213e3
|
||||
name: X-Header
|
||||
value: xxxx
|
||||
disabled: false
|
||||
- id: pair_ab4b870278e943cba6babf5a73e213e3
|
||||
name: "{{ _.ApiHeaderName }}"
|
||||
value: "{{ _.ApiKey }}"
|
||||
disabled: false
|
||||
authentication:
|
||||
type: basic
|
||||
useISO88591: false
|
||||
disabled: false
|
||||
username: user
|
||||
password: pass
|
||||
settings:
|
||||
renderRequestBody: true
|
||||
encodeUrl: true
|
||||
followRedirects: global
|
||||
cookies:
|
||||
send: true
|
||||
store: true
|
||||
rebuildPath: true
|
||||
pathParameters:
|
||||
- name: id
|
||||
value: iii
|
||||
- url: grpcb.in:9000
|
||||
name: New Request
|
||||
meta:
|
||||
id: greq_06d659324df94504a4d64632be7106b3
|
||||
created: 1746799344864
|
||||
modified: 1746799544082
|
||||
isPrivate: false
|
||||
sortKey: -1746799344864
|
||||
body:
|
||||
text: |-
|
||||
{
|
||||
"greeting": "Greg"
|
||||
}
|
||||
protoFileId: pf_9d45b0dfaccc4bcc9d930746716786c5
|
||||
protoMethodName: /hello.HelloService/SayHello
|
||||
reflectionApi:
|
||||
enabled: false
|
||||
url: https://buf.build
|
||||
module: buf.build/connectrpc/eliza
|
||||
- url: wss://echo.websocket.org
|
||||
name: New WebSocket Request
|
||||
meta:
|
||||
id: ws-req_5d1a4c7c79494743962e5176f6add270
|
||||
created: 1746799553909
|
||||
modified: 1746887120958
|
||||
sortKey: -1746799553909
|
||||
settings:
|
||||
encodeUrl: true
|
||||
followRedirects: global
|
||||
cookies:
|
||||
send: true
|
||||
store: true
|
||||
authentication:
|
||||
type: basic
|
||||
useISO88591: false
|
||||
disabled: false
|
||||
username: user
|
||||
password: password
|
||||
headers:
|
||||
- name: User-Agent
|
||||
value: insomnia/11.1.0
|
||||
cookieJar:
|
||||
name: Default Jar
|
||||
meta:
|
||||
id: jar_663d5741b072441aa2709a6113371510
|
||||
created: 1736781343768
|
||||
modified: 1736781343768
|
||||
environments:
|
||||
name: Base Environment
|
||||
meta:
|
||||
id: env_20945044d3c8497ca8b717bef750987e
|
||||
created: 1736781343767
|
||||
modified: 1736781355209
|
||||
isPrivate: false
|
||||
data:
|
||||
BASE_VAR: hello
|
||||
subEnvironments:
|
||||
- name: Production
|
||||
meta:
|
||||
id: env_6f7728bb7fc04d558d668e954d756ea2
|
||||
created: 1736781358515
|
||||
modified: 1736781394705
|
||||
isPrivate: false
|
||||
sortKey: 1736781358515
|
||||
data:
|
||||
BASE_URL: https://api.yaak.app
|
||||
color: "#f22c2c"
|
||||
- name: Staging
|
||||
meta:
|
||||
id: env_976a8b6eb5d44fb6a20150f65c32d243
|
||||
created: 1736781374707
|
||||
modified: 1736781391078
|
||||
isPrivate: false
|
||||
sortKey: 1736781358565
|
||||
data:
|
||||
BASE_URL: https://api.staging.yaak.app
|
||||
color: "#206fac"
|
||||
203
plugins/importer-insomnia/tests/fixtures/version-5.output.json
vendored
Normal file
203
plugins/importer-insomnia/tests/fixtures/version-5.output.json
vendored
Normal file
@@ -0,0 +1,203 @@
|
||||
{
|
||||
"resources": {
|
||||
"environments": [
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:43.767",
|
||||
"updatedAt": "2025-01-13T15:15:55.209",
|
||||
"public": true,
|
||||
"id": "GENERATE_ID::env_20945044d3c8497ca8b717bef750987e",
|
||||
"model": "environment",
|
||||
"name": "Base Environment",
|
||||
"parentId": null,
|
||||
"parentModel": "workspace",
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "BASE_VAR",
|
||||
"value": "hello"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-01-13T15:15:58.515",
|
||||
"updatedAt": "2025-01-13T15:16:34.705",
|
||||
"public": true,
|
||||
"id": "GENERATE_ID::env_6f7728bb7fc04d558d668e954d756ea2",
|
||||
"model": "environment",
|
||||
"name": "Production",
|
||||
"parentId": null,
|
||||
"parentModel": "environment",
|
||||
"sortPriority": 1736781358515,
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "BASE_URL",
|
||||
"value": "https://api.yaak.app"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
},
|
||||
{
|
||||
"createdAt": "2025-01-13T15:16:14.707",
|
||||
"updatedAt": "2025-01-13T15:16:31.078",
|
||||
"public": true,
|
||||
"parentId": null,
|
||||
"parentModel": "environment",
|
||||
"id": "GENERATE_ID::env_976a8b6eb5d44fb6a20150f65c32d243",
|
||||
"model": "environment",
|
||||
"name": "Staging",
|
||||
"sortPriority": 1736781358565,
|
||||
"variables": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "BASE_URL",
|
||||
"value": "https://api.staging.yaak.app"
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
}
|
||||
],
|
||||
"folders": [
|
||||
{
|
||||
"createdAt": "2025-01-13T15:16:44.718",
|
||||
"updatedAt": "2025-01-13T15:16:44.718",
|
||||
"folderId": null,
|
||||
"id": "GENERATE_ID::fld_42eb2e2bb22b4cedacbd3d057634e80c",
|
||||
"model": "folder",
|
||||
"name": "Top Level",
|
||||
"sortPriority": -1736781404718,
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
|
||||
"authentication": {},
|
||||
"authenticationType": null,
|
||||
"headers": []
|
||||
}
|
||||
],
|
||||
"grpcRequests": [
|
||||
{
|
||||
"model": "grpc_request",
|
||||
"createdAt": "2025-05-09T14:02:24.864",
|
||||
"folderId": null,
|
||||
"id": "GENERATE_ID::greq_06d659324df94504a4d64632be7106b3",
|
||||
"message": "{\n\t\"greeting\": \"Greg\"\n}",
|
||||
"metadata": [],
|
||||
"method": "SayHello",
|
||||
"name": "New Request",
|
||||
"service": "hello.HelloService",
|
||||
"sortPriority": -1746799344864,
|
||||
"updatedAt": "2025-05-09T14:05:44.082",
|
||||
"url": "grpcb.in:9000",
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
}
|
||||
],
|
||||
"httpRequests": [
|
||||
{
|
||||
"authentication": {
|
||||
"password": "pass",
|
||||
"username": "user"
|
||||
},
|
||||
"authenticationType": "basic",
|
||||
"body": {
|
||||
"form": [
|
||||
{
|
||||
"enabled": true,
|
||||
"file": null,
|
||||
"name": "form",
|
||||
"value": "data"
|
||||
}
|
||||
]
|
||||
},
|
||||
"bodyType": "multipart/form-data",
|
||||
"createdAt": "2025-01-13T15:16:46.672",
|
||||
"updatedAt": "2025-01-13T15:17:53.176",
|
||||
"description": "My description of the request",
|
||||
"folderId": "GENERATE_ID::fld_42eb2e2bb22b4cedacbd3d057634e80c",
|
||||
"headers": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "Content-Type",
|
||||
"value": "multipart/form-data"
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/10.3.0"
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "X-Header",
|
||||
"value": "xxxx"
|
||||
},
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "${[ApiHeaderName ]}",
|
||||
"value": "${[ApiKey ]}"
|
||||
}
|
||||
],
|
||||
"id": "GENERATE_ID::req_d72fff2a6b104b91a2ebe9de9edd2785",
|
||||
"method": "GET",
|
||||
"model": "http_request",
|
||||
"name": "New Request",
|
||||
"sortPriority": -1736781406672,
|
||||
"url": "${[BASE_URL ]}/foo/:id",
|
||||
"urlParameters": [
|
||||
{
|
||||
"name": "query",
|
||||
"value": "qqq",
|
||||
"enabled": true
|
||||
}
|
||||
],
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
}
|
||||
],
|
||||
"websocketRequests": [
|
||||
{
|
||||
"id": "GENERATE_ID::ws-req_5d1a4c7c79494743962e5176f6add270",
|
||||
"createdAt": "2025-05-09T14:05:53.909",
|
||||
"updatedAt": "2025-05-10T14:25:20.958",
|
||||
"message": "",
|
||||
"model": "websocket_request",
|
||||
"name": "New WebSocket Request",
|
||||
"sortPriority": -1746799553909,
|
||||
"authenticationType": "basic",
|
||||
"authentication": {
|
||||
"password": "password",
|
||||
"username": "user"
|
||||
},
|
||||
"folderId": null,
|
||||
"headers": [
|
||||
{
|
||||
"enabled": true,
|
||||
"name": "User-Agent",
|
||||
"value": "insomnia/11.1.0"
|
||||
}
|
||||
],
|
||||
"url": "wss://echo.websocket.org",
|
||||
"workspaceId": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
}
|
||||
],
|
||||
"workspaces": [
|
||||
{
|
||||
"createdAt": "2025-05-09T14:01:45.927",
|
||||
"updatedAt": "2025-05-10T02:10:54.272",
|
||||
"description": "This is the description",
|
||||
"id": "GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53",
|
||||
"model": "workspace",
|
||||
"name": "Dummy",
|
||||
"authentication": {},
|
||||
"authenticationType": null,
|
||||
"headers": []
|
||||
}
|
||||
]
|
||||
},
|
||||
"sourceKeys": {
|
||||
"GENERATE_ID::env_20945044d3c8497ca8b717bef750987e": "env_20945044d3c8497ca8b717bef750987e",
|
||||
"GENERATE_ID::env_6f7728bb7fc04d558d668e954d756ea2": "env_6f7728bb7fc04d558d668e954d756ea2",
|
||||
"GENERATE_ID::env_976a8b6eb5d44fb6a20150f65c32d243": "env_976a8b6eb5d44fb6a20150f65c32d243",
|
||||
"GENERATE_ID::fld_42eb2e2bb22b4cedacbd3d057634e80c": "fld_42eb2e2bb22b4cedacbd3d057634e80c",
|
||||
"GENERATE_ID::greq_06d659324df94504a4d64632be7106b3": "greq_06d659324df94504a4d64632be7106b3",
|
||||
"GENERATE_ID::req_d72fff2a6b104b91a2ebe9de9edd2785": "req_d72fff2a6b104b91a2ebe9de9edd2785",
|
||||
"GENERATE_ID::ws-req_5d1a4c7c79494743962e5176f6add270": "ws-req_5d1a4c7c79494743962e5176f6add270",
|
||||
"GENERATE_ID::wrk_c1eacfa750a04f3ea9985ef28043fa53": "wrk_c1eacfa750a04f3ea9985ef28043fa53"
|
||||
}
|
||||
}
|
||||
67
plugins/importer-insomnia/tests/index.test.ts
Normal file
67
plugins/importer-insomnia/tests/index.test.ts
Normal file
@@ -0,0 +1,67 @@
|
||||
import * as fs from "node:fs";
|
||||
import * as path from "node:path";
|
||||
import { describe, expect, test } from "vite-plus/test";
|
||||
import YAML from "yaml";
|
||||
import { convertInsomnia } from "../src";
|
||||
|
||||
describe("importer-yaak", () => {
|
||||
const p = path.join(__dirname, "fixtures");
|
||||
const fixtures = fs.readdirSync(p);
|
||||
|
||||
for (const fixture of fixtures) {
|
||||
if (fixture.includes(".output")) {
|
||||
continue;
|
||||
}
|
||||
|
||||
test(`Imports ${fixture}`, () => {
|
||||
const contents = fs.readFileSync(path.join(p, fixture), "utf-8");
|
||||
const expected = fs.readFileSync(
|
||||
path.join(p, fixture.replace(/.input\..*/, ".output.json")),
|
||||
"utf-8",
|
||||
);
|
||||
const result = convertInsomnia(contents);
|
||||
// console.log(JSON.stringify(result, null, 2))
|
||||
expect(result).toEqual(parseJsonOrYaml(expected));
|
||||
});
|
||||
}
|
||||
|
||||
test("Keys resources by their Insomnia _id, unchanged by a rename", () => {
|
||||
const collection = (requestName: string) =>
|
||||
YAML.stringify({
|
||||
type: "collection.insomnia.rest/5.0",
|
||||
name: "Keys",
|
||||
meta: { id: "wrk_1" },
|
||||
environments: { meta: { id: "env_1" }, name: "Base", data: {} },
|
||||
collection: [
|
||||
{
|
||||
meta: { id: "fld_1" },
|
||||
name: "Folder",
|
||||
children: [
|
||||
{
|
||||
meta: { id: "req_1" },
|
||||
name: requestName,
|
||||
method: "GET",
|
||||
url: "https://yaak.app",
|
||||
},
|
||||
],
|
||||
},
|
||||
],
|
||||
});
|
||||
|
||||
const before = convertInsomnia(collection("Original"));
|
||||
const after = convertInsomnia(collection("Renamed"));
|
||||
|
||||
expect(before?.sourceKeys?.[before.resources.httpRequests[0]!.id]).toBe("req_1");
|
||||
expect(after?.sourceKeys?.[after.resources.httpRequests[0]!.id]).toBe("req_1");
|
||||
expect(before?.sourceKeys?.[before.resources.folders[0]!.id]).toBe("fld_1");
|
||||
expect(before?.sourceKeys?.[before.resources.workspaces[0]!.id]).toBe("wrk_1");
|
||||
});
|
||||
});
|
||||
|
||||
function parseJsonOrYaml(text: string): unknown {
|
||||
try {
|
||||
return JSON.parse(text);
|
||||
} catch {
|
||||
return YAML.parse(text);
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user