fix/collection-search-validations unit-tests-fix (#2833)

* fix: updates

* fix: update test title

* fix: removed console
This commit is contained in:
lohit 2024-08-14 13:23:00 +05:30 committed by GitHub
parent 22c096507d
commit eceb114d6c
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
4 changed files with 27 additions and 4 deletions

View File

@ -3,7 +3,7 @@ import filter from 'lodash/filter';
import find from 'lodash/find';
export const doesRequestMatchSearchText = (request, searchText = '') => {
return request.name.toLowerCase().includes(searchText.toLowerCase());
return request?.name?.toLowerCase().includes(searchText.toLowerCase());
};
export const doesFolderHaveItemsMatchSearchText = (item, searchText = '') => {

View File

@ -123,7 +123,8 @@ const curlToJson = (curlCommand) => {
request.urlWithoutQuery = 'http://' + request.urlWithoutQuery;
}
requestJson.url = request.urlWithoutQuery
requestJson.url = request.urlWithoutQuery;
requestJson.raw_url = request.url;
requestJson.method = request.method;
if (request.cookies) {

View File

@ -75,4 +75,15 @@ describe('curlToJson', () => {
}
});
});
it('should return and parse a simple curl command with a trailing slash', () => {
const curlCommand = 'curl https://www.usebruno.com/';
const result = curlToJson(curlCommand);
expect(result).toEqual({
url: 'https://www.usebruno.com/',
raw_url: 'https://www.usebruno.com/',
method: 'get'
});
});
});

View File

@ -187,10 +187,21 @@ const parseCurlCommand = (curlCommand) => {
}
urlObject.search = null; // Clean out the search/query portion.
let urlWithoutQuery = URL.format(urlObject);
let urlHost = urlObject?.host;
if (!url?.includes(`${urlHost}/`)) {
if (urlWithoutQuery && urlHost) {
const [beforeHost, afterHost] = urlWithoutQuery.split(urlHost);
urlWithoutQuery = beforeHost + urlHost + afterHost?.slice(1);
}
}
const request = {
url: url,
urlWithoutQuery: URL.format(urlObject)
url,
urlWithoutQuery
};
if (compressed) {
request.compressed = true;
}