Skip to content

Commit 20d934a

Browse files
authored
Merge pull request #596 from KKSurendran06/feat/env-var-text-body
Feat/env var text body
2 parents f33ff02 + 0ef5a80 commit 20d934a

File tree

2 files changed

+45
-1
lines changed

2 files changed

+45
-1
lines changed

lib/utils/envvar_utils.dart

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -86,6 +86,11 @@ HttpRequestModel substituteHttpRequestModel(
8686
value: substituteVariables(param.value, envMap, activeEnvironmentId),
8787
);
8888
}).toList(),
89+
body: substituteVariables(
90+
httpRequestModel.body,
91+
envMap,
92+
activeEnvironmentId,
93+
),
8994
);
9095
return newRequestModel;
9196
}

test/utils/envvar_utils_test.dart

Lines changed: 40 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -211,10 +211,12 @@ void main() {
211211
NameValueModel(name: "num", value: "{{num}}"),
212212
],
213213
);
214+
214215
Map<String?, List<EnvironmentVariableModel>> envMap = {
215216
kGlobalEnvironmentId: globalVars,
216217
"activeEnvId": activeEnvVars,
217218
};
219+
218220
String? activeEnvironmentId = "activeEnvId";
219221
const expected = HttpRequestModel(
220222
url: "api.apidash.dev/humanize/social",
@@ -227,7 +229,10 @@ void main() {
227229
);
228230
expect(
229231
substituteHttpRequestModel(
230-
httpRequestModel, envMap, activeEnvironmentId),
232+
httpRequestModel,
233+
envMap,
234+
activeEnvironmentId,
235+
),
231236
expected);
232237
});
233238

@@ -260,6 +265,40 @@ void main() {
260265
httpRequestModel, envMap, activeEnvironmentId),
261266
expected);
262267
});
268+
269+
test(
270+
"Testing substituteHttpRequestModel with environment variables in body",
271+
() {
272+
const httpRequestModel = HttpRequestModel(
273+
url: "{{url}}/humanize/social",
274+
headers: [
275+
NameValueModel(name: "Authorization", value: "Bearer {{token}}"),
276+
],
277+
params: [
278+
NameValueModel(name: "num", value: "{{num}}"),
279+
],
280+
body: "The API key is {{token}} and the number is {{num}}",
281+
);
282+
Map<String?, List<EnvironmentVariableModel>> envMap = {
283+
kGlobalEnvironmentId: globalVars,
284+
"activeEnvId": activeEnvVars,
285+
};
286+
String? activeEnvironmentId = "activeEnvId";
287+
const expected = HttpRequestModel(
288+
url: "api.apidash.dev/humanize/social",
289+
headers: [
290+
NameValueModel(name: "Authorization", value: "Bearer token"),
291+
],
292+
params: [
293+
NameValueModel(name: "num", value: "8940000"),
294+
],
295+
body: "The API key is token and the number is 8940000",
296+
);
297+
expect(
298+
substituteHttpRequestModel(
299+
httpRequestModel, envMap, activeEnvironmentId),
300+
expected);
301+
});
263302
});
264303

265304
group("Testing getEnvironmentTriggerSuggestions function", () {

0 commit comments

Comments
 (0)