11import { expect } from 'chai'
22
3- import { exhortDevUrl , testSelectExhortBackend } from '../src/index.js'
3+ import { selectExhortBackend } from '../src/index.js'
44
55const testProdUrl = 'https://exhort.example.com' ;
6+ const testDevUrl = 'https://dev.exhort.example.com' ;
67
78suite ( '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
3944suite ( '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
7786suite ( '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