From eee815e465b6a528cad01f480556cc824e64bf0a Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Thu, 2 Sep 2021 18:12:54 +0530 Subject: [PATCH 01/10] reply_to_list support is added --- .gitignore | 2 ++ CHANGELOG.md | 3 +++ packages/helpers/classes/mail.d.ts | 6 ++++++ packages/helpers/classes/mail.js | 21 +++++++++++++++++++-- packages/mail/src/mail.spec.js | 6 ++++++ 5 files changed, 36 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index d71c17808..1c5acab77 100644 --- a/.gitignore +++ b/.gitignore @@ -10,3 +10,5 @@ package-lock.json yarn.lock *.bak .idea/ +sendgrid.env +.history diff --git a/CHANGELOG.md b/CHANGELOG.md index a5d0c31df..8b9cadd08 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,6 +1,9 @@ # Change Log All notable changes to this project will be documented in this file. +[2021-09-02] Version 7.4.7 +- Changes done by subinoy locally + [2021-08-11] Version 7.4.6 -------------------------- **Library - Fix** diff --git a/packages/helpers/classes/mail.d.ts b/packages/helpers/classes/mail.d.ts index f3246b804..9b88f507c 100644 --- a/packages/helpers/classes/mail.d.ts +++ b/packages/helpers/classes/mail.d.ts @@ -179,6 +179,7 @@ export interface MailJSON { batch_id?: string; template_id?: string; ip_pool_name?: string; + reply_to_list?: EmailJSON[]; } export default class Mail { @@ -353,4 +354,9 @@ export default class Mail { * Create a Mail instance from given data */ static create(data: MailData[]): Mail[]; + + /** + * Set reply_to_list header from given data + */ + setReplyToList(replyToList: EmailJSON[]): void; } diff --git a/packages/helpers/classes/mail.js b/packages/helpers/classes/mail.js index ac47128dc..9b2db2166 100644 --- a/packages/helpers/classes/mail.js +++ b/packages/helpers/classes/mail.js @@ -68,7 +68,7 @@ class Mail { templateId, personalizations, attachments, ipPoolName, batchId, sections, headers, categories, category, customArgs, asm, mailSettings, trackingSettings, substitutions, substitutionWrappers, dynamicTemplateData, isMultiple, - hideWarnings, + hideWarnings, replyToList, } = data; //Set data @@ -90,6 +90,7 @@ class Mail { this.setMailSettings(mailSettings); this.setTrackingSettings(trackingSettings); this.setHideWarnings(hideWarnings); + this.setReplyToList(replyToList); if (this.isDynamic) { this.setDynamicTemplateData(dynamicTemplateData); @@ -504,7 +505,7 @@ class Mail { from, replyTo, sendAt, subject, content, templateId, personalizations, attachments, ipPoolName, batchId, asm, sections, headers, categories, customArgs, mailSettings, - trackingSettings, + trackingSettings, replyToList, } = this; //Initialize with mandatory values @@ -560,6 +561,9 @@ class Mail { if (typeof ipPoolName !== 'undefined') { json.ipPoolName = ipPoolName; } + if(typeof replyToList !== 'undefined') { + json.replyToList = replyToList; + } //Return as snake cased object return toSnakeCase(json, ['substitutions', 'dynamicTemplateData', 'customArgs', 'headers', 'sections']); @@ -667,6 +671,19 @@ class Mail { value, [this._checkUndefined, this._createCheckThatThrows(Array.isArray, 'Array expected for`' + propertyName + '`')]); } + + setReplyToList(replyToList) { + if (this._doArrayCheck('replyToList', replyToList)) { + if (!replyToList.every(replyTo => typeof replyTo.email === 'string')) { + throw new Error('Expected each replyTo to contain a `email` string'); + } + if (!replyToList.every(replyTo => typeof replyTo.name === 'string')) { + throw new Error('Expected each replyTo to contain a `name` string'); + } + // this.replyToList = EmailAddress.create(replyToList); + this.replyToList = replyToList; + } + } } //Export class diff --git a/packages/mail/src/mail.spec.js b/packages/mail/src/mail.spec.js index 936b799a2..3a4c72dbf 100644 --- a/packages/mail/src/mail.spec.js +++ b/packages/mail/src/mail.spec.js @@ -67,5 +67,11 @@ describe('sgMail.send()', () => { })); }); }); + + // it('should have multiple replyTo emails', () => { + // sgClient.setDefaultHeader('X-Mock', 201); + // const clientSpy = sinon.spy(sgClient, "request"); + // debugger; + // }) }); From a31855c034a21dd6621165d26b54f5031d83741c Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Thu, 2 Sep 2021 23:43:12 +0530 Subject: [PATCH 02/10] added missing declaration in MailData --- packages/helpers/classes/mail.d.ts | 2 ++ 1 file changed, 2 insertions(+) diff --git a/packages/helpers/classes/mail.d.ts b/packages/helpers/classes/mail.d.ts index 9b88f507c..65ba9329f 100644 --- a/packages/helpers/classes/mail.d.ts +++ b/packages/helpers/classes/mail.d.ts @@ -155,6 +155,8 @@ export interface MailData { dynamicTemplateData?: { [key: string]: any }, hideWarnings?: boolean, + + replyToList?: EmailJSON | EmailJSON[], } export type MailDataRequired = MailData & ( From 7c9bd6820c5a5fa24d3fce35d32de731cda45c46 Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 24 Sep 2021 00:16:26 +0530 Subject: [PATCH 03/10] minor change in code logic --- packages/helpers/classes/mail.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/helpers/classes/mail.js b/packages/helpers/classes/mail.js index 9b2db2166..9fdf93374 100644 --- a/packages/helpers/classes/mail.js +++ b/packages/helpers/classes/mail.js @@ -672,14 +672,14 @@ class Mail { [this._checkUndefined, this._createCheckThatThrows(Array.isArray, 'Array expected for`' + propertyName + '`')]); } - setReplyToList(replyToList) { - if (this._doArrayCheck('replyToList', replyToList)) { - if (!replyToList.every(replyTo => typeof replyTo.email === 'string')) { + /** + * Set the replyToList from email body + */ + setReplyToList(replyToList) { + if (this._doArrayCheck('replyToList', replyToList) && replyToList.length) { + if (!replyToList.every(replyTo => replyTo && typeof replyTo.email === 'string')) { throw new Error('Expected each replyTo to contain a `email` string'); } - if (!replyToList.every(replyTo => typeof replyTo.name === 'string')) { - throw new Error('Expected each replyTo to contain a `name` string'); - } // this.replyToList = EmailAddress.create(replyToList); this.replyToList = replyToList; } From af05b7879a012b4fd79242c11ec5e5bdebef9ff9 Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 24 Sep 2021 00:25:23 +0530 Subject: [PATCH 04/10] removed the changes done in changelog as it's populated automatically --- CHANGELOG.md | 3 --- 1 file changed, 3 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 8b9cadd08..a5d0c31df 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -1,9 +1,6 @@ # Change Log All notable changes to this project will be documented in this file. -[2021-09-02] Version 7.4.7 -- Changes done by subinoy locally - [2021-08-11] Version 7.4.6 -------------------------- **Library - Fix** From 05fba7d416834f55715446f59886c0e4dd087744 Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 24 Sep 2021 02:15:43 +0530 Subject: [PATCH 05/10] Added test case coverage for replyToList functionality --- packages/mail/src/mail.spec.js | 83 +++++++++++++++++++++++++++++----- 1 file changed, 71 insertions(+), 12 deletions(-) diff --git a/packages/mail/src/mail.spec.js b/packages/mail/src/mail.spec.js index 3a4c72dbf..1061afc6c 100644 --- a/packages/mail/src/mail.spec.js +++ b/packages/mail/src/mail.spec.js @@ -17,7 +17,7 @@ before(() => { * Default mock header */ beforeEach(() => { - sgClient.setDefaultHeader('X-Mock', 200); + sgClient.setDefaultHeader('X-Mock', 202); }); /** @@ -38,12 +38,12 @@ describe('sgMail.send()', () => { return expect(sgMail.send()).to.eventually.be.rejectedWith(Error); }); - it('should send a basic email', () => { - sgClient.setDefaultHeader('X-Mock', 201); + it('should send a basic email', async () => { + sgClient.setDefaultHeader('X-Mock', 202); return sgMail .send(data) .then(([response, body]) => { - expect(response.statusCode).to.equal(201); + expect(response.statusCode).to.equal(202); }); }); @@ -53,13 +53,13 @@ describe('sgMail.send()', () => { }).to.throw(Error); }); - it('should include custom headers to the request', () => { - sgClient.setDefaultHeader('X-Mock', 201); + it('should include custom headers to the request', async () => { + sgClient.setDefaultHeader('X-Mock', 202); const clientSpy = sinon.spy(sgClient, "request") return sgMail .send(Object.assign(data, { headers: { customHeader: "Custom Header Content" } })) .then(([response, body]) => { - expect(response.statusCode).to.equal(201); + expect(response.statusCode).to.equal(202); expect(clientSpy).to.have.been.calledWith(sinon.match({ url: "/v3/mail/send", method: "POST", @@ -68,10 +68,69 @@ describe('sgMail.send()', () => { }); }); - // it('should have multiple replyTo emails', () => { - // sgClient.setDefaultHeader('X-Mock', 201); - // const clientSpy = sinon.spy(sgClient, "request"); - // debugger; - // }) + it('should send email with correct replyToList format', async () => { + sgClient.setDefaultHeader('X-Mock', 202); + data["replyToList"] = [ + { + "name": "Test Team", + "email": "test@twilio.com" + }, + { + "name": "Support Test Team", + "email": "support.test@twilio.com" + } + ]; + return sgMail + .send(data) + .then(([response, body]) => { + expect(response.statusCode).to.equal(202); + }); + }); + + it('should throw error with wrong replyToList format', async () => { + sgClient.setDefaultHeader('X-Mock', 202); + data["replyToList"] = { + "name": "Support Test Team", + "email": "support.test@twilio.com" + }; + return expect(function() { + sgMail.send(data, false, {}); + }).to.throw(Error); + }); + + it('should throw error if any record in replyToList is without email', async () => { + data["replyToList"] = [ + { + "name": "Test Team", + "email": "test@twilio.com" + }, + { + "name": "Support Test Team" + } + ]; + return expect(function() { + sgMail.send(data, false, {}); + }).to.throw(Error); + }); + + it('should throw error if both replyTo and replyToList are mentioned', async () => { + data["replyTo"] = { + "name": "Test Team234234", + "email": "test234235@twilio.com" + }; + data["replyToList"] = [ + { + "name": "Test Team", + "email": "test@twilio.com" + }, + { + "name": "Support Test Team", + "email": "support.test@twilio.com" + } + ]; + return expect(function() { + sgMail.send(data, false, {}); + }).to.throw(Error); + }); }); From be7d9498804d219f6b4c13c15daaa3e9ff684e7e Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 24 Sep 2021 02:18:56 +0530 Subject: [PATCH 06/10] reverted the changes of .gitignore that was done for development only --- .gitignore | 2 -- 1 file changed, 2 deletions(-) diff --git a/.gitignore b/.gitignore index 1c5acab77..d71c17808 100644 --- a/.gitignore +++ b/.gitignore @@ -10,5 +10,3 @@ package-lock.json yarn.lock *.bak .idea/ -sendgrid.env -.history From f22f65b133df954018a4fab62326310dc3c003f9 Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 24 Sep 2021 02:30:26 +0530 Subject: [PATCH 07/10] corrected test email ids to look good --- packages/mail/src/mail.spec.js | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/packages/mail/src/mail.spec.js b/packages/mail/src/mail.spec.js index 1061afc6c..ec517e7c7 100644 --- a/packages/mail/src/mail.spec.js +++ b/packages/mail/src/mail.spec.js @@ -73,11 +73,11 @@ describe('sgMail.send()', () => { data["replyToList"] = [ { "name": "Test Team", - "email": "test@twilio.com" + "email": "test@example.org" }, { "name": "Support Test Team", - "email": "support.test@twilio.com" + "email": "support.test@example.org" } ]; return sgMail @@ -91,7 +91,7 @@ describe('sgMail.send()', () => { sgClient.setDefaultHeader('X-Mock', 202); data["replyToList"] = { "name": "Support Test Team", - "email": "support.test@twilio.com" + "email": "support.test@example.org" }; return expect(function() { sgMail.send(data, false, {}); @@ -102,7 +102,7 @@ describe('sgMail.send()', () => { data["replyToList"] = [ { "name": "Test Team", - "email": "test@twilio.com" + "email": "test@example.org" }, { "name": "Support Test Team" @@ -115,17 +115,17 @@ describe('sgMail.send()', () => { it('should throw error if both replyTo and replyToList are mentioned', async () => { data["replyTo"] = { - "name": "Test Team234234", - "email": "test234235@twilio.com" + "name": "Manual Tester", + "email": "manual.test@example.org" }; data["replyToList"] = [ { "name": "Test Team", - "email": "test@twilio.com" + "email": "test@example.org" }, { "name": "Support Test Team", - "email": "support.test@twilio.com" + "email": "support.test@example.org" } ]; return expect(function() { From 1cb65250802e4c716f4a7fb2e38e2745f32c6c84 Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 24 Sep 2021 03:05:30 +0530 Subject: [PATCH 08/10] Added support of replyToList in the library, #339: - Use the replyToList header to set multiple emailIds in the reply-to section of an email - Fixed old test cases that were failing as SendGrid changed the acceptable response code to 202 --- packages/helpers/classes/mail.d.ts | 8 +++ packages/helpers/classes/mail.js | 21 +++++++- packages/mail/src/mail.spec.js | 79 +++++++++++++++++++++++++++--- 3 files changed, 99 insertions(+), 9 deletions(-) diff --git a/packages/helpers/classes/mail.d.ts b/packages/helpers/classes/mail.d.ts index f3246b804..65ba9329f 100644 --- a/packages/helpers/classes/mail.d.ts +++ b/packages/helpers/classes/mail.d.ts @@ -155,6 +155,8 @@ export interface MailData { dynamicTemplateData?: { [key: string]: any }, hideWarnings?: boolean, + + replyToList?: EmailJSON | EmailJSON[], } export type MailDataRequired = MailData & ( @@ -179,6 +181,7 @@ export interface MailJSON { batch_id?: string; template_id?: string; ip_pool_name?: string; + reply_to_list?: EmailJSON[]; } export default class Mail { @@ -353,4 +356,9 @@ export default class Mail { * Create a Mail instance from given data */ static create(data: MailData[]): Mail[]; + + /** + * Set reply_to_list header from given data + */ + setReplyToList(replyToList: EmailJSON[]): void; } diff --git a/packages/helpers/classes/mail.js b/packages/helpers/classes/mail.js index ac47128dc..9fdf93374 100644 --- a/packages/helpers/classes/mail.js +++ b/packages/helpers/classes/mail.js @@ -68,7 +68,7 @@ class Mail { templateId, personalizations, attachments, ipPoolName, batchId, sections, headers, categories, category, customArgs, asm, mailSettings, trackingSettings, substitutions, substitutionWrappers, dynamicTemplateData, isMultiple, - hideWarnings, + hideWarnings, replyToList, } = data; //Set data @@ -90,6 +90,7 @@ class Mail { this.setMailSettings(mailSettings); this.setTrackingSettings(trackingSettings); this.setHideWarnings(hideWarnings); + this.setReplyToList(replyToList); if (this.isDynamic) { this.setDynamicTemplateData(dynamicTemplateData); @@ -504,7 +505,7 @@ class Mail { from, replyTo, sendAt, subject, content, templateId, personalizations, attachments, ipPoolName, batchId, asm, sections, headers, categories, customArgs, mailSettings, - trackingSettings, + trackingSettings, replyToList, } = this; //Initialize with mandatory values @@ -560,6 +561,9 @@ class Mail { if (typeof ipPoolName !== 'undefined') { json.ipPoolName = ipPoolName; } + if(typeof replyToList !== 'undefined') { + json.replyToList = replyToList; + } //Return as snake cased object return toSnakeCase(json, ['substitutions', 'dynamicTemplateData', 'customArgs', 'headers', 'sections']); @@ -667,6 +671,19 @@ class Mail { value, [this._checkUndefined, this._createCheckThatThrows(Array.isArray, 'Array expected for`' + propertyName + '`')]); } + + /** + * Set the replyToList from email body + */ + setReplyToList(replyToList) { + if (this._doArrayCheck('replyToList', replyToList) && replyToList.length) { + if (!replyToList.every(replyTo => replyTo && typeof replyTo.email === 'string')) { + throw new Error('Expected each replyTo to contain a `email` string'); + } + // this.replyToList = EmailAddress.create(replyToList); + this.replyToList = replyToList; + } + } } //Export class diff --git a/packages/mail/src/mail.spec.js b/packages/mail/src/mail.spec.js index 936b799a2..ec517e7c7 100644 --- a/packages/mail/src/mail.spec.js +++ b/packages/mail/src/mail.spec.js @@ -17,7 +17,7 @@ before(() => { * Default mock header */ beforeEach(() => { - sgClient.setDefaultHeader('X-Mock', 200); + sgClient.setDefaultHeader('X-Mock', 202); }); /** @@ -38,12 +38,12 @@ describe('sgMail.send()', () => { return expect(sgMail.send()).to.eventually.be.rejectedWith(Error); }); - it('should send a basic email', () => { - sgClient.setDefaultHeader('X-Mock', 201); + it('should send a basic email', async () => { + sgClient.setDefaultHeader('X-Mock', 202); return sgMail .send(data) .then(([response, body]) => { - expect(response.statusCode).to.equal(201); + expect(response.statusCode).to.equal(202); }); }); @@ -53,13 +53,13 @@ describe('sgMail.send()', () => { }).to.throw(Error); }); - it('should include custom headers to the request', () => { - sgClient.setDefaultHeader('X-Mock', 201); + it('should include custom headers to the request', async () => { + sgClient.setDefaultHeader('X-Mock', 202); const clientSpy = sinon.spy(sgClient, "request") return sgMail .send(Object.assign(data, { headers: { customHeader: "Custom Header Content" } })) .then(([response, body]) => { - expect(response.statusCode).to.equal(201); + expect(response.statusCode).to.equal(202); expect(clientSpy).to.have.been.calledWith(sinon.match({ url: "/v3/mail/send", method: "POST", @@ -67,5 +67,70 @@ describe('sgMail.send()', () => { })); }); }); + + it('should send email with correct replyToList format', async () => { + sgClient.setDefaultHeader('X-Mock', 202); + data["replyToList"] = [ + { + "name": "Test Team", + "email": "test@example.org" + }, + { + "name": "Support Test Team", + "email": "support.test@example.org" + } + ]; + return sgMail + .send(data) + .then(([response, body]) => { + expect(response.statusCode).to.equal(202); + }); + }); + + it('should throw error with wrong replyToList format', async () => { + sgClient.setDefaultHeader('X-Mock', 202); + data["replyToList"] = { + "name": "Support Test Team", + "email": "support.test@example.org" + }; + return expect(function() { + sgMail.send(data, false, {}); + }).to.throw(Error); + }); + + it('should throw error if any record in replyToList is without email', async () => { + data["replyToList"] = [ + { + "name": "Test Team", + "email": "test@example.org" + }, + { + "name": "Support Test Team" + } + ]; + return expect(function() { + sgMail.send(data, false, {}); + }).to.throw(Error); + }); + + it('should throw error if both replyTo and replyToList are mentioned', async () => { + data["replyTo"] = { + "name": "Manual Tester", + "email": "manual.test@example.org" + }; + data["replyToList"] = [ + { + "name": "Test Team", + "email": "test@example.org" + }, + { + "name": "Support Test Team", + "email": "support.test@example.org" + } + ]; + return expect(function() { + sgMail.send(data, false, {}); + }).to.throw(Error); + }); }); From cb36df57f4faf3e640fd0e8b735905e64733cb73 Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Mon, 4 Oct 2021 23:06:44 +0530 Subject: [PATCH 09/10] Implemented code changes requested - removed commented unused code - Fixed typo in error message string - added missing test cases - added example doc of replyToLIst in use-cases --- docs/use-cases/multiple-reply-to-email.md | 24 ++++++++++ packages/helpers/classes/mail.js | 3 +- packages/helpers/classes/mail.spec.js | 58 +++++++++++++++++++++++ 3 files changed, 83 insertions(+), 2 deletions(-) create mode 100644 docs/use-cases/multiple-reply-to-email.md diff --git a/docs/use-cases/multiple-reply-to-email.md b/docs/use-cases/multiple-reply-to-email.md new file mode 100644 index 000000000..59736229d --- /dev/null +++ b/docs/use-cases/multiple-reply-to-email.md @@ -0,0 +1,24 @@ +# Multiple emails in replyTo + +An array of recipients who will receive replies and/or bounces. Each object in this array must contain the recipient's email address. Each object in the array may optionally contain the recipient's name. You can either choose to use “reply_to” field or “reply_to_list” but not both. [API specification](https://docs.sendgrid.com/api-reference/mail-send/mail-send#multiple-reply-to-emails) + +```js +const sgMail = require('@sendgrid/mail'); +sgMail.setApiKey(process.env.SENDGRID_API_KEY); +const msg = { + to: 'recipient@example.org', + from: 'sender@example.org', + subject: 'Multiple mail in replyTo', + html: '

