Skip to content

Commit b04c123

Browse files
committed
feat: update tests
Signed-off-by: Ruben Romero Montes <rromerom@redhat.com>
1 parent 51a12ca commit b04c123

File tree

1 file changed

+38
-100
lines changed

1 file changed

+38
-100
lines changed

test/get-exhort-url.test.js

Lines changed: 38 additions & 100 deletions
Original file line numberDiff line numberDiff line change
@@ -2,126 +2,64 @@ import { expect } from 'chai'
22

33
import { selectTrustifyDABackend } from '../src/index.js'
44

5-
const testProdUrl = 'https://trustify-da.example.com';
6-
const testDevUrl = 'https://dev.trustify-da.example.com';
5+
const testUrl = 'https://trustify-da.example.com';
6+
const testUrl2 = 'https://dev.trustify-da.example.com';
77

8-
suite('testing Select Trustify DA Backend function when TRUSTIFY_DA_DEV_MODE environment variable is True', () => {
8+
suite('testing Select Trustify DA Backend function', () => {
99

10-
test('When Dev Mode environment Variable= true, default DEV Trustify DA Backend Selected', () => {
11-
let testOpts = {
12-
'TRUSTIFY_DA_DEV_MODE': 'true'
13-
}
14-
let selectedUrl = selectTrustifyDABackend(testOpts);
15-
expect(selectedUrl).not.to.be.equals(testProdUrl)
16-
expect(selectedUrl).to.be.equals(testDevUrl)
17-
});
18-
19-
test('When Dev Mode environment Variable= true, and despite option Dev Mode = false, default DEV Trustify DA Backend Selected', () => {
20-
let testOpts = {
21-
'TRUSTIFY_DA_DEV_MODE': 'false'
22-
}
23-
let selectedUrl = selectTrustifyDABackend(testOpts);
24-
expect(selectedUrl).not.to.be.equals(testProdUrl)
25-
expect(selectedUrl).to.be.equals(testDevUrl)
26-
});
27-
28-
test('When Dev Mode environment Variable= true, And option DEV_TRUSTIFY_DA_BACKEND_URL contains some url route that client set, default DEV Trustify DA Backend Not Selected', () => {
29-
const dummyRoute = 'http://dummy-trustify-da-route';
30-
delete process.env['DEV_TRUSTIFY_DA_BACKEND_URL']
31-
let testOpts = {
32-
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
33-
}
34-
let selectedUrl = selectTrustifyDABackend(testOpts);
35-
expect(selectedUrl).to.be.equals(dummyRoute)
10+
test('When TRUSTIFY_DA_BACKEND_URL is set in environment variable, should return that value', () => {
11+
process.env['TRUSTIFY_DA_BACKEND_URL'] = testUrl;
12+
let selectedUrl = selectTrustifyDABackend({});
13+
expect(selectedUrl).to.be.equals(testUrl);
14+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
3615
});
3716

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']);
43-
44-
suite('testing Select Trustify DA Backend function when TRUSTIFY_DA_DEV_MODE environment variable is false', () => {
45-
46-
test('When Dev Mode environment Variable= true, default DEV Trustify DA Backend Selected', () => {
47-
17+
test('When TRUSTIFY_DA_BACKEND_URL is set in opts (but not in env), should return that value', () => {
18+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
4819
let testOpts = {
49-
'TRUSTIFY_DA_DEV_MODE': 'false'
50-
}
20+
'TRUSTIFY_DA_BACKEND_URL': testUrl
21+
};
5122
let selectedUrl = selectTrustifyDABackend(testOpts);
52-
expect(selectedUrl).not.to.be.equals(testDevUrl)
53-
expect(selectedUrl).to.be.equals(testProdUrl)
23+
expect(selectedUrl).to.be.equals(testUrl);
5424
});
5525

56-
test('When Dev Mode environment Variable= false, and despite option Dev Mode = true, default Trustify DA Backend Selected (production)', () => {
57-
let dummyRoute = 'http://dummy-dev-route-trustify-da'
26+
test('When TRUSTIFY_DA_BACKEND_URL is set in both environment and opts, environment variable should take precedence', () => {
27+
process.env['TRUSTIFY_DA_BACKEND_URL'] = testUrl;
5828
let testOpts = {
59-
'TRUSTIFY_DA_DEV_MODE': 'true',
60-
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
61-
}
29+
'TRUSTIFY_DA_BACKEND_URL': testUrl2
30+
};
6231
let selectedUrl = selectTrustifyDABackend(testOpts);
63-
expect(selectedUrl).not.to.be.equals(dummyRoute)
64-
expect(selectedUrl).to.be.equals(testProdUrl)
32+
expect(selectedUrl).to.be.equals(testUrl);
33+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
6534
});
6635

67-
test('When Dev Mode environment Variable= false, environment variable DEV_TRUSTIFY_DA_BACKEND_URL=dummy-url, option TRUSTIFY_DA_DEV_MODE=true, default Trustify DA Backend Selected anyway', () => {
68-
const dummyRoute = 'http://dummy-url'
69-
process.env['DEV_TRUSTIFY_DA_BACKEND_URL'] = dummyRoute
70-
let testOpts = {
71-
'TRUSTIFY_DA_DEV_MODE': 'true',
72-
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
73-
}
74-
let selectedUrl = selectTrustifyDABackend(testOpts);
75-
delete process.env['DEV_TRUSTIFY_DA_BACKEND_URL']
76-
expect(selectedUrl).not.to.be.equals(dummyRoute)
77-
expect(selectedUrl).to.be.equals(testProdUrl)
36+
test('When TRUSTIFY_DA_BACKEND_URL is not set, should throw error', () => {
37+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
38+
expect(() => selectTrustifyDABackend({})).to.throw('TRUSTIFY_DA_BACKEND_URL is unset');
7839
});
7940

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']);
85-
86-
suite('testing Select Trustify DA Backend function when TRUSTIFY_DA_DEV_MODE environment variable is not set', () => {
87-
88-
test('When Dev Mode Option = false, default Trustify DA Backend Selected (production)', () => {
89-
90-
let testOpts = {
91-
'TRUSTIFY_DA_DEV_MODE': 'false'
92-
}
93-
let selectedUrl = selectTrustifyDABackend(testOpts);
94-
expect(selectedUrl).not.to.be.equals(testDevUrl)
95-
expect(selectedUrl).to.be.equals(testProdUrl)
41+
test('When TRUSTIFY_DA_BACKEND_URL is empty string in environment, should throw error', () => {
42+
process.env['TRUSTIFY_DA_BACKEND_URL'] = '';
43+
expect(() => selectTrustifyDABackend({})).to.throw('TRUSTIFY_DA_BACKEND_URL is unset');
44+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
9645
});
9746

98-
test('When Dev Mode Option Variable= true, default dev Trustify DA Backend Selected', () => {
47+
test('When TRUSTIFY_DA_BACKEND_URL is empty string in opts, should throw error', () => {
48+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
9949
let testOpts = {
100-
'TRUSTIFY_DA_DEV_MODE': 'true'
101-
}
102-
let selectedUrl = selectTrustifyDABackend(testOpts);
103-
expect(selectedUrl).not.to.be.equals(testProdUrl)
104-
expect(selectedUrl).to.be.equals(testDevUrl)
50+
'TRUSTIFY_DA_BACKEND_URL': ''
51+
};
52+
expect(() => selectTrustifyDABackend(testOpts)).to.throw('TRUSTIFY_DA_BACKEND_URL is unset');
10553
});
10654

107-
test('When Dev Mode option = true, option DEV_TRUSTIFY_DA_BACKEND_URL=some dummy-url, then some dummy-url Trustify DA Backend Selected', () => {
108-
let dummyRoute = 'http://dummy-dev-route-trustify-da'
109-
process.env['DEV_TRUSTIFY_DA_BACKEND_URL'] = dummyRoute
55+
test('When TRUSTIFY_DA_BACKEND_URL is null in opts, should throw error', () => {
56+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
11057
let testOpts = {
111-
'TRUSTIFY_DA_DEV_MODE': 'true',
112-
'DEV_TRUSTIFY_DA_BACKEND_URL': dummyRoute
113-
}
114-
let selectedUrl = selectTrustifyDABackend(testOpts);
115-
expect(selectedUrl).not.to.be.equals(testProdUrl)
116-
expect(selectedUrl).to.be.equals(dummyRoute)
117-
delete process.env['DEV_TRUSTIFY_DA_BACKEND_URL']
58+
'TRUSTIFY_DA_BACKEND_URL': null
59+
};
60+
expect(() => selectTrustifyDABackend(testOpts)).to.throw('TRUSTIFY_DA_BACKEND_URL is unset');
11861
});
11962

120-
test('When Nothing set, throw error', () => {
121-
let selectedUrl = selectTrustifyDABackend({});
122-
expect(selectedUrl).to.be.equals(testProdUrl)
123-
})
124-
}).beforeAll(() => {
125-
process.env['TRUSTIFY_DA_BACKEND_URL'] = testProdUrl;
126-
process.env['DEV_TRUSTIFY_DA_BACKEND_URL'] = testDevUrl
63+
}).afterAll(() => {
64+
delete process.env['TRUSTIFY_DA_BACKEND_URL'];
12765
});

0 commit comments

Comments
 (0)