From 38c173e311b698fc2612383ca80d740843d98b2d Mon Sep 17 00:00:00 2001
From: Andrei Cioromila <andrei.cioromila@thinslices.com>
Date: Tue, 30 Oct 2018 12:22:26 +0200
Subject: [PATCH] feat(email-templating): Rename helpers file to be more
 specific: htmlTemplateService

---
 .../component-email-templating/src/EmailTemplate.js    |  6 +++---
 .../src/{helpers.js => HTMLTemplateService.js}         |  9 +--------
 .../component-email-templating/tests/helpers.test.js   | 10 +++++-----
 3 files changed, 9 insertions(+), 16 deletions(-)
 rename packages/component-email-templating/src/{helpers.js => HTMLTemplateService.js} (90%)

diff --git a/packages/component-email-templating/src/EmailTemplate.js b/packages/component-email-templating/src/EmailTemplate.js
index 2cdb7982e..0887072c9 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 8df0e7950..6dc314521 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 e655ec191..f30ddf909 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')
-- 
GitLab