Here’s an example of multiple replyTo email for you!

', + replyToList: [ + { + 'name': 'Test User1', + 'email': 'test_user1@example.org' + }, + { + 'email': 'test_user2@example.org' + } + ], +}; +``` + diff --git a/packages/helpers/classes/mail.js b/packages/helpers/classes/mail.js index 9fdf93374..b7dce14a2 100644 --- a/packages/helpers/classes/mail.js +++ b/packages/helpers/classes/mail.js @@ -678,9 +678,8 @@ class Mail { setReplyToList(replyToList) { if (this._doArrayCheck('replyToList', replyToList) && replyToList.length) { if (!replyToList.every(replyTo => replyTo && typeof replyTo.email === 'string')) { - throw new Error('Expected each replyTo to contain a `email` string'); + throw new Error('Expected each replyTo to contain an `email` string'); } - // this.replyToList = EmailAddress.create(replyToList); this.replyToList = replyToList; } } diff --git a/packages/helpers/classes/mail.spec.js b/packages/helpers/classes/mail.spec.js index d62fb9969..41aec6be9 100644 --- a/packages/helpers/classes/mail.spec.js +++ b/packages/helpers/classes/mail.spec.js @@ -246,4 +246,62 @@ describe('Mail', function() { expect(logSpy.calledWith(DYNAMIC_TEMPLATE_CHAR_WARNING)).to.equal(true); }); }); + + describe('set replyToList to set multiple reply-to', () => { + let data; + + this.beforeEach(() => { + data = { + to: 'send-to@example.org', + from: 'sender@example.org', + subject: 'test replyToList', + category: 'test', + text: 'Testing replyToList settings', + html: '

