|
1 | 1 | import { expect } from 'chai' |
2 | 2 |
|
3 | | -import {exhortDefaultUrl, exhortDevDefaultUrl, testSelectExhortBackend} from "../src/index.js" |
| 3 | +import { exhortDevUrl, testSelectExhortBackend } from '../src/index.js' |
| 4 | + |
| 5 | +const testProdUrl = 'https://exhort.example.com'; |
4 | 6 |
|
5 | 7 | suite('testing Select Exhort Backend function when EXHORT_DEV_MODE environment variable is True', () => { |
6 | 8 |
|
7 | | - test('When Dev Mode environment Variable= true, default DEV Exhort Backend Selected ', () => { |
| 9 | + test('When Dev Mode environment Variable= true, default DEV Exhort Backend Selected', () => { |
8 | 10 | let testOpts = { |
9 | | - "EXHORT_DEV_MODE" : "true" |
10 | | - |
| 11 | + 'EXHORT_DEV_MODE': 'true' |
11 | 12 | } |
12 | 13 | let selectedUrl = testSelectExhortBackend(testOpts); |
13 | | - expect(selectedUrl).not.to.be.equals(exhortDefaultUrl) |
14 | | - expect(selectedUrl).to.be.equals(exhortDevDefaultUrl) |
| 14 | + expect(selectedUrl).not.to.be.equals(testProdUrl) |
| 15 | + expect(selectedUrl).to.be.equals(exhortDevUrl) |
15 | 16 | }); |
16 | 17 |
|
17 | | - test('When Dev Mode environment Variable= true, and despite option Dev Mode = false , default DEV Exhort Backend Selected ', () => { |
| 18 | + test('When Dev Mode environment Variable= true, and despite option Dev Mode = false, default DEV Exhort Backend Selected', () => { |
18 | 19 | let testOpts = { |
19 | | - "EXHORT_DEV_MODE" : "false" |
| 20 | + 'EXHORT_DEV_MODE': 'false' |
20 | 21 | } |
21 | 22 | let selectedUrl = testSelectExhortBackend(testOpts); |
22 | | - expect(selectedUrl).not.to.be.equals(exhortDefaultUrl) |
23 | | - expect(selectedUrl).to.be.equals(exhortDevDefaultUrl) |
| 23 | + expect(selectedUrl).not.to.be.equals(testProdUrl) |
| 24 | + expect(selectedUrl).to.be.equals(exhortDevUrl) |
24 | 25 | }); |
25 | 26 |
|
26 | | - test('When Dev Mode environment Variable= true, And option DEV_EXHORT_BACKEND_URL contains some url route that client set , default DEV Exhort Backend Not Selected ', () => { |
27 | | - const dummyRoute = "http://dummy-exhort-route"; |
| 27 | + test('When Dev Mode environment Variable= true, And option DEV_EXHORT_BACKEND_URL contains some url route that client set, default DEV Exhort Backend Not Selected', () => { |
| 28 | + const dummyRoute = 'http://dummy-exhort-route'; |
28 | 29 | let testOpts = { |
29 | | - "DEV_EXHORT_BACKEND_URL" : dummyRoute |
| 30 | + 'DEV_EXHORT_BACKEND_URL': dummyRoute |
30 | 31 | } |
31 | 32 | let selectedUrl = testSelectExhortBackend(testOpts); |
32 | | - expect(selectedUrl).not.to.be.equals(exhortDevDefaultUrl) |
| 33 | + expect(selectedUrl).not.to.be.equals(exhortDevUrl) |
33 | 34 | expect(selectedUrl).to.be.equals(dummyRoute) |
34 | 35 | }); |
35 | 36 |
|
36 | | -}).beforeAll(() => process.env["EXHORT_DEV_MODE"] = "true" ).afterAll(() => delete process.env['EXHORT_DEV_MODE']); |
| 37 | +}).beforeAll(() => { process.env['EXHORT_DEV_MODE'] = 'true'; process.env['EXHORT_BACKEND_URL'] = testProdUrl }).afterAll(() => delete process.env['EXHORT_DEV_MODE']); |
37 | 38 |
|
38 | 39 | suite('testing Select Exhort Backend function when EXHORT_DEV_MODE environment variable is false', () => { |
39 | 40 |
|
40 | | - test('When Dev Mode environment Variable= true, default DEV Exhort Backend Selected ', () => { |
| 41 | + test('When Dev Mode environment Variable= true, default DEV Exhort Backend Selected', () => { |
41 | 42 |
|
42 | 43 | let testOpts = { |
43 | | - "EXHORT_DEV_MODE" : "false" |
| 44 | + 'EXHORT_DEV_MODE': 'false' |
44 | 45 | } |
45 | 46 | let selectedUrl = testSelectExhortBackend(testOpts); |
46 | | - expect(selectedUrl).not.to.be.equals(exhortDevDefaultUrl) |
47 | | - expect(selectedUrl).to.be.equals(exhortDefaultUrl) |
| 47 | + expect(selectedUrl).not.to.be.equals(exhortDevUrl) |
| 48 | + expect(selectedUrl).to.be.equals(testProdUrl) |
48 | 49 | }); |
49 | 50 |
|
50 | | - test('When Dev Mode environment Variable= false, and despite option Dev Mode = true , default Exhort Backend Selected (production) ', () => { |
51 | | - let dummyRoute = "http://dummy-dev-route-exhirt" |
| 51 | + test('When Dev Mode environment Variable= false, and despite option Dev Mode = true, default Exhort Backend Selected (production)', () => { |
| 52 | + let dummyRoute = 'http://dummy-dev-route-exhort' |
52 | 53 | let testOpts = { |
53 | | - "EXHORT_DEV_MODE" : "true", |
54 | | - "DEV_EXHORT_BACKEND_URL" : dummyRoute |
| 54 | + 'EXHORT_DEV_MODE': 'true', |
| 55 | + 'DEV_EXHORT_BACKEND_URL': dummyRoute |
55 | 56 | } |
56 | 57 | let selectedUrl = testSelectExhortBackend(testOpts); |
57 | 58 | expect(selectedUrl).not.to.be.equals(dummyRoute) |
58 | | - expect(selectedUrl).to.be.equals(exhortDefaultUrl) |
| 59 | + expect(selectedUrl).to.be.equals(testProdUrl) |
59 | 60 | }); |
60 | 61 |
|
61 | | - test('When Dev Mode environment Variable= false, environment variable DEV_EXHORT_BACKEND_URL=dummy-url , option EXHORT_DEV_MODE=true , default Exhort Backend Selected anyway ', () => { |
62 | | - const dummyRoute = "http://dummy-url" |
63 | | - process.env["DEV_EXHORT_BACKEND_URL"] = dummyRoute |
| 62 | + test('When Dev Mode environment Variable= false, environment variable DEV_EXHORT_BACKEND_URL=dummy-url, option EXHORT_DEV_MODE=true, default Exhort Backend Selected anyway', () => { |
| 63 | + const dummyRoute = 'http://dummy-url' |
| 64 | + process.env['DEV_EXHORT_BACKEND_URL'] = dummyRoute |
64 | 65 | let testOpts = { |
65 | | - "EXHORT_DEV_MODE" : "true", |
66 | | - "DEV_EXHORT_BACKEND_URL" : dummyRoute |
| 66 | + 'EXHORT_DEV_MODE': 'true', |
| 67 | + 'DEV_EXHORT_BACKEND_URL': dummyRoute |
67 | 68 | } |
68 | 69 | let selectedUrl = testSelectExhortBackend(testOpts); |
69 | | - delete process.env["DEV_EXHORT_BACKEND_URL"] |
| 70 | + delete process.env['DEV_EXHORT_BACKEND_URL'] |
70 | 71 | expect(selectedUrl).not.to.be.equals(dummyRoute) |
71 | | - expect(selectedUrl).to.be.equals(exhortDefaultUrl) |
| 72 | + expect(selectedUrl).to.be.equals(testProdUrl) |
72 | 73 | }); |
73 | 74 |
|
74 | | -}).beforeAll(() => process.env["EXHORT_DEV_MODE"] = "false" ).afterAll(() => delete process.env['EXHORT_DEV_MODE']); |
| 75 | +}).beforeAll(() => { process.env['EXHORT_DEV_MODE'] = 'false'; process.env['EXHORT_BACKEND_URL'] = testProdUrl }).afterAll(() => delete process.env['EXHORT_DEV_MODE']); |
75 | 76 |
|
76 | 77 | suite('testing Select Exhort Backend function when EXHORT_DEV_MODE environment variable is not set', () => { |
77 | 78 |
|
78 | 79 | test('When Dev Mode Option = false, default Exhort Backend Selected (production)', () => { |
79 | 80 |
|
80 | 81 | let testOpts = { |
81 | | - "EXHORT_DEV_MODE" : "false" |
| 82 | + 'EXHORT_DEV_MODE': 'false' |
82 | 83 | } |
83 | 84 | let selectedUrl = testSelectExhortBackend(testOpts); |
84 | | - expect(selectedUrl).not.to.be.equals(exhortDevDefaultUrl) |
85 | | - expect(selectedUrl).to.be.equals(exhortDefaultUrl) |
| 85 | + expect(selectedUrl).not.to.be.equals(exhortDevUrl) |
| 86 | + expect(selectedUrl).to.be.equals(testProdUrl) |
86 | 87 | }); |
87 | 88 |
|
88 | | - test('When Dev Mode Option Variable= true, default dev Exhort Backend Selected ', () => { |
| 89 | + test('When Dev Mode Option Variable= true, default dev Exhort Backend Selected', () => { |
89 | 90 | let testOpts = { |
90 | | - "EXHORT_DEV_MODE" : "true" |
| 91 | + 'EXHORT_DEV_MODE': 'true' |
91 | 92 | } |
92 | 93 | let selectedUrl = testSelectExhortBackend(testOpts); |
93 | | - expect(selectedUrl).not.to.be.equals(exhortDefaultUrl) |
94 | | - expect(selectedUrl).to.be.equals(exhortDevDefaultUrl) |
| 94 | + expect(selectedUrl).not.to.be.equals(testProdUrl) |
| 95 | + expect(selectedUrl).to.be.equals(exhortDevUrl) |
95 | 96 | }); |
96 | 97 |
|
97 | | - test('When Dev Mode option = true, option DEV_EXHORT_BACKEND_URL=some dummy-url , then some dummy-url Selected ', () => { |
98 | | - let dummyRoute = "http://dummy-dev-route-exhirt" |
99 | | - process.env["DEV_EXHORT_BACKEND_URL"] = dummyRoute |
| 98 | + test('When Dev Mode option = true, option DEV_EXHORT_BACKEND_URL=some dummy-url, then some dummy-url Selected', () => { |
| 99 | + let dummyRoute = 'http://dummy-dev-route-exhort' |
| 100 | + process.env['DEV_EXHORT_BACKEND_URL'] = dummyRoute |
100 | 101 | let testOpts = { |
101 | | - "EXHORT_DEV_MODE" : "true", |
102 | | - "DEV_EXHORT_BACKEND_URL" : dummyRoute |
| 102 | + 'EXHORT_DEV_MODE': 'true', |
| 103 | + 'DEV_EXHORT_BACKEND_URL': dummyRoute |
103 | 104 | } |
104 | 105 | let selectedUrl = testSelectExhortBackend(testOpts); |
105 | | - expect(selectedUrl).not.to.be.equals(exhortDefaultUrl) |
| 106 | + expect(selectedUrl).not.to.be.equals(testProdUrl) |
106 | 107 | expect(selectedUrl).to.be.equals(dummyRoute) |
107 | | - delete process.env["DEV_EXHORT_BACKEND_URL"] |
| 108 | + delete process.env['DEV_EXHORT_BACKEND_URL'] |
108 | 109 | }); |
109 | 110 |
|
110 | | - test('When Nothing set, Choose default backend (production) ', () => { |
| 111 | + test('When Nothing set, throw error', () => { |
111 | 112 | let selectedUrl = testSelectExhortBackend({}); |
112 | | - expect(selectedUrl).to.be.equals(exhortDefaultUrl) |
113 | | - }); |
114 | | - |
115 | | - |
116 | | -}); |
117 | | - |
| 113 | + expect(selectedUrl).to.be.equals(testProdUrl) |
| 114 | + }) |
| 115 | +}).beforeAll(() => process.env['EXHORT_BACKEND_URL'] = testProdUrl); |
0 commit comments