1
1
'use strict' ;
2
2
const nock = require ( 'nock' ) ;
3
3
const sgClient = require ( './client' ) ;
4
- const testClient = require ( './client' ) ;
4
+ let testClient = require ( './client' ) ;
5
5
const testRequest = ( request , statusCode ) => {
6
6
const sgClient = require ( './client' ) ;
7
7
sgClient . setApiKey ( 'SG.API Key' ) ;
@@ -3094,23 +3094,26 @@ describe('test_whitelabel_links__link_id__subuser_post', () => {
3094
3094
} ) ;
3095
3095
3096
3096
describe ( 'setDataResidency' , ( ) => {
3097
- const testClient = require ( './client' ) ;
3098
3097
let consoleWarnSpy ;
3099
-
3100
3098
beforeEach ( ( ) => {
3099
+ testClient = require ( './client' ) ;
3101
3100
consoleWarnSpy = sinon . spy ( console , 'warn' ) ;
3102
3101
} ) ;
3103
3102
afterEach ( ( ) => {
3104
3103
console . warn . restore ( ) ;
3105
3104
} ) ;
3106
-
3105
+ it ( 'should have default value of hostname as https://api.sendgrid.com/' , ( ) => {
3106
+ expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.sendgrid.com/' ) ;
3107
+ expect ( testClient . sendgrid_region ) . to . equal ( '' ) ;
3108
+ } ) ;
3107
3109
it ( 'should send to host EU' , ( ) => {
3108
3110
testClient . setDataResidency ( 'eu' ) ;
3109
3111
expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.eu.sendgrid.com/' ) ;
3110
3112
} ) ;
3111
3113
it ( 'should send to host Global/default' , ( ) => {
3112
3114
testClient . setDataResidency ( 'global' ) ;
3113
3115
expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.sendgrid.com/' ) ;
3116
+ expect ( testClient . sendgrid_region ) . to . equal ( 'global' ) ;
3114
3117
} ) ;
3115
3118
it ( 'should override the existing set hostname, if data residency setter is called after' , ( ) => {
3116
3119
testClient . setApiKey ( 'SG.1234567890' ) ;
@@ -3125,13 +3128,19 @@ describe('setDataResidency', () => {
3125
3128
testClient . setDataResidency ( null ) ;
3126
3129
expect ( consoleWarnSpy . calledOnce ) . to . equal ( true ) ;
3127
3130
} ) ;
3128
- it ( 'should give precedence to the order of execution ' , ( ) => {
3131
+ it ( 'setting the API Key wont reset the region set ' , ( ) => {
3129
3132
testClient . setDataResidency ( 'eu' ) ;
3130
3133
testClient . setApiKey ( 'SG.1234567890' ) ;
3131
- expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.sendgrid.com/' ) ;
3134
+ expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.eu.sendgrid.com/' ) ;
3135
+ expect ( testClient . sendgrid_region ) . to . equal ( 'eu' ) ;
3132
3136
} ) ;
3133
- it ( 'should have default value of hostname as https://api.sendgrid.com/' , ( ) => {
3137
+ it ( 'should send to host global and then call setApiKey' , ( ) => {
3138
+ testClient . setDataResidency ( 'global' ) ;
3139
+ testClient . setApiKey ( 'SG.1234567890' ) ;
3134
3140
expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.sendgrid.com/' ) ;
3141
+ expect ( testClient . sendgrid_region ) . to . equal ( 'global' ) ;
3142
+
3143
+
3135
3144
} ) ;
3136
3145
} ) ;
3137
3146
0 commit comments