fixed send email tests
This commit is contained in:
parent
ef9265576c
commit
995e94f7f5
|
@ -3,9 +3,11 @@
|
|||
/**
|
||||
* Module dependencies.
|
||||
*/
|
||||
const emailNotifications = require('../../libs/send-email-notifications'),
|
||||
constants = require('../../libs/constants'),
|
||||
mockTransport = require("nodemailer").createTransport("Stub"),
|
||||
const should = require('should'),
|
||||
emailNotifications = require('../../libs/send-email-notifications'),
|
||||
mockTransport = require('nodemailer').createTransport({
|
||||
jsonTransport: true
|
||||
}),
|
||||
config = require('../../../config/config');
|
||||
|
||||
/**
|
||||
|
@ -20,7 +22,7 @@ const validFormFields = [
|
|||
const validFieldDict = {
|
||||
'56340745f59a6fc9e22028e9': 'John Smith',
|
||||
'5c9e22028e907634f45f59a6': 'https://johnsmith.me',
|
||||
'56e90745f5934fc9e22028a6': 45
|
||||
'56e90745f5934fc9e22028a6': '45'
|
||||
};
|
||||
|
||||
const invalidFormFields = [
|
||||
|
@ -29,13 +31,11 @@ const invalidFormFields = [
|
|||
{fieldType:'number', title:'Your Age'}
|
||||
];
|
||||
|
||||
const htmlTemplate = '<p><var class="tag" id="field:56340745f59a6fc9e22028e9">First Name</var> \
|
||||
<br><var class="tag" id="field:5c9e22028e907634f45f59a6">Your Website</var> \
|
||||
<br><var class="tag" id="field:56e90745f5934fc9e22028a6">Your Age</var></p>';
|
||||
const htmlTemplate = '<p><span class="placeholder-tag" data-id="56340745f59a6fc9e22028e9">First Name</span>'+
|
||||
'<br><span class="placeholder-tag" data-id="5c9e22028e907634f45f59a6">Your Website</span>'+
|
||||
'<br><span class="placeholder-tag" data-id="56e90745f5934fc9e22028a6">Your Age</span></p>';
|
||||
|
||||
const renderedTemplate = '<p>John Smith \
|
||||
<br>https://johnsmith.me \
|
||||
<br>45</p>';
|
||||
const renderedTemplate = '<!DOCTYPE html><html><head></head><body><p>John Smith<br>https://johnsmith.me<br>45</p></body></html>';
|
||||
|
||||
/**
|
||||
* Unit tests
|
||||
|
@ -56,36 +56,24 @@ describe('Send Email Notification Unit Tests', function() {
|
|||
|
||||
describe('Method parseTemplate', function(){
|
||||
it('should properly render a template given a valid field dict', function() {
|
||||
var actualRenderedTemplate = emailNotifications.parseTemplate(htmlTemplate, validFieldDict, constants.varFormat).replace((/ |\r\n|\n|\r|\t/gm),'');
|
||||
var actualRenderedTemplate = emailNotifications.parseTemplate(htmlTemplate, validFieldDict, false).replace((/ |\r\n|\n|\r|\t/gm),'');
|
||||
actualRenderedTemplate.should.equal(renderedTemplate.replace((/ |\r\n|\n|\r|\t/gm),''));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Method replaceTemplateVal', function() {
|
||||
it('should properly replace a template var in a valid template', function() {
|
||||
var expectedHtml = '<p>John Smith \
|
||||
<br><var class="tag" id="field:5c9e22028e907634f45f59a6">Your Website</var> \
|
||||
<br><var class="tag" id="field:56e90745f5934fc9e22028a6">Your Age</var></p>';
|
||||
|
||||
var actualRenderedTemplate = emailNotifications.replaceTemplateVal('56340745f59a6fc9e22028e9', validFieldDict['56340745f59a6fc9e22028e9'], htmlTemplate, constants.varFormat).replace((/ |\r\n|\n|\r|\t/gm),'');
|
||||
actualRenderedTemplate.should.equal(expectedHtml.replace((/ |\r\n|\n|\r|\t/gm),''));
|
||||
});
|
||||
});
|
||||
|
||||
describe('Method send', function() {
|
||||
this.timeout(10000);
|
||||
const emailSettings = {
|
||||
fromEmails: 'somewhere@somewhere.com',
|
||||
toEmails: 'there@there.com',
|
||||
subject: 'Hello <var class="tag" id="field:56340745f59a6fc9e22028e9">First Name</var>!',
|
||||
subject: 'Hello <span class="placeholder-tag" data-id="56340745f59a6fc9e22028e9">First Name</span>!',
|
||||
htmlTemplate: htmlTemplate
|
||||
};
|
||||
|
||||
const emailTemplateVars = validFieldDict;
|
||||
const varFormat = constants.varFormat;
|
||||
|
||||
it('should properly replace a template var in a valid template', function(done) {
|
||||
emailNotifications.send(emailSettings, emailTemplateVars, mockTransport, varFormat, function(err){
|
||||
emailNotifications.send(emailSettings, emailTemplateVars, mockTransport, function(err){
|
||||
should.not.exist(err);
|
||||
done();
|
||||
});
|
||||
|
|
|
@ -16,7 +16,7 @@
|
|||
|
||||
<div class="form-group row">
|
||||
<div class="col-xs-7 field-title">
|
||||
{{ 'FIRST_NAME_LABEL' | translate }}
|
||||
<h4>{{ 'FIRST_NAME_LABEL' | translate }}</h4>
|
||||
</div>
|
||||
<div class="col-xs-12 field-input">
|
||||
<input type="text" id="firstName" name="firstName" class="form-control" data-ng-model="user.firstName" ng-pattern="/^[\w0-9 \-.]*$/">
|
||||
|
@ -24,7 +24,7 @@
|
|||
</div>
|
||||
<div class="form-group row">
|
||||
<div class="col-xs-7 field-title">
|
||||
{{ 'LAST_NAME_LABEL' | translate }}
|
||||
<h4>{{ 'LAST_NAME_LABEL' | translate }}</h4>
|
||||
</div>
|
||||
<div class="col-xs-12 field-input">
|
||||
<input type="text" id="lastName" name="lastName" class="form-control" data-ng-model="user.lastName" ng-pattern="/^[\w0-9 \-.]*$/">
|
||||
|
@ -53,7 +53,7 @@
|
|||
|
||||
<div class="row form-group">
|
||||
<div class="col-xs-7 field-title">
|
||||
{{ 'USERNAME_LABEL' | translate }}
|
||||
<h4>{{ 'USERNAME_LABEL' | translate }}</h4>
|
||||
</div>
|
||||
<div class="col-xs-12 field-input">
|
||||
<input type="text" id="username" name="username" class="form-control" data-ng-model="user.username">
|
||||
|
@ -62,7 +62,7 @@
|
|||
|
||||
<div class="row form-group">
|
||||
<div class="col-xs-7 field-title">
|
||||
{{ 'EMAIL_LABEL' | translate }}
|
||||
<h4>{{ 'EMAIL_LABEL' | translate }}</h4>
|
||||
</div>
|
||||
<div class="col-xs-12 field-input">
|
||||
<input type="email" id="email" name="email" class="form-control" data-ng-model="user.email">
|
||||
|
|
Loading…
Reference in a new issue