Skip to content

Commit

Permalink
test
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutiburman committed Nov 23, 2023
1 parent b69670e commit bf6d7cc
Show file tree
Hide file tree
Showing 2 changed files with 15 additions and 4 deletions.
2 changes: 1 addition & 1 deletion packages/client/src/classes/client.js
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,7 @@ class Client {

setApiKey(apiKey) {
this.auth = 'Bearer ' + apiKey;
// this means that region based setter was not called
// this means that region was never set before
if (this.sendgrid_region == '') {
this.setDefaultRequest('baseUrl', SENDGRID_BASE_URL);
}
Expand Down
17 changes: 14 additions & 3 deletions packages/client/src/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -3094,10 +3094,10 @@ describe('test_whitelabel_links__link_id__subuser_post', () => {
});

describe('setDataResidency', () => {
const testClient = require('./client');
let consoleWarnSpy;

beforeEach(() => {
const testClient = require('./client');
consoleWarnSpy = sinon.spy(console, 'warn');
});
afterEach(() => {
Expand All @@ -3111,6 +3111,7 @@ describe('setDataResidency', () => {
it('should send to host Global/default', () => {
testClient.setDataResidency('global');
expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/');
expect(testClient.region).to.equal('global');
});
it('should override the existing set hostname, if data residency setter is called after', () => {
testClient.setApiKey('SG.1234567890');
Expand All @@ -3125,13 +3126,23 @@ describe('setDataResidency', () => {
testClient.setDataResidency(null);
expect(consoleWarnSpy.calledOnce).to.equal(true);
});
it('should give precedence to the order of execution', () => {
it('setting the API Key wont reset the region set', () => {
testClient.setDataResidency('eu');
testClient.setApiKey('SG.1234567890');
expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/');
expect(testClient.defaultRequest.baseUrl).to.equal('https://api.eu.sendgrid.com/');
expect(testClient.region).to.equal('eu');
});
it('should have default value of hostname as https://api.sendgrid.com/', () => {
expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/');
expect(testClient.region).to.equal('');
});
it('should send to host global and then call setApiKey', () => {
testClient.setDataResidency('global');
testClient.setApiKey('SG.1234567890');
expect(testClient.defaultRequest.baseUrl).to.equal('https://api.sendgrid.com/');
expect(testClient.region).to.equal('global');


});
});

0 comments on commit bf6d7cc

Please sign in to comment.