@@ -35,6 +35,7 @@ describe('services', () => {
35
35
const profile = configData . getProfileById ( 'DOES_NOT_EXIST' ) ;
36
36
expect ( profile ) . to . be . undefined ;
37
37
} ) ;
38
+
38
39
test . it ( 'should return undefined if no profiles, even with env vars' , ( ) => {
39
40
const configData = new ConfigData ( ) ;
40
41
process . env . TWILIO_ACCOUNT_SID = constants . FAKE_ACCOUNT_SID ;
@@ -43,6 +44,7 @@ describe('services', () => {
43
44
const profile = configData . getProfileById ( 'DOES_NOT_EXIST' ) ;
44
45
expect ( profile ) . to . be . undefined ;
45
46
} ) ;
47
+
46
48
test . it ( 'should return first profile if it exists, and no env vars' , ( ) => {
47
49
const configData = new ConfigData ( ) ;
48
50
configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
@@ -52,6 +54,7 @@ describe('services', () => {
52
54
expect ( profile . apiKey ) . to . be . undefined ;
53
55
expect ( profile . apiSecret ) . to . be . undefined ;
54
56
} ) ;
57
+
55
58
test . it ( 'return the active profile if there are multiple profiles' , ( ) => {
56
59
const configData = new ConfigData ( ) ;
57
60
configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
@@ -64,6 +67,7 @@ describe('services', () => {
64
67
expect ( profile . apiKey ) . to . be . undefined ;
65
68
expect ( profile . apiSecret ) . to . be . undefined ;
66
69
} ) ;
70
+
67
71
test . it ( 'should return profile populated from AccountSid/AuthToken env vars' , ( ) => {
68
72
const configData = new ConfigData ( ) ;
69
73
configData . addProfile ( 'envProfile' , constants . FAKE_ACCOUNT_SID ) ;
@@ -91,6 +95,21 @@ describe('services', () => {
91
95
expect ( profile . apiKey ) . to . equal ( constants . FAKE_API_KEY ) ;
92
96
expect ( profile . apiSecret ) . to . equal ( constants . FAKE_API_SECRET ) ;
93
97
} ) ;
98
+
99
+ test . it ( 'should return profile populated with region env var' , ( ) => {
100
+ const configData = new ConfigData ( ) ;
101
+ configData . addProfile ( 'envProfile' , constants . FAKE_ACCOUNT_SID ) ;
102
+
103
+ process . env . TWILIO_ACCOUNT_SID = constants . FAKE_ACCOUNT_SID ;
104
+ process . env . TWILIO_AUTH_TOKEN = FAKE_AUTH_TOKEN ;
105
+ process . env . TWILIO_REGION = 'region' ;
106
+
107
+ const profile = configData . getProfileById ( ) ;
108
+ expect ( profile . accountSid ) . to . equal ( constants . FAKE_ACCOUNT_SID ) ;
109
+ expect ( profile . apiKey ) . to . equal ( constants . FAKE_ACCOUNT_SID ) ;
110
+ expect ( profile . apiSecret ) . to . equal ( FAKE_AUTH_TOKEN ) ;
111
+ expect ( profile . region ) . to . equal ( 'region' ) ;
112
+ } ) ;
94
113
} ) ;
95
114
96
115
describe ( 'ConfigData.activeProfile' , ( ) => {
@@ -104,6 +123,7 @@ describe('services', () => {
104
123
expect ( active . id ) . to . equal ( 'firstProfile' ) ;
105
124
expect ( active . accountSid ) . to . equal ( constants . FAKE_ACCOUNT_SID ) ;
106
125
} ) ;
126
+
107
127
test . it ( 'should return active profile when active profile has been set' , ( ) => {
108
128
const configData = new ConfigData ( ) ;
109
129
configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
@@ -115,12 +135,14 @@ describe('services', () => {
115
135
expect ( active . id ) . to . equal ( 'secondProfile' ) ;
116
136
expect ( active . accountSid ) . to . equal ( 'new_account_SID' ) ;
117
137
} ) ;
138
+
118
139
test . it ( 'should not allow the active profile to not exist' , ( ) => {
119
140
const configData = new ConfigData ( ) ;
120
141
configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
121
142
expect ( configData . setActiveProfile ( 'secondProfile' ) ) . to . be . undefined ;
122
143
expect ( configData . getActiveProfile ( ) . id ) . to . equal ( 'firstProfile' ) ;
123
144
} ) ;
145
+
124
146
test . it ( 'should return undefined if profile does not exist and there are no profiles configured' , ( ) => {
125
147
const configData = new ConfigData ( ) ;
126
148
const active = configData . getActiveProfile ( ) ;
@@ -143,6 +165,7 @@ describe('services', () => {
143
165
144
166
expect ( configData . profiles . length ) . to . equal ( originalLength ) ;
145
167
} ) ;
168
+
146
169
test . it ( 'removes profile' , ( ) => {
147
170
const configData = new ConfigData ( ) ;
148
171
configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
@@ -154,6 +177,7 @@ describe('services', () => {
154
177
expect ( configData . profiles [ 1 ] . id ) . to . equal ( 'thirdProfile' ) ;
155
178
expect ( configData . profiles [ 1 ] . accountSid ) . to . equal ( 'newest_account_SID' ) ;
156
179
} ) ;
180
+
157
181
test . it ( 'removes active profile' , ( ) => {
158
182
const configData = new ConfigData ( ) ;
159
183
configData . addProfile ( 'firstProfile' , constants . FAKE_ACCOUNT_SID ) ;
0 commit comments