Skip to content

Commit

Permalink
shallow copy
Browse files Browse the repository at this point in the history
  • Loading branch information
gring2 committed Dec 4, 2023
1 parent 03b49b6 commit 42fce6c
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
5 changes: 2 additions & 3 deletions packages/mail/src/classes/mail-service.js
Original file line number Diff line number Diff line change
Expand Up @@ -181,7 +181,7 @@ class MailService {
try {

// copy object to avoid mutating original
const args = data;
const args = { ...data };
//Append multiple flag to data if not set
if (typeof data.isMultiple === 'undefined') {
args.isMultiple = isMultiple;
Expand All @@ -191,11 +191,10 @@ class MailService {
if (typeof data.substitutionWrappers === 'undefined') {
args.substitutionWrappers = this.substitutionWrappers;
}

//Create Mail instance from data and get JSON body for request
const mail = Mail.create(args);
const body = mail.toJSON();

//Filters the Mail body to avoid sensitive content leakage
this.filterSecrets(body);

Expand Down
33 changes: 33 additions & 0 deletions packages/mail/src/classes/mail-service.spec.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
const { assert } = require('chai');

const MailService = require('./mail-service');
describe('MailService send', () => {
it('should not mutate original data variable', () => {
const mailService = new MailService();
mailService.setClient({
request: (req, cb) => {
return new Promise((resolve) => {
resolve();
});
},
});
const data = {
to: '[email protected]',
from: '[email protected]', // Use the email address or domain you verified above
subject: 'Sending with Twilio SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
};
return mailService.send(data).then(() => {
assert.deepStrictEqual(data,
{
to: '[email protected]',
from: '[email protected]', // Use the email address or domain you verified above
subject: 'Sending with Twilio SendGrid is Fun',
text: 'and easy to do anywhere, even with Node.js',
html: '<strong>and easy to do anywhere, even with Node.js</strong>',
});

});
});
});

0 comments on commit 42fce6c

Please sign in to comment.