From f360660ac3631540b217148c4fc2f37e840ca477 Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Wed, 18 Dec 2024 20:57:48 +0530 Subject: [PATCH 1/2] chore: optimise helpers extracting and processing ENV vars in config --- src/helpers/helper.js | 11 ++--------- test/config.spec.js | 29 +++++++++++++++++++++++++++++ 2 files changed, 31 insertions(+), 9 deletions(-) diff --git a/src/helpers/helper.js b/src/helpers/helper.js index b632841..1d32438 100644 --- a/src/helpers/helper.js +++ b/src/helpers/helper.js @@ -14,18 +14,11 @@ function getPercentage(x, y) { function processText(raw) { const dataRefMatches = raw.match(DATA_REF_PATTERN); if (dataRefMatches) { - const values = []; for (let i = 0; i < dataRefMatches.length; i++) { const dataRefMatch = dataRefMatches[i]; const content = dataRefMatch.slice(1, -1); - if (process.env[content]) { - values.push(process.env[content]); - } else { - values.push(content); - } - } - for (let i = 0; i < dataRefMatches.length; i++) { - raw = raw.replace(dataRefMatches[i], values[i]); + const envValue = process.env[content] || content; + raw = raw.replace(dataRefMatches[i], envValue); } } return raw; diff --git a/test/config.spec.js b/test/config.spec.js index 192cfcd..8ed25e4 100644 --- a/test/config.spec.js +++ b/test/config.spec.js @@ -1,8 +1,37 @@ const assert = require('assert'); +const { mock } = require('pactum'); const { publish } = require("../src"); describe('Config', () => { + it('should allow valid config with ENV vars - successful', async () => { + const id = mock.addInteraction('post test-summary to teams'); + process.env.TEST_URL='http://localhost:9393/message' + await publish({ + config: { + "targets": [ + { + "name": "teams", + "condition": "result.status === 'PASS'", + "inputs": { + "url": "{TEST_URL}" + } + } + ], + "results": [ + { + "type": "testng", + "files": [ + "test/data/testng/single-suite.xml" + ] + } + ] + } + }); + process.env.TEST_URL='' + assert.equal(mock.getInteraction(id).exercised, true); + }); + it('should not allow missing options', async () => { let e; try { From 4478d56ccd0ea0ca4e230085e85bd205506af006 Mon Sep 17 00:00:00 2001 From: Leela Prasad <47483946+leelaprasadv@users.noreply.github.com> Date: Thu, 19 Dec 2024 13:50:32 +0530 Subject: [PATCH 2/2] minor update for review suggestion Co-authored-by: Anudeep --- src/helpers/helper.js | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/helpers/helper.js b/src/helpers/helper.js index 1d32438..3b8bcfc 100644 --- a/src/helpers/helper.js +++ b/src/helpers/helper.js @@ -18,7 +18,7 @@ function processText(raw) { const dataRefMatch = dataRefMatches[i]; const content = dataRefMatch.slice(1, -1); const envValue = process.env[content] || content; - raw = raw.replace(dataRefMatches[i], envValue); + raw = raw.replace(dataRefMatch, envValue); } } return raw;