Testing replyToList settings

', + }; + }); + + it('should set the replyToList', () => { + let replyToList = [ + { + 'name': 'Test User1', + 'email': 'test_user1@example.org' + }, + { + 'email': 'test_user2@example.org' + } + ]; + data.replyToList = replyToList; + + const mail = new Mail(data); + + expect(mail.replyToList) + .to.be.deep.equal(replyToList); + }); + + it('should throw error for incorrect replyToList format', () => { + let replyToList = [ + { + 'name': 'Test User1' + }, + { + 'email_data': 'test_user2@example.org' + } + ]; + data.replyToList = replyToList; + + expect(() => new Mail(data)) + .to.throw('Expected each replyTo to contain an `email` string'); + }); + + it('should throw error for as replyToList is not an array', () => { + let replyToList = { + 'name': 'Test User1', + 'email': 'test_user1@example.org' + }; + data.replyToList = replyToList; + expect(() => new Mail(data)) + .to.throw('Array expected for`replyToList`'); + }); + }); }); From 423df199933a1a4fedd38b5e8ca5948fb22a014d Mon Sep 17 00:00:00 2001 From: Subinoy Ghosh Date: Fri, 15 Oct 2021 11:30:36 +0530 Subject: [PATCH 10/10] removed the use of async in test case as we are supporting node 6/8 --- packages/mail/src/mail.spec.js | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/packages/mail/src/mail.spec.js b/packages/mail/src/mail.spec.js index ec517e7c7..09698baa2 100644 --- a/packages/mail/src/mail.spec.js +++ b/packages/mail/src/mail.spec.js @@ -38,7 +38,7 @@ describe('sgMail.send()', () => { return expect(sgMail.send()).to.eventually.be.rejectedWith(Error); }); - it('should send a basic email', async () => { + it('should send a basic email', () => { sgClient.setDefaultHeader('X-Mock', 202); return sgMail .send(data) @@ -53,7 +53,7 @@ describe('sgMail.send()', () => { }).to.throw(Error); }); - it('should include custom headers to the request', async () => { + it('should include custom headers to the request', () => { sgClient.setDefaultHeader('X-Mock', 202); const clientSpy = sinon.spy(sgClient, "request") return sgMail @@ -68,7 +68,7 @@ describe('sgMail.send()', () => { }); }); - it('should send email with correct replyToList format', async () => { + it('should send email with correct replyToList format', () => { sgClient.setDefaultHeader('X-Mock', 202); data["replyToList"] = [ { @@ -87,7 +87,7 @@ describe('sgMail.send()', () => { }); }); - it('should throw error with wrong replyToList format', async () => { + it('should throw error with wrong replyToList format', () => { sgClient.setDefaultHeader('X-Mock', 202); data["replyToList"] = { "name": "Support Test Team", @@ -98,7 +98,7 @@ describe('sgMail.send()', () => { }).to.throw(Error); }); - it('should throw error if any record in replyToList is without email', async () => { + it('should throw error if any record in replyToList is without email', () => { data["replyToList"] = [ { "name": "Test Team", @@ -113,7 +113,7 @@ describe('sgMail.send()', () => { }).to.throw(Error); }); - it('should throw error if both replyTo and replyToList are mentioned', async () => { + it('should throw error if both replyTo and replyToList are mentioned', () => { data["replyTo"] = { "name": "Manual Tester", "email": "manual.test@example.org"