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