chore: pr #632 polish

This commit is contained in:
Anoop M D 2023-10-18 10:54:51 +05:30
parent d5a72b1a5d
commit b6da0b2113
2 changed files with 19 additions and 13 deletions

View File

@ -17,7 +17,7 @@ const interpolateEnvVars = (str, processEnvVars) => {
});
};
const interpolateString = (str, { envVars, collectionVariables, processEnvVars }) => {
const interpolateString = (str, { envVariables, collectionVariables, processEnvVars }) => {
if (!str || !str.length || typeof str !== 'string') {
return str;
}
@ -25,20 +25,20 @@ const interpolateString = (str, { envVars, collectionVariables, processEnvVars }
processEnvVars = processEnvVars || {};
collectionVariables = collectionVariables || {};
// we clone envVars because we don't want to modify the original object
envVars = envVars ? cloneDeep(envVars) : {};
// we clone envVariables because we don't want to modify the original object
envVariables = envVariables ? cloneDeep(envVariables) : {};
// envVars can inturn have values as {{process.env.VAR_NAME}}
// so we need to interpolate envVars first with processEnvVars
forOwn(envVars, (value, key) => {
envVars[key] = interpolateEnvVars(value, processEnvVars);
// envVariables can inturn have values as {{process.env.VAR_NAME}}
// so we need to interpolate envVariables first with processEnvVars
forOwn(envVariables, (value, key) => {
envVariables[key] = interpolateEnvVars(value, processEnvVars);
});
const template = Handlebars.compile(str, { noEscape: true });
// collectionVariables take precedence over envVars
// collectionVariables take precedence over envVariables
const combinedVars = {
...envVars,
...envVariables,
...collectionVariables,
process: {
env: {

View File

@ -162,6 +162,12 @@ const evaluateRhsOperand = (rhsOperand, operator, context) => {
return;
}
const interpolationContext = {
collectionVariables: context.bru.collectionVariables,
envVariables: context.bru.envVariables,
processEnvVars: context.bu.processEnvVars
};
// gracefully allow both a,b as well as [a, b]
if (operator === 'in' || operator === 'notIn') {
if (rhsOperand.startsWith('[') && rhsOperand.endsWith(']')) {
@ -170,13 +176,13 @@ const evaluateRhsOperand = (rhsOperand, operator, context) => {
return rhsOperand
.split(',')
.map((v) => evaluateJsTemplateLiteral(interpolateString(v.trim(), context.bru), context));
.map((v) => evaluateJsTemplateLiteral(interpolateString(v.trim(), interpolationContext), context));
}
if (operator === 'between') {
const [lhs, rhs] = rhsOperand
.split(',')
.map((v) => evaluateJsTemplateLiteral(interpolateString(v.trim(), context.bru), context));
.map((v) => evaluateJsTemplateLiteral(interpolateString(v.trim(), interpolationContext), context));
return [lhs, rhs];
}
@ -186,10 +192,10 @@ const evaluateRhsOperand = (rhsOperand, operator, context) => {
rhsOperand = rhsOperand.substring(1, rhsOperand.length - 1);
}
return interpolateString(rhsOperand, context.bru);
return interpolateString(rhsOperand, interpolationContext);
}
return evaluateJsTemplateLiteral(interpolateString(rhsOperand, context.bru), context);
return evaluateJsTemplateLiteral(interpolateString(rhsOperand, interpolationContext), context);
};
class AssertRuntime {