Skip to content

Commit

Permalink
fix tests
Browse files Browse the repository at this point in the history
  • Loading branch information
jackkav committed Jun 21, 2024
1 parent 6b7f12a commit 3360320
Show file tree
Hide file tree
Showing 3 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -5845,15 +5845,15 @@ exports[`Fixtures Import postman scripts-import-v2_1-input.json 1`] = `
"description": "",
"environment": {
"bob": "something",
"dssx": "{{env_var_in_global}}",
"dssx": "{{_['env-var-in-global']}}",
},
"metaSortKey": -1622117984000,
"name": "New Collection",
"parentId": "__WORKSPACE_ID__",
"preRequestScript": "console.log('pre')",
"variable": {
"bob": "something",
"dssx": "{{env_var_in_global}}",
"dssx": "{{_['env-var-in-global']}}",
},
},
{
Expand Down Expand Up @@ -5907,7 +5907,7 @@ exports[`Fixtures Import postman-env no-name-input.json 1`] = `
"_id": "__ENV_1__",
"_type": "environment",
"data": {
"foo_and_bar": "production-env",
"foo-and-bar": "production-env",
},
"name": "Postman Environment",
"parentId": "__BASE_ENVIRONMENT_ID__",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ describe('postman', () => {
});
it('should transform hyphens to underscores', () => {
const input = 'abc{{my-env-var}}def{{here-and-here}}ghi';
const output = 'abc{{my_env_var}}def{{here_and_here}}ghi';
const output = "abc{{_['my-env-var']}}def{{_['here-and-here']}}ghi";
expect(transformPostmanToNunjucksString(input)).toEqual(output);
expect(transformPostmanToNunjucksString()).toEqual('');
});
Expand Down
11 changes: 7 additions & 4 deletions packages/insomnia/src/utils/importers/importers/postman.ts
Original file line number Diff line number Diff line change
Expand Up @@ -65,10 +65,10 @@ export const transformPostmanToNunjucksString = (inputString?: string | null) =>
if (typeof inputString !== 'string') {
return inputString;
}
const sanitizedString = normaliseJsonPath(inputString);
return postmanTagRegexs.reduce((transformedString, { tag, regex }) => {
const replaceFaker = postmanTagRegexs.reduce((transformedString, { tag, regex }) => {
return transformedString.replace(regex, postmanToNunjucksLookup[tag]);
}, sanitizedString);
}, inputString);
return normaliseJsonPath(replaceFaker);
};

// old: {{ arr-name-with-dash }}
Expand All @@ -77,8 +77,11 @@ export const normaliseJsonPath = (input?: string) => {
if (!input) {
return '';
}
if (!input.includes('-')) {
return input;
}
// Use a regular expression to find and replace the pattern
return input.replace(/\{\{([^\}]+)\}\}/g, (_, match) => {
return input.replace(/{{\s*([^ }]+)\s*[^}]*\s*}}/g, (_, match) => {
// Replace hyphens with underscores within the match
const replaced = forceBracketNotation('_', match);
// Return the replaced pattern within the curly braces
Expand Down

0 comments on commit 3360320

Please sign in to comment.