-
Notifications
You must be signed in to change notification settings - Fork 778
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Incorporated code review comments for #691
- Loading branch information
1 parent
2abbbce
commit afc4e65
Showing
10 changed files
with
254 additions
and
336 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -21,7 +21,7 @@ class Mail { | |
constructor(data) { | ||
|
||
//Initialize array and object properties | ||
this._isDynamic = false; | ||
this.isDynamic = false; | ||
this.personalizations = []; | ||
this.attachments = []; | ||
this.content = []; | ||
|
@@ -86,7 +86,7 @@ class Mail { | |
this.setMailSettings(mailSettings); | ||
this.setTrackingSettings(trackingSettings); | ||
|
||
if (this._isDynamic) { | ||
if (this.isDynamic) { | ||
This comment has been minimized.
Sorry, something went wrong.
This comment has been minimized.
Sorry, something went wrong.
thinkingserious
Contributor
|
||
this.setDynamicTemplateData(dynamicTemplateData) | ||
} else { | ||
this.setSubstitutions(substitutions); | ||
|
@@ -171,7 +171,7 @@ class Mail { | |
} | ||
|
||
if (templateId.indexOf('d-') === 0) { | ||
this._isDynamic = true; | ||
this.isDynamic = true; | ||
} | ||
|
||
this.templateId = templateId; | ||
|
@@ -240,7 +240,7 @@ class Mail { | |
|
||
//We should either send substitutions or dynamicTemplateData | ||
//depending on the templateId | ||
if (this._isDynamic && personalization.substitutions) { | ||
if (this.isDynamic && personalization.substitutions) { | ||
delete personalization.substitutions; | ||
} else if (personalization.dynamicTemplateData) { | ||
delete personalization.dynamicTemplateData; | ||
|
@@ -252,7 +252,7 @@ class Mail { | |
} | ||
|
||
//If this is dynamic, set dynamicTemplateData, or set substitutions | ||
if (this._isDynamic) { | ||
if (this.isDynamic) { | ||
this.applyDynamicTemplateData(personalization); | ||
} else { | ||
this.applySubstitutions(personalization); | ||
|
@@ -273,7 +273,7 @@ class Mail { | |
) { | ||
throw new Error('Provide at least one of to, cc or bcc'); | ||
} | ||
this.addPersonalization(new Personalization({ to, cc, bcc })); | ||
this.addPersonalization(new Personalization({to, cc, bcc})); | ||
} | ||
|
||
/** | ||
|
@@ -319,12 +319,12 @@ class Mail { | |
*/ | ||
applyDynamicTemplateData(personalization) { | ||
if (personalization instanceof Personalization) { | ||
personalization.reverseMergeDynamicTemplateData(this.dynamicTemplateData); | ||
personalization.deepMergeDynamicTemplateData(this.dynamicTemplateData); | ||
} | ||
} | ||
|
||
/** | ||
* Set substitutions | ||
* Set dynamicTemplateData | ||
*/ | ||
setDynamicTemplateData(dynamicTemplateData) { | ||
if (typeof dynamicTemplateData === 'undefined') { | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -8,10 +8,10 @@ const Mail = require('./mail'); | |
/** | ||
* Tests | ||
*/ | ||
describe('Mail', function () { | ||
describe('Mail', function() { | ||
|
||
describe('#527', function () { | ||
it('shouldn\'t convert the headers to camel/snake case', function () { | ||
describe('#527', function() { | ||
it('shouldn\'t convert the headers to camel/snake case', function() { | ||
const mail = new Mail({ | ||
personalizations: [{ | ||
to: '[email protected]', | ||
|
@@ -40,9 +40,9 @@ describe('Mail', function () { | |
.equal('<mailto:[email protected]>'); | ||
}); | ||
}); | ||
describe('#689', function () { | ||
describe('#689', function() { | ||
|
||
it('should detect dynamic template id', function () { | ||
it('should detect dynamic template id', function() { | ||
const mail = new Mail({ | ||
personalizations: [{ | ||
to: '[email protected]', | ||
|
@@ -58,11 +58,11 @@ describe('Mail', function () { | |
content: [{ | ||
type: 'text/plain', | ||
value: 'test', | ||
}] | ||
}], | ||
}); | ||
expect(mail._isDynamic).to.equal(true); | ||
expect(mail.isDynamic).to.equal(true); | ||
}); | ||
it('should detect legacy template id', function () { | ||
it('should detect legacy template id', function() { | ||
const mail = new Mail({ | ||
personalizations: [{ | ||
to: '[email protected]', | ||
|
@@ -78,19 +78,19 @@ describe('Mail', function () { | |
content: [{ | ||
type: 'text/plain', | ||
value: 'test', | ||
}] | ||
}], | ||
}); | ||
expect(mail._isDynamic).to.equal(false); | ||
expect(mail.isDynamic).to.equal(false); | ||
}); | ||
it('should ignore substitutions if templateId is dynamic', function () { | ||
it('should ignore substitutions if templateId is dynamic', function() { | ||
const mail = new Mail({ | ||
personalizations: [{ | ||
to: '[email protected]', | ||
headers: { | ||
'test-header': 'test', | ||
}, | ||
substitutions: { | ||
test2: 'Test2' | ||
test2: 'Test2', | ||
}, | ||
dynamicTemplateData: { | ||
test2: 'Testy 2', | ||
|
@@ -102,7 +102,7 @@ describe('Mail', function () { | |
test2: 'Test 2', | ||
}, | ||
substitutions: { | ||
test1: 'Test1' | ||
test1: 'Test1', | ||
}, | ||
from: { | ||
email: '[email protected]', | ||
|
@@ -112,7 +112,7 @@ describe('Mail', function () { | |
content: [{ | ||
type: 'text/plain', | ||
value: 'test', | ||
}] | ||
}], | ||
}); | ||
expect(mail.substitutions).to.equal(null); | ||
expect(mail.personalizations[0].substitutions).to.deep.equal({}); | ||
|
@@ -121,37 +121,37 @@ describe('Mail', function () { | |
expect(mail.personalizations[0].dynamicTemplateData).to.deep.equal({ test1: 'Test 1', test2: 'Testy 2', test3: 'Testy 3' }); | ||
|
||
expect(mail.toJSON()).to.deep.equal({ | ||
"content": [ | ||
'content': [ | ||
{ | ||
"type": "text/plain", | ||
"value": "test" | ||
} | ||
'type': 'text/plain', | ||
'value': 'test', | ||
}, | ||
], | ||
"from": { | ||
"email": "[email protected]" | ||
'from': { | ||
'email': '[email protected]', | ||
}, | ||
"personalizations": [ | ||
'personalizations': [ | ||
{ | ||
"dynamic_template_data": { | ||
"test1": "Test 1", | ||
"test2": "Testy 2", | ||
"test3": "Testy 3" | ||
'dynamic_template_data': { | ||
'test1': 'Test 1', | ||
'test2': 'Testy 2', | ||
'test3': 'Testy 3', | ||
}, | ||
"headers": { | ||
"test-header": "test" | ||
'headers': { | ||
'test-header': 'test', | ||
}, | ||
"to": [ | ||
'to': [ | ||
{ | ||
"email": "[email protected]", | ||
"name": "" | ||
} | ||
] | ||
} | ||
'email': '[email protected]', | ||
'name': '', | ||
}, | ||
], | ||
}, | ||
], | ||
"subject": "test", | ||
"template_id": "d-df80613cccc6441ea5cd7c95377bc1ef" | ||
'subject': 'test', | ||
'template_id': 'd-df80613cccc6441ea5cd7c95377bc1ef', | ||
}); | ||
}); | ||
|
||
}) | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,7 +1,7 @@ | ||
import * as helpers from "@sendgrid/helpers/helpers/index" | ||
import * as classes from "@sendgrid/helpers/classes/index" | ||
import * as helpers from '@sendgrid/helpers/helpers/index'; | ||
import * as classes from '@sendgrid/helpers/classes/index'; | ||
|
||
export { | ||
helpers, | ||
classes, | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -30,6 +30,7 @@ | |
"helpers" | ||
], | ||
"dependencies": { | ||
"chalk": "^2.0.1" | ||
"chalk": "^2.0.1", | ||
"deepmerge": "^2.1.1" | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Would there ever be a time in which this would not be
false
(with the way that things are written currently)?