Skip to content

Commit 37aa459

Browse files
committed
chore: move test url to env var
1 parent 4bd0d86 commit 37aa459

File tree

4 files changed

+38
-34
lines changed

4 files changed

+38
-34
lines changed

.github/workflows/pr.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -93,6 +93,8 @@ jobs:
9393
env:
9494
TRUSTIFY_DA_PYTHON3_PATH: "${{steps.python-location.outputs.python-bin-location}}/python3"
9595
TRUSTIFY_DA_PIP3_PATH: "${{steps.python-location.outputs.python-bin-location}}/pip3"
96+
TRUSTIFY_DA_DEV_MODE: 'true'
97+
DEV_TRUSTIFY_DA_BACKEND_URL: 'https://exhort.stage.devshift.net'
9698
run: npm run test
9799

98100
- name: Compile project

.github/workflows/stage.yml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -120,6 +120,8 @@ jobs:
120120
if: steps.test-check.outputs.retest-is-needed == 'true'
121121
env:
122122
TRIGGERING_FILE: ${{ steps.test-check.outputs.triggering-file}}
123+
TRUSTIFY_DA_DEV_MODE: 'true'
124+
DEV_TRUSTIFY_DA_BACKEND_URL: 'https://exhort.stage.devshift.net'
123125
run: |
124126
echo "Re-test was triggered!!, triggering changed file - $TRIGGERING_FILE"
125127
echo "Running Again Unit-tests =>"

src/index.js

Lines changed: 2 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -84,8 +84,6 @@ function readAndPrintVersionFromPackageJson() {
8484
logOptionsAndEnvironmentsVariables("trustify-da-javascript-client analysis started, version: ", packageJson.version)
8585
}
8686

