From 995e94f7f570c59fba8baff08f6207f7df11c75c Mon Sep 17 00:00:00 2001 From: David Baldwynn Date: Wed, 15 Nov 2017 11:43:36 -0800 Subject: [PATCH] fixed send email tests --- .../libs/send-email-notifications.test.js | 38 +++++++------------ .../settings/edit-profile.client.view.html | 8 ++-- 2 files changed, 17 insertions(+), 29 deletions(-) diff --git a/app/tests/libs/send-email-notifications.test.js b/app/tests/libs/send-email-notifications.test.js index 10f8d98f..9f9db698 100644 --- a/app/tests/libs/send-email-notifications.test.js +++ b/app/tests/libs/send-email-notifications.test.js @@ -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 = '

First Name \ -
Your Website \ -
Your Age

'; +const htmlTemplate = '

First Name'+ + '
Your Website'+ + '
Your Age

'; -const renderedTemplate = '

John Smith \ -
https://johnsmith.me \ -
45

'; +const renderedTemplate = '

John Smith
https://johnsmith.me
45

'; /** * 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 = '

John Smith \ -
Your Website \ -
Your Age

'; - - 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 First Name!', + subject: 'Hello First Name!', 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(); }); diff --git a/public/modules/users/views/settings/edit-profile.client.view.html b/public/modules/users/views/settings/edit-profile.client.view.html index 8a6a635b..d7840c48 100755 --- a/public/modules/users/views/settings/edit-profile.client.view.html +++ b/public/modules/users/views/settings/edit-profile.client.view.html @@ -16,7 +16,7 @@
- {{ 'FIRST_NAME_LABEL' | translate }} +

{{ 'FIRST_NAME_LABEL' | translate }}

@@ -24,7 +24,7 @@
- {{ 'LAST_NAME_LABEL' | translate }} +

{{ 'LAST_NAME_LABEL' | translate }}

@@ -53,7 +53,7 @@
- {{ 'USERNAME_LABEL' | translate }} +

{{ 'USERNAME_LABEL' | translate }}

@@ -62,7 +62,7 @@
- {{ 'EMAIL_LABEL' | translate }} +

{{ 'EMAIL_LABEL' | translate }}