Skip to content

Commit

Permalink
Feat/import-prereq-script (#7144)
Browse files Browse the repository at this point in the history
* add import function

* fix some of the tests

* more tests

* fix tests
  • Loading branch information
jackkav authored Mar 5, 2024
1 parent 03172c5 commit 24b096b
Show file tree
Hide file tree
Showing 28 changed files with 91 additions and 4 deletions.
9 changes: 7 additions & 2 deletions packages/insomnia/src/ui/routes/workspace.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -122,7 +122,13 @@ export const workspaceLoader: LoaderFunction = async ({
const searchParams = new URL(request.url).searchParams;
const filter = searchParams.get('filter');
const sortOrder = searchParams.get('sortOrder') as SortOrder;
const sortFunction = sortMethodMap[sortOrder] || sortMethodMap['type-manual'];
const defaultSort = (a: Request | GrpcRequest | WebSocketRequest | RequestGroup, b: Request | GrpcRequest | WebSocketRequest | RequestGroup) => {
if (a.metaSortKey === b.metaSortKey) {
return a._id > b._id ? 1 : -1;
}
return a.metaSortKey < b.metaSortKey ? 1 : -1;
};
const sortFunction = sortMethodMap[sortOrder] || defaultSort;

// first recursion to get all the folders ids in order to use nedb search by an array
const flattenFoldersIntoList = async (id: string): Promise<string[]> => {
Expand All @@ -145,7 +151,6 @@ export const workspaceLoader: LoaderFunction = async ({
const grpcRequestMetas = await database.find(models.grpcRequestMeta.type, { parentId: { $in: grpcReqs.map(r => r._id) } });
const grpcAndRequestMetas = [...requestMetas, ...grpcRequestMetas] as (RequestMeta | GrpcRequestMeta)[];
const requestGroupMetas = await database.find(models.requestGroupMeta.type, { parentId: { $in: listOfParentIds } }) as RequestGroupMeta[];

// second recursion to build the tree
const getCollectionTree = async ({
parentId,
Expand Down
1 change: 1 addition & 0 deletions packages/insomnia/src/utils/importers/entities.ts
Original file line number Diff line number Diff line change
Expand Up @@ -77,6 +77,7 @@ export interface ImportRequest<T extends {} = {}> extends Comment {
variable?: UNKNOWN;
queryString?: QueryString[];
url?: string;
preRequestScript?: string;
}

export type Converter<T extends {} = {}> = (
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{
"_id": "__REQ_1__",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "mockbin.org/request/any",
"name": "New Request",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{
"_id": "__REQ_1__",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "mockbin.org/request/any",
"name": "New Request",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
{
"_id": "__REQ_1__",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "mockbin.org/request/any",
"name": "New Request",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "AWS Signature",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "AWS Signature",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Basic Auth",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Basic Auth",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Bearer Token",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Bearer Token",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Test Request",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Test Request",
"parameters": [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "{{base_url}}/api/users",
"description": "First Request",
Expand Down Expand Up @@ -58,6 +59,7 @@
"_id": "__REQ_2__",
"_type": "request",
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Urlencoded Form Test",
"description": "First Request",
Expand Down Expand Up @@ -85,6 +87,7 @@
"_id": "__REQ_3__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Test Request Raw Body",
"description": "Request with raw body",
Expand All @@ -101,6 +104,7 @@
"_id": "__REQ_4__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Test Request Empty Raw Body",
"description": "Request with empty raw body",
Expand All @@ -114,6 +118,7 @@
"_id": "__REQ_5__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Test Request Unknown Body",
"description": "Request with unknown body",
Expand All @@ -127,6 +132,7 @@
"_id": "__REQ_6__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/graphql/",
"name": "Test Request GraphQL Body",
"description": "Request with graphql body",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,7 @@
}
],
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": ""
},
{
Expand Down Expand Up @@ -102,6 +103,7 @@
}
],
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": ""
},
{
Expand Down Expand Up @@ -132,6 +134,7 @@
"name": "Create a new project.",
"parameters": [],
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": ""
},
{
Expand Down Expand Up @@ -162,6 +165,7 @@
"name": "Display the specified project.",
"parameters": [],
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": ""
},
{
Expand Down Expand Up @@ -202,6 +206,7 @@
"name": "Update the specified project.",
"parameters": [],
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": ""
}
]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,6 +24,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "{{base_url}}/api/users",
"description": "First Request",
Expand Down Expand Up @@ -64,6 +65,7 @@
"_id": "__REQ_2__",
"_type": "request",
"parentId": "__GRP_2__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Urlencoded Form Test",
"description": "First Request",
Expand Down Expand Up @@ -91,6 +93,7 @@
"_id": "__REQ_3__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Test Request",
"description": "Request with raw body",
Expand All @@ -107,6 +110,7 @@
"_id": "__REQ_4__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Test Request Unknown Body",
"description": "Request with unknown body",
Expand All @@ -120,6 +124,7 @@
"_id": "__REQ_5__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/api/users",
"name": "Test Request Empty Body",
"description": "Request with empty raw body",
Expand All @@ -133,6 +138,7 @@
"_id": "__REQ_6__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "{{base_url}}/graphql/",
"name": "Test Request GraphQL Body",
"description": "Request with graphql body",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://jigsaw.w3.org/HTTP/Digest/",
"name": "Digest Auth",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://jigsaw.w3.org/HTTP/Digest/",
"name": "Digest Auth",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "",
"name": "",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "",
"name": "",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Added to Request Body/URL",
"description": "",
Expand Down Expand Up @@ -44,6 +45,7 @@
"_id": "__REQ_2__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Added to Request Headers",
"description": "",
Expand Down Expand Up @@ -72,6 +74,7 @@
"_id": "__REQ_3__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Signature Method PLAINTEXT",
"description": "",
Expand Down Expand Up @@ -100,6 +103,7 @@
"_id": "__REQ_4__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Signature Method HMAC-SHA256",
"description": "",
Expand Down Expand Up @@ -128,6 +132,7 @@
"_id": "__REQ_5__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Signature Method HMAC-SHA1",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Added to Request Body/URL",
"description": "",
Expand Down Expand Up @@ -44,6 +45,7 @@
"_id": "__REQ_2__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Added to Request Headers",
"description": "",
Expand Down Expand Up @@ -72,6 +74,7 @@
"_id": "__REQ_3__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Signature Method PLAINTEXT",
"description": "",
Expand Down Expand Up @@ -100,6 +103,7 @@
"_id": "__REQ_4__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Signature Method HMAC-SHA256",
"description": "",
Expand Down Expand Up @@ -128,6 +132,7 @@
"_id": "__REQ_5__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Signature Method HMAC-SHA1",
"description": "",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
"_id": "__REQ_1__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Added to Request URL",
"description": "",
Expand All @@ -37,6 +38,7 @@
"_id": "__REQ_2__",
"_type": "request",
"parentId": "__GRP_1__",
"preRequestScript": "",
"url": "https://insomnia.rest",
"name": "Added to Request Headers",
"description": "",
Expand Down
Loading

0 comments on commit 24b096b

Please sign in to comment.