|
1 | 1 | 'use strict'; |
2 | 2 | const nock = require('nock'); |
3 | 3 | const sgClient = require('./client'); |
4 | | - |
| 4 | +const testClient = require('./client'); |
5 | 5 | const testRequest = (request, statusCode) => { |
6 | 6 | const sgClient = require('./client'); |
7 | 7 | sgClient.setApiKey('SG.API Key'); |
@@ -3094,10 +3094,44 @@ describe('test_whitelabel_links__link_id__subuser_post', () => { |
3094 | 3094 | }); |
3095 | 3095 |
|
3096 | 3096 | describe('setDataResidency', () => { |
3097 | | - const sgClient = require('./client'); |
3098 | | - sgClient.setDataResidency('eu'); |
| 3097 | + const testClient = require('./client'); |
| 3098 | + let consoleWarnSpy; |
3099 | 3099 |
|
3100 | | - it('should have host as eu', () => { |
3101 | | - expect(sgClient.baseUrl).to.equal('api.eu.sendgrid.com'); |
| 3100 | + beforeEach(() => { |
| 3101 | + consoleWarnSpy = sinon.spy(console, 'warn'); |
| 3102 | + }); |
| 3103 | + afterEach(() => { |
| 3104 | + console.warn.restore(); |
| 3105 | + }); |
| 3106 | + |
| 3107 | + it('should send to host EU', () => { |
| 3108 | + testClient.setDataResidency('eu'); |
| 3109 | + expect(testClient.defaultRequest.baseUrl).to.equal('https://api.eu.sendgrid.com/'); |
| 3110 | + }); |
| 3111 | + it('should send to host Global/default', () => { |
| 3112 | + testClient.setDataResidency('global'); |
| 3113 | + expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/'); |
| 3114 | + }); |
| 3115 | + it('should override the existing set hostname, if data residency setter is called after', () => { |
| 3116 | + testClient.setApiKey('SG.1234567890'); |
| 3117 | + testClient.setDataResidency('eu'); |
| 3118 | + expect(testClient.defaultRequest.baseUrl).to.equal('https://api.eu.sendgrid.com/'); |
| 3119 | + }); |
| 3120 | + it('should give a warning if the provided value is not allowed', () => { |
| 3121 | + testClient.setDataResidency(''); |
| 3122 | + expect(consoleWarnSpy.calledOnce).to.equal(true); |
| 3123 | + }); |
| 3124 | + it('should give a warning if the provided value is null', () => { |
| 3125 | + testClient.setDataResidency(null); |
| 3126 | + expect(consoleWarnSpy.calledOnce).to.equal(true); |
| 3127 | + }); |
| 3128 | + it('should give precedence to the order of execution', () => { |
| 3129 | + testClient.setDataResidency('eu'); |
| 3130 | + testClient.setApiKey('SG.1234567890'); |
| 3131 | + expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/'); |
| 3132 | + }); |
| 3133 | + it('should have default value of hostname as https://api.sendgrid.com/', () => { |
| 3134 | + expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/'); |
3102 | 3135 | }); |
3103 | 3136 | }); |
| 3137 | + |
0 commit comments