fix: params test (#2395)

This commit is contained in:
lohit
2024-05-31 15:55:23 +05:30
committed by GitHub
parent 46df2e967f
commit b63ae360fe
4 changed files with 125 additions and 96 deletions

View File

@@ -5,55 +5,7 @@ import StyledWrapper from './StyledWrapper';
import { isValidUrl } from 'utils/url';
import { find, get } from 'lodash';
import { findEnvironmentInCollection } from 'utils/collections';
// Todo: Fix this
// import { interpolate } from '@usebruno/common';
import brunoCommon from '@usebruno/common';
const { interpolate } = brunoCommon;
const interpolateUrl = ({ url, envVars, collectionVariables, processEnvVars }) => {
if (!url || !url.length || typeof url !== 'string') {
return;
}
return interpolate(url, {
...envVars,
...collectionVariables,
process: {
env: {
...processEnvVars
}
}
});
};
// interpolate URL paths
const interpolateUrlPathParams = (url, params) => {
const getInterpolatedBasePath = (pathname, params) => {
return pathname
.split('/')
.map((segment) => {
if (segment.startsWith(':')) {
const pathParamName = segment.slice(1);
const pathParam = params.find((p) => p?.name === pathParamName && p?.type === 'path');
return pathParam ? pathParam.value : segment;
}
return segment;
})
.join('/');
};
let uri;
try {
uri = new URL(url);
} catch (error) {
uri = new URL(`http://${url}`);
}
const basePath = getInterpolatedBasePath(uri.pathname, params);
return `${uri.origin}${basePath}${uri?.search || ''}`;
};
import { interpolateUrl, interpolateUrlPathParams } from 'utils/url/index';
const languages = [
{
@@ -117,7 +69,7 @@ const GenerateCodeItem = ({ collection, item, onClose }) => {
const requestUrl =
get(item, 'draft.request.url') !== undefined ? get(item, 'draft.request.url') : get(item, 'request.url');
// interpolate the query params
// interpolate the url
const interpolatedUrl = interpolateUrl({
url: requestUrl,
envVars,