11'use strict' ;
22const nock = require ( 'nock' ) ;
33const sgClient = require ( './client' ) ;
4- const testClient = require ( './client' ) ;
4+ let testClient = require ( './client' ) ;
55const testRequest = ( request , statusCode ) => {
66 const sgClient = require ( './client' ) ;
77 sgClient . setApiKey ( 'SG.API Key' ) ;
@@ -3094,23 +3094,26 @@ describe('test_whitelabel_links__link_id__subuser_post', () => {
30943094} ) ;
30953095
30963096describe ( 'setDataResidency' , ( ) => {
3097- const testClient = require ( './client' ) ;
30983097 let consoleWarnSpy ;
3099-
31003098 beforeEach ( ( ) => {
3099+ testClient = require ( './client' ) ;
31013100 consoleWarnSpy = sinon . spy ( console , 'warn' ) ;
31023101 } ) ;
31033102 afterEach ( ( ) => {
31043103 console . warn . restore ( ) ;
31053104 } ) ;
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+ } ) ;
31073109 it ( 'should send to host EU' , ( ) => {
31083110 testClient . setDataResidency ( 'eu' ) ;
31093111 expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.eu.sendgrid.com/' ) ;
31103112 } ) ;
31113113 it ( 'should send to host Global/default' , ( ) => {
31123114 testClient . setDataResidency ( 'global' ) ;
31133115 expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.sendgrid.com/' ) ;
3116+ expect ( testClient . sendgrid_region ) . to . equal ( 'global' ) ;
31143117 } ) ;
31153118 it ( 'should override the existing set hostname, if data residency setter is called after' , ( ) => {
31163119 testClient . setApiKey ( 'SG.1234567890' ) ;
@@ -3125,13 +3128,19 @@ describe('setDataResidency', () => {
31253128 testClient . setDataResidency ( null ) ;
31263129 expect ( consoleWarnSpy . calledOnce ) . to . equal ( true ) ;
31273130 } ) ;
3128- it ( 'should give precedence to the order of execution ' , ( ) => {
3131+ it ( 'setting the API Key wont reset the region set ' , ( ) => {
31293132 testClient . setDataResidency ( 'eu' ) ;
31303133 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' ) ;
31323136 } ) ;
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' ) ;
31343140 expect ( testClient . defaultRequest . baseUrl ) . to . equal ( 'https://api.sendgrid.com/' ) ;
3141+ expect ( testClient . sendgrid_region ) . to . equal ( 'global' ) ;
3142+
3143+
31353144 } ) ;
31363145} ) ;
31373146
0 commit comments