Skip to content
Snippets Groups Projects
Commit 38c173e3 authored by Andrei Cioromila's avatar Andrei Cioromila
Browse files

feat(email-templating): Rename helpers file to be more specific: htmlTemplateService

parent 650d0270
No related branches found
No related tags found
3 merge requests!160Update staging with master features,!156Develop,!149Hin 1089
const config = require('config') const config = require('config')
const helpers = require('./helpers') const htmlTemplateService = require('./HTMLTemplateService')
const SendEmail = require('@pubsweet/component-send-email') const SendEmail = require('@pubsweet/component-send-email')
const logger = require('@pubsweet/logger') const logger = require('@pubsweet/logger')
...@@ -54,7 +54,7 @@ class EmailTemplate { ...@@ -54,7 +54,7 @@ class EmailTemplate {
_getInvitationBody({ emailBodyProps }) { _getInvitationBody({ emailBodyProps }) {
return { return {
html: helpers.getCompiledInvitationBody({ html: htmlTemplateService.getCompiledInvitationBody({
replacements: { replacements: {
...configData, ...configData,
...this.content, ...this.content,
...@@ -71,7 +71,7 @@ class EmailTemplate { ...@@ -71,7 +71,7 @@ class EmailTemplate {
_getNotificationBody({ emailBodyProps }) { _getNotificationBody({ emailBodyProps }) {
return { return {
html: helpers.getCompiledNotificationBody({ html: htmlTemplateService.getCompiledNotificationBody({
replacements: { replacements: {
...configData, ...configData,
...this.content, ...this.content,
......
...@@ -24,14 +24,7 @@ const getCompiledInvitationBody = ({ replacements }) => { ...@@ -24,14 +24,7 @@ const getCompiledInvitationBody = ({ replacements }) => {
return compileBody({ fileName: 'invitation', context: replacements }) return compileBody({ fileName: 'invitation', context: replacements })
} }
const readFile = path => const readFile = path => fs.readFileSync(path, 'utf-8')
fs.readFileSync(path, { encoding: 'utf-8' }, (err, file) => {
if (err) {
throw err
} else {
return file
}
})
const handlePartial = (partialName, context = {}) => { const handlePartial = (partialName, context = {}) => {
let partial = readFile(`${__dirname}/templates/partials/${partialName}.hbs`) let partial = readFile(`${__dirname}/templates/partials/${partialName}.hbs`)
......
...@@ -2,7 +2,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' ...@@ -2,7 +2,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0'
process.env.SUPPRESS_NO_CONFIG_WARNING = true process.env.SUPPRESS_NO_CONFIG_WARNING = true
const { cloneDeep } = require('lodash') const { cloneDeep } = require('lodash')
const helpers = require('../src/helpers') const htmlTemplateService = require('../src/HTMLTemplateService')
const emailProps = { const emailProps = {
toUserName: 'Peter Griffin', toUserName: 'Peter Griffin',
...@@ -19,7 +19,7 @@ describe('Email template helpers', () => { ...@@ -19,7 +19,7 @@ describe('Email template helpers', () => {
replacements = cloneDeep(emailProps) replacements = cloneDeep(emailProps)
}) })
it('should return the notification HTML with CTA', () => { it('should return the notification HTML with CTA', () => {
const notificationBody = helpers.getCompiledNotificationBody({ const notificationBody = htmlTemplateService.getCompiledNotificationBody({
replacements, replacements,
}) })
...@@ -32,7 +32,7 @@ describe('Email template helpers', () => { ...@@ -32,7 +32,7 @@ describe('Email template helpers', () => {
it('should return the notification HTML without CTA', () => { it('should return the notification HTML without CTA', () => {
replacements.hasLink = false replacements.hasLink = false
const notificationBody = helpers.getCompiledNotificationBody({ const notificationBody = htmlTemplateService.getCompiledNotificationBody({
replacements, replacements,
}) })
expect(notificationBody).toContain('Peter Griffin') expect(notificationBody).toContain('Peter Griffin')
...@@ -41,7 +41,7 @@ describe('Email template helpers', () => { ...@@ -41,7 +41,7 @@ describe('Email template helpers', () => {
}) })
it('should return the notification HTML without intro', () => { it('should return the notification HTML without intro', () => {
replacements.hasIntro = false replacements.hasIntro = false
const notificationBody = helpers.getCompiledNotificationBody({ const notificationBody = htmlTemplateService.getCompiledNotificationBody({
replacements, replacements,
}) })
expect(notificationBody).not.toContain('Peter Griffin') expect(notificationBody).not.toContain('Peter Griffin')
...@@ -50,7 +50,7 @@ describe('Email template helpers', () => { ...@@ -50,7 +50,7 @@ describe('Email template helpers', () => {
}) })
it('should return the notification HTML without signature', () => { it('should return the notification HTML without signature', () => {
replacements.hasSignature = false replacements.hasSignature = false
const notificationBody = helpers.getCompiledNotificationBody({ const notificationBody = htmlTemplateService.getCompiledNotificationBody({
replacements, replacements,
}) })
expect(notificationBody).toContain('Peter Griffin') expect(notificationBody).toContain('Peter Griffin')
......
0% or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment