diff --git a/packages/component-email-templating/src/EmailTemplate.js b/packages/component-email-templating/src/EmailTemplate.js index 2cdb7982e8dc14d2c887ac868ece8937c695b95f..0887072c95cc482a2e3eee39c21d39fe27af2dd5 100644 --- a/packages/component-email-templating/src/EmailTemplate.js +++ b/packages/component-email-templating/src/EmailTemplate.js @@ -1,5 +1,5 @@ const config = require('config') -const helpers = require('./helpers') +const htmlTemplateService = require('./HTMLTemplateService') const SendEmail = require('@pubsweet/component-send-email') const logger = require('@pubsweet/logger') @@ -54,7 +54,7 @@ class EmailTemplate { _getInvitationBody({ emailBodyProps }) { return { - html: helpers.getCompiledInvitationBody({ + html: htmlTemplateService.getCompiledInvitationBody({ replacements: { ...configData, ...this.content, @@ -71,7 +71,7 @@ class EmailTemplate { _getNotificationBody({ emailBodyProps }) { return { - html: helpers.getCompiledNotificationBody({ + html: htmlTemplateService.getCompiledNotificationBody({ replacements: { ...configData, ...this.content, diff --git a/packages/component-email-templating/src/helpers.js b/packages/component-email-templating/src/HTMLTemplateService.js similarity index 90% rename from packages/component-email-templating/src/helpers.js rename to packages/component-email-templating/src/HTMLTemplateService.js index 8df0e7950b1093bd8df9e03fa096f48d26232644..6dc314521e5533c7fda4166de3726ee3c5c21980 100644 --- a/packages/component-email-templating/src/helpers.js +++ b/packages/component-email-templating/src/HTMLTemplateService.js @@ -24,14 +24,7 @@ const getCompiledInvitationBody = ({ replacements }) => { return compileBody({ fileName: 'invitation', context: replacements }) } -const readFile = path => - fs.readFileSync(path, { encoding: 'utf-8' }, (err, file) => { - if (err) { - throw err - } else { - return file - } - }) +const readFile = path => fs.readFileSync(path, 'utf-8') const handlePartial = (partialName, context = {}) => { let partial = readFile(`${__dirname}/templates/partials/${partialName}.hbs`) diff --git a/packages/component-email-templating/tests/helpers.test.js b/packages/component-email-templating/tests/helpers.test.js index e655ec191cf012021e8de5ba690c88b0b5afbf38..f30ddf90902d5e14c49acf54dbae54c566b588f5 100644 --- a/packages/component-email-templating/tests/helpers.test.js +++ b/packages/component-email-templating/tests/helpers.test.js @@ -2,7 +2,7 @@ process.env.NODE_TLS_REJECT_UNAUTHORIZED = '0' process.env.SUPPRESS_NO_CONFIG_WARNING = true const { cloneDeep } = require('lodash') -const helpers = require('../src/helpers') +const htmlTemplateService = require('../src/HTMLTemplateService') const emailProps = { toUserName: 'Peter Griffin', @@ -19,7 +19,7 @@ describe('Email template helpers', () => { replacements = cloneDeep(emailProps) }) it('should return the notification HTML with CTA', () => { - const notificationBody = helpers.getCompiledNotificationBody({ + const notificationBody = htmlTemplateService.getCompiledNotificationBody({ replacements, }) @@ -32,7 +32,7 @@ describe('Email template helpers', () => { it('should return the notification HTML without CTA', () => { replacements.hasLink = false - const notificationBody = helpers.getCompiledNotificationBody({ + const notificationBody = htmlTemplateService.getCompiledNotificationBody({ replacements, }) expect(notificationBody).toContain('Peter Griffin') @@ -41,7 +41,7 @@ describe('Email template helpers', () => { }) it('should return the notification HTML without intro', () => { replacements.hasIntro = false - const notificationBody = helpers.getCompiledNotificationBody({ + const notificationBody = htmlTemplateService.getCompiledNotificationBody({ replacements, }) expect(notificationBody).not.toContain('Peter Griffin') @@ -50,7 +50,7 @@ describe('Email template helpers', () => { }) it('should return the notification HTML without signature', () => { replacements.hasSignature = false - const notificationBody = helpers.getCompiledNotificationBody({ + const notificationBody = htmlTemplateService.getCompiledNotificationBody({ replacements, }) expect(notificationBody).toContain('Peter Griffin')