From 11c2a5c60dbe565c106dfcd2bc448cbb9eff6d92 Mon Sep 17 00:00:00 2001 From: sburman Date: Mon, 20 Nov 2023 12:58:40 +0530 Subject: [PATCH] Update client.spec.js --- packages/client/src/client.spec.js | 56 ++++++++++++++++++++++++++---- 1 file changed, 49 insertions(+), 7 deletions(-) diff --git a/packages/client/src/client.spec.js b/packages/client/src/client.spec.js index 57cbcdf2..d7508177 100644 --- a/packages/client/src/client.spec.js +++ b/packages/client/src/client.spec.js @@ -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; @@ -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: 'me@you.com', + }, + 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()); }); });