87-
export const exhortDevUrl = 'https://exhort.stage.devshift.net';
88-
8987
/**
9088
* This function is used to determine exhort theUrl backend according to the following logic:
9189
* If TRUSTIFY_DA_DEV_MODE = true, then take the value of the EXHORT BACKEND URL of dev/staging environment in such a way:
@@ -99,14 +97,14 @@ export const exhortDevUrl = 'https://exhort.stage.devshift.net';
9997
* @return {string} - The selected exhort backend
10098
* @private
10199
*/
102-
function selectExhortBackend(opts = {}) {
100+
export function selectExhortBackend(opts = {}) {
103101
if (getCustom("TRUSTIFY_DA_DEBUG", "false", opts) === "true") {
104102
readAndPrintVersionFromPackageJson();
105103
}
106104

107105
let url;
108106
if (getCustom('TRUSTIFY_DA_DEV_MODE', 'false', opts) === 'true') {
109-
url = getCustom('DEV_TRUSTIFY_DA_BACKEND_URL', exhortDevUrl, opts);
107+
url = getCustom('DEV_TRUSTIFY_DA_BACKEND_URL', undefined, opts);
110108
} else {
111109
url = getCustom('TRUSTIFY_DA_BACKEND_URL', undefined, opts);
112110
}
@@ -120,16 +118,6 @@ function selectExhortBackend(opts = {}) {
120118
return url;
121119
}
122120

123-
/**
124-
* Test function for selecting the Exhort backend URL.
125-
* Primarily used for testing the backend selection logic.
126-
* @param {object} [opts={}] - Optional configuration, similar to `selectExhortBackend`.
127-
* @return {string} The selected exhort backend URL.
128-
*/
129-
export function testSelectExhortBackend(opts) {
130-
return selectExhortBackend(opts)
131-
}
132-
133121
/**
134122
* @overload
135123
* @param {string} manifest

test/get-exhort-url.test.js

Lines changed: 32 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,40 +1,45 @@
11
import { expect } from 'chai'
22

3-
import { exhortDevUrl, testSelectExhortBackend } from '../src/index.js'
3+
import { selectExhortBackend } from '../src/index.js'
44

55
const testProdUrl = 'https://exhort.example.com';
6+
const testDevUrl = 'https://dev.exhort.example.com';
67

78
suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environment variable is True', () => {
89

910
test('When Dev Mode environment Variable= true, default DEV Exhort Backend Selected', () => {
1011
let testOpts = {
1112
'TRUSTIFY_DA_DEV_MODE': 'true'
1213
}
13-
let selectedUrl = testSelectExhortBackend(testOpts);
14+
let selectedUrl = selectExhortBackend(testOpts);
1415
expect(selectedUrl).not.to.be.equals(testProdUrl)
15-
expect(selectedUrl).to.be.equals(exhortDevUrl)
16+
expect(selectedUrl).to.be.equals(testDevUrl)
1617
});
1718

1819
test('When Dev Mode environment Variable= true, and despite option Dev Mode = false, default DEV Exhort Backend Selected', () => {
1920
let testOpts = {
2021
'TRUSTIFY_DA_DEV_MODE': 'false'
2122
}
22-
let selectedUrl = testSelectExhortBackend(testOpts);
23+
let selectedUrl = selectExhortBackend(testOpts);
2324
expect(selectedUrl).not.to.be.equals(testProdUrl)
24-
expect(selectedUrl).to.be.equals(exhortDevUrl)
25+
expect(selectedUrl).to.be.equals(testDevUrl)
2526
});
2627

2728
test('When Dev Mode environment Variable= true, And option DEV_TRUSTIFY_DA_BACKEND_URL contains some url route that client set, default DEV Exhort Backend Not Selected', () => {
2829
const dummyRoute = 'http://dummy-exhort-route';
30+
delete process.env['DEV_TRUSTIFY_DA_BACKEND_URL']
2931
let testOpts = {
3032
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
3133
}
32-
let selectedUrl = testSelectExhortBackend(testOpts);
33-
expect(selectedUrl).not.to.be.equals(exhortDevUrl)
34+
let selectedUrl = selectExhortBackend(testOpts);
3435
expect(selectedUrl).to.be.equals(dummyRoute)
3536
});
3637

37-
}).beforeAll(() => { process.env['TRUSTIFY_DA_DEV_MODE'] = 'true'; process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl }).afterAll(() => delete process.env['TRUSTIFY_DA_DEV_MODE']);
38+
}).beforeAll(() => {
39+
process.env['TRUSTIFY_DA_DEV_MODE'] = 'true'
40+
process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl
41+
process.env['DEV_TRUSTIFY_DA_BACKEND_URL'] = testDevUrl
42+
}).afterAll(() => delete process.env['TRUSTIFY_DA_DEV_MODE']);
3843

3944
suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environment variable is false', () => {
4045

@@ -43,8 +48,8 @@ suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environm
4348
let testOpts = {
4449
'TRUSTIFY_DA_DEV_MODE': 'false'
4550
}
46-
let selectedUrl = testSelectExhortBackend(testOpts);
47-
expect(selectedUrl).not.to.be.equals(exhortDevUrl)
51+
let selectedUrl = selectExhortBackend(testOpts);
52+
expect(selectedUrl).not.to.be.equals(testDevUrl)
4853
expect(selectedUrl).to.be.equals(testProdUrl)
4954
});
5055

@@ -54,7 +59,7 @@ suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environm
5459
'TRUSTIFY_DA_DEV_MODE': 'true',
5560
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
5661
}
57-
let selectedUrl = testSelectExhortBackend(testOpts);
62+
let selectedUrl = selectExhortBackend(testOpts);
5863
expect(selectedUrl).not.to.be.equals(dummyRoute)
5964
expect(selectedUrl).to.be.equals(testProdUrl)
6065
});
@@ -66,13 +71,17 @@ suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environm
6671
'TRUSTIFY_DA_DEV_MODE': 'true',
6772
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
6873
}
69-
let selectedUrl = testSelectExhortBackend(testOpts);
74+
let selectedUrl = selectExhortBackend(testOpts);
7075
delete process.env['DEV_TRUSTIFY_DA_BACKEND_URL']
7176
expect(selectedUrl).not.to.be.equals(dummyRoute)
7277
expect(selectedUrl).to.be.equals(testProdUrl)
7378
});
7479

75-
}).beforeAll(() => { process.env['TRUSTIFY_DA_DEV_MODE'] = 'false'; process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl }).afterAll(() => delete process.env['TRUSTIFY_DA_DEV_MODE']);
80+
}).beforeAll(() => {
81+
process.env['TRUSTIFY_DA_DEV_MODE'] = 'false'
82+
process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl
83+
process.env['DEV_TRUSTIFY_DA_BACKEND_URL'] = testDevUrl
84+
}).afterAll(() => delete process.env['TRUSTIFY_DA_DEV_MODE']);
7685

7786
suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environment variable is not set', () => {
7887

@@ -81,18 +90,18 @@ suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environm
8190
let testOpts = {
8291
'TRUSTIFY_DA_DEV_MODE': 'false'
8392
}
84-
let selectedUrl = testSelectExhortBackend(testOpts);
85-
expect(selectedUrl).not.to.be.equals(exhortDevUrl)
93+
let selectedUrl = selectExhortBackend(testOpts);
94+
expect(selectedUrl).not.to.be.equals(testDevUrl)
8695
expect(selectedUrl).to.be.equals(testProdUrl)
8796
});
8897

8998
test('When Dev Mode Option Variable= true, default dev Exhort Backend Selected', () => {
9099
let testOpts = {
91100
'TRUSTIFY_DA_DEV_MODE': 'true'
92101
}
93-
let selectedUrl = testSelectExhortBackend(testOpts);
102+
let selectedUrl = selectExhortBackend(testOpts);
94103
expect(selectedUrl).not.to.be.equals(testProdUrl)
95-
expect(selectedUrl).to.be.equals(exhortDevUrl)
104+
expect(selectedUrl).to.be.equals(testDevUrl)
96105
});
97106

98107
test('When Dev Mode option = true, option DEV_TRUSTIFY_DA_BACKEND_URL=some dummy-url, then some dummy-url Selected', () => {
@@ -102,14 +111,17 @@ suite('testing Select Exhort Backend function when TRUSTIFY_DA_DEV_MODE environm
102111
'TRUSTIFY_DA_DEV_MODE': 'true',
103112
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
104113
}
105-
let selectedUrl = testSelectExhortBackend(testOpts);
114+
let selectedUrl = selectExhortBackend(testOpts);
106115
expect(selectedUrl).not.to.be.equals(testProdUrl)
107116
expect(selectedUrl).to.be.equals(dummyRoute)
108117
delete process.env['DEV_TRUSTIFY_DA_BACKEND_URL']
109118
});
110119

111120
test('When Nothing set, throw error', () => {
112-
let selectedUrl = testSelectExhortBackend({});
121+
let selectedUrl = selectExhortBackend({});
113122
expect(selectedUrl).to.be.equals(testProdUrl)
114123
})
115-
}).beforeAll(() => process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl);
124+
}).beforeAll(() => {
125+
process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl;
126+
process.env['DEV_TRUSTIFY_DA_BACKEND_URL'] = testDevUrl
127+
});

0 commit comments

Comments
 (0)