File tree Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Expand file tree Collapse file tree 2 files changed +20
-2
lines changed Original file line number Diff line number Diff line change @@ -38,7 +38,6 @@ class Client {
38
38
39
39
setApiKey ( apiKey ) {
40
40
this . auth = 'Bearer ' + apiKey ;
41
- this . setDefaultRequest ( 'baseUrl' , SENDGRID_BASE_URL ) ;
42
41
43
42
if ( ! this . isValidApiKey ( apiKey ) ) {
44
43
console . warn ( `API key does not start with "${ API_KEY_PREFIX } ".` ) ;
@@ -48,7 +47,9 @@ class Client {
48
47
setTwilioEmailAuth ( username , password ) {
49
48
const b64Auth = Buffer . from ( username + ':' + password ) . toString ( 'base64' ) ;
50
49
this . auth = 'Basic ' + b64Auth ;
51
- this . setDefaultRequest ( 'baseUrl' , TWILIO_BASE_URL ) ;
50
+ if ( this . defaultRequest . baseUrl === SENDGRID_BASE_URL ) {
51
+ this . setDefaultRequest ( 'baseUrl' , TWILIO_BASE_URL ) ;
52
+ }
52
53
53
54
if ( ! this . isValidTwilioAuth ( username , password ) ) {
54
55
console . warn ( 'Twilio Email credentials must be non-empty strings.' ) ;
Original file line number Diff line number Diff line change @@ -106,6 +106,23 @@ describe('setImpersonateSubuser', () => {
106
106
} ) ;
107
107
} ) ;
108
108
109
+ describe ( 'setDefaultRequest' , ( ) => {
110
+ const customBaseUrl = 'localhost:3030' ;
111
+ const sgClient = require ( './client' ) ;
112
+
113
+ it ( 'should set the custom base URL without being overwritten by setApiKey' , ( ) => {
114
+ sgClient . setDefaultRequest ( 'baseUrl' , customBaseUrl ) ;
115
+ sgClient . setApiKey ( 'SG\.1234567890' ) ;
116
+ expect ( sgClient . defaultRequest . baseUrl ) . to . equal ( customBaseUrl ) ;
117
+ } ) ;
118
+
119
+ it ( 'should set the custom base URL without being overwritten by setTwilioEmailAuth' , ( ) => {
120
+ sgClient . setDefaultRequest ( 'baseUrl' , customBaseUrl ) ;
121
+ sgClient . setTwilioEmailAuth ( 'username' , 'password' ) ;
122
+ expect ( sgClient . defaultRequest . baseUrl ) . to . equal ( customBaseUrl ) ;
123
+ } ) ;
124
+ } ) ;
125
+
109
126
describe ( 'test_access_settings_activity_get' , ( ) => {
110
127
const request = { } ;
111
128
request . qs = {
You can’t perform that action at this time.
0 commit comments