Skip to content

Commit

Permalink
Update client.spec.js
Browse files Browse the repository at this point in the history
  • Loading branch information
shrutiburman committed Nov 20, 2023
1 parent 36b31da commit 11c2a5c
Showing 1 changed file with 49 additions and 7 deletions.
56 changes: 49 additions & 7 deletions packages/client/src/client.spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,17 @@ const testRequest = (request, statusCode) => {
});
};

const testRequestWithClient = (request, statusCode) => {
const testClient = require('./client');
testClient.setDefaultHeader('X-Mock', statusCode);
testClient.setDataResidency('eu');
return testClient
.request(request)
.then(([response, body]) => {
expect(response.statusCode).to.equal(statusCode);
});
};

describe('client', () => {
const sgClient = require('./client');
let consoleWarnSpy;
Expand Down Expand Up @@ -3097,15 +3108,46 @@ describe('test_whitelabel_links__link_id__subuser_post', () => {

describe('test client', () => {
const testClient = require('./client');
// describe('setDataResidency', () => {
// testClient.setDataResidency('eu');
// console.log("before: ");
// console.log(testClient);
// console.log('Actual:', testClient.defaultRequest.baseUrl);
// it('should have hostname as global', () => {
// console.log(testClient);
// expect(testClient.defaultRequest.baseUrl).to.equal('api.eu.sendgrid.com');
// });
// });
it('should test', () => {
const request = {
body: {
content: [
{
type: 'text/plain',
value: '#'.repeat(1024 * 1024 * 10), // 10 MB,
},
],
from: {
email: '[email protected]',
},
subject: 'Hello, World!',
},
method: 'POST',
url: '/v3/mail/send',
};

return testRequestWithClient(request, 202);
});
it('should send requests to the hostname', () => {
const scope = nock('https://api.eu.sendgrid.com')
.matchHeader('Authorization', /^Bearer SG\.1234567890$/)
.get('/')
.reply(200, 'test response');

describe('setDataResidency', () => {
testClient.setDataResidency('eu');
sgClient.setDataResidency('eu');
console.log('Actual:', testClient.defaultRequest.baseUrl);
it('should have hostname as global', () => {
console.log(testClient);
expect(testClient.defaultRequest.baseUrl).to.equal('api.eu.sendgrid.com');
});

return sgClient.request({})
.then(() => scope.done());
});
});

0 comments on commit 11c2a5c

Please sign in to comment.