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 {
3838
3939 setApiKey ( apiKey ) {
4040 this . auth = 'Bearer ' + apiKey ;
41- this . setDefaultRequest ( 'baseUrl' , SENDGRID_BASE_URL ) ;
4241
4342 if ( ! this . isValidApiKey ( apiKey ) ) {
4443 console . warn ( `API key does not start with "${ API_KEY_PREFIX } ".` ) ;
@@ -48,7 +47,9 @@ class Client {
4847 setTwilioEmailAuth ( username , password ) {
4948 const b64Auth = Buffer . from ( username + ':' + password ) . toString ( 'base64' ) ;
5049 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+ }
5253
5354 if ( ! this . isValidTwilioAuth ( username , password ) ) {
5455 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', () => {
106106 } ) ;
107107} ) ;
108108
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+
109126describe ( 'test_access_settings_activity_get' , ( ) => {
110127 const request = { } ;
111128 request . qs = {
You can’t perform that action at this time.
0 commit comments