diff --git a/packages/server/__tests__/db/seeds/fixtures.js b/packages/server/__tests__/db/seeds/fixtures.js index ee3c303a1..8f0a93a97 100644 --- a/packages/server/__tests__/db/seeds/fixtures.js +++ b/packages/server/__tests__/db/seeds/fixtures.js @@ -117,7 +117,7 @@ const grants = { search_terms: '[in title/desc]+', reviewer_name: 'none', opportunity_category: 'Discretionary', - description: '

The Division of Earth Sciences (EAR) awards Postdoctoral Fellowships

', + description: 'The Division of Earth Sciences (EAR) awards Postdoctoral Fellowships', eligibility_codes: '25', opportunity_status: 'posted', raw_body: 'raw body', @@ -141,7 +141,7 @@ const grants = { search_terms: '[in title/desc]+', reviewer_name: 'none', opportunity_category: 'Discretionary', - description: '

Health Aide Program for Covid

', + description: ' Health Aide Program for Covid', eligibility_codes: '11 07 25', opportunity_status: 'posted', raw_body: 'raw body', @@ -165,7 +165,7 @@ const grants = { search_terms: '[in title/desc]+', reviewer_name: 'none', opportunity_category: 'Discretionary', - description: '

The Tactical Technology Office (TTO) of the Defense Advanced Research Projects Agency (DARPA)

', + description: 'The Tactical Technology Office (TTO) of the Defense Advanced Research Projects Agency (DARPA)', eligibility_codes: '11', opportunity_status: 'posted', raw_body: 'raw body', diff --git a/packages/server/__tests__/email/email.test.js b/packages/server/__tests__/email/email.test.js index 625baca46..e58c1be56 100644 --- a/packages/server/__tests__/email/email.test.js +++ b/packages/server/__tests__/email/email.test.js @@ -364,13 +364,15 @@ describe('Email sender', () => { const agencies = await db.getAgency(fixtures.agencies.accountancy.id); const agency = agencies[0]; agency.matched_grants = [fixtures.grants.healthAide]; - const body = await email.buildDigestBody(agency.matched_grants); + const body = await email.buildDigestBody({ name: 'Saved search test', openDate: '2021-08-05', matchedGrants: agency.matched_grants }); expect(body).to.include(fixtures.grants.healthAide.description); }); it('builds only first 3 grants if >3 available', async () => { const agencies = await db.getAgency(fixtures.agencies.accountancy.id); const agency = agencies[0]; const ignoredGrant = { ...fixtures.grants.healthAide }; + const name = 'Saved search test'; + const openDate = moment().subtract(1, 'day').format('YYYY-MM-DD'); ignoredGrant.description = 'Added a brand new description'; const updateFn = (int) => { @@ -380,7 +382,7 @@ describe('Email sender', () => { }; const additionalGrants = [...Array(30).keys()].map(updateFn); agency.matched_grants = [...additionalGrants, ...[fixtures.grants.healthAide, fixtures.grants.earFellowship, fixtures.grants.redefiningPossible]]; - const body = await email.buildDigestBody(agency.matched_grants); + const body = await email.buildDigestBody({ name, openDate, matchedGrants: agency.matched_grants }); /* the last 3 grants should not be included in the email */ expect(body).to.not.include(fixtures.grants.healthAide.description); @@ -389,6 +391,8 @@ describe('Email sender', () => { /* the first 30 grants should be included in the email */ additionalGrants.forEach((grant) => expect(body).to.include(grant.description)); + expect(body).to.include(name); + expect(body).to.include(moment(openDate).format('MMMM Do YYYY')); }); }); context('getAndSendGrantForSavedSearch', () => { diff --git a/packages/server/src/lib/email.js b/packages/server/src/lib/email.js index ec9a070ea..dea324cb4 100644 --- a/packages/server/src/lib/email.js +++ b/packages/server/src/lib/email.js @@ -117,10 +117,14 @@ function sendWelcomeEmail(email, httpOrigin) { function getGrantDetail(grant, emailNotificationType) { const grantDetailTemplate = fileSystem.readFileSync(path.join(__dirname, '../static/email_templates/_grant_detail.html')); + + const shortDescription = grant.description?.length > 380 ? grant.description.substring(0, 380) : grant.description; + const description = shortDescription.replace(/<\/?p[^>]*>/g, ''); + const grantDetail = mustache.render( grantDetailTemplate.toString(), { title: grant.title, - description: grant.description && grant.description.length > 400 ? `${grant.description.substring(0, 400)}...` : grant.description, + description, status: grant.opportunity_status, show_date_range: grant.open_date && grant.close_date, open_date: grant.open_date ? new Date(grant.open_date).toLocaleDateString('en-US', { timeZone: 'UTC' }) : undefined, @@ -193,7 +197,7 @@ async function sendGrantAssignedEmail({ grantId, agencyIds, userId }) { agencies.forEach((agency) => module.exports.sendGrantAssignedNotficationForAgency(agency, grantDetail, userId)); } -async function buildDigestBody(matchedGrants) { +async function buildDigestBody({ name, openDate, matchedGrants }) { const grantDetails = []; matchedGrants.slice(0, 30).forEach((grant) => grantDetails.push(module.exports.getGrantDetail(grant, notificationType.grantDigest))); @@ -201,14 +205,14 @@ async function buildDigestBody(matchedGrants) { const contentSpacerTemplate = fileSystem.readFileSync(path.join(__dirname, '../static/email_templates/_content_spacer.html')); const contentSpacerStr = contentSpacerTemplate.toString(); - let additionalBody = grantDetails.join(contentSpacerStr); + let additionalBody = grantDetails.join(contentSpacerStr).concat(contentSpacerStr); const additionalButtonTemplate = fileSystem.readFileSync(path.join(__dirname, '../static/email_templates/_additional_grants_button.html')); additionalBody += mustache.render(additionalButtonTemplate.toString(), { additional_grants_url: `${process.env.WEBSITE_DOMAIN}/#/grants` }); const formattedBody = mustache.render(formattedBodyTemplate.toString(), { - body_title: 'New grants have been posted', - body_detail: `There are ${matchedGrants.length} new grants matching your keywords and settings.`, + body_title: `${name} - ${matchedGrants.length} NEW GRANTS`, + body_detail: moment(openDate).format('MMMM Do YYYY'), additional_body: additionalBody, }); @@ -230,10 +234,10 @@ async function sendGrantDigest({ return; } - const formattedBody = await buildDigestBody(matchedGrants); + const formattedBody = await buildDigestBody({ name, openDate, matchedGrants }); const emailHTML = module.exports.addBaseBranding(formattedBody, { - tool_name: 'Grants Identification Tool', + tool_name: 'Federal Grant Finder', title: 'New Grants Digest', notifications_url: `${process.env.WEBSITE_DOMAIN}/#/grants?manageSettings=true`, }); diff --git a/packages/server/src/static/email_templates/_additional_grants_button.html b/packages/server/src/static/email_templates/_additional_grants_button.html index 40333acc4..4b6f1209f 100644 --- a/packages/server/src/static/email_templates/_additional_grants_button.html +++ b/packages/server/src/static/email_templates/_additional_grants_button.html @@ -1,13 +1,13 @@ -
+ diff --git a/packages/server/src/static/email_templates/_content_spacer.html b/packages/server/src/static/email_templates/_content_spacer.html index 31a297a6d..404d54d57 100644 --- a/packages/server/src/static/email_templates/_content_spacer.html +++ b/packages/server/src/static/email_templates/_content_spacer.html @@ -1,11 +1,11 @@
+ style="padding:0;Margin:0;padding-top:28px;padding-bottom:28px;padding-left:20px;padding-right:20px"> @@ -17,22 +17,25 @@ role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px"> - +
- - See - all new grants - - +
+ + See all new grants + + +
+
-
+ - + style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px;background-color:#f6f6f6;width:640px" + cellspacing="0" cellpadding="0" bgcolor="#f6f6f6" align="center"> +
+ style="padding:0;Margin:0;background:#FFFFFF none repeat scroll 0% 0%;height:1px;width:100%;margin:0px">
diff --git a/packages/server/src/static/email_templates/_formatted_body.html b/packages/server/src/static/email_templates/_formatted_body.html index d3b5246d1..bb171ab4f 100644 --- a/packages/server/src/static/email_templates/_formatted_body.html +++ b/packages/server/src/static/email_templates/_formatted_body.html @@ -1,12 +1,12 @@ -
+ -
+ @@ -15,19 +15,19 @@ style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px"> {{#body_title}} - {{/body_title}} {{#body_detail}} - diff --git a/packages/server/src/static/email_templates/_grant_detail.html b/packages/server/src/static/email_templates/_grant_detail.html index 31ad24e34..ede16230e 100644 --- a/packages/server/src/static/email_templates/_grant_detail.html +++ b/packages/server/src/static/email_templates/_grant_detail.html @@ -1,7 +1,7 @@
+

- {{body_title}} + style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:normal;letter-spacing: 1px; text-transform: uppercase; color:#000000;font-size:14px"> + {{body_title}}

+

+ style="Margin:0;-webkit-text-size-adjust:none;-ms-text-size-adjust:none;mso-line-height-rule:exactly;font-family:arial, 'helvetica neue', helvetica, sans-serif;line-height:normal;letter-spacing: 1px;color:#43464A;font-size:14px"> {{{body_detail}}}

-
+ @@ -13,57 +13,45 @@
- - - - - diff --git a/packages/server/src/static/email_templates/base.html b/packages/server/src/static/email_templates/base.html index 08e55a1c5..116d004a6 100644 --- a/packages/server/src/static/email_templates/base.html +++ b/packages/server/src/static/email_templates/base.html @@ -388,15 +388,15 @@
-

+

+ +

{{title}}

+
+

- {{{description}}} + {{{description}}}... View on Grants.gov

- - - - -
-
-
+ style="Margin:0">

- Status: {{status}}
+ Status: {{status}}
{{#show_date_range}} - Valid from: {{open_date}} - {{close_date}}
+ Valid From: {{open_date}} - {{close_date}}
{{/show_date_range}} - Award Range: {{award_floor}} – {{award_ceiling}}
+ Award Range: {{award_floor}} - {{award_ceiling}}
{{#estimated_funding}} - Estimated Total Program Funding:{{estimated_funding}}
+ Estimated Total Program Funding: {{estimated_funding}}
{{/estimated_funding}} {{#cost_sharing}} - Cost Sharing:{{cost_sharing}}
+ Cost Sharing: {{cost_sharing}}
{{/cost_sharing}} - View in Grants.gov

-
- +
- @@ -476,11 +473,11 @@
+ style="padding:0;Margin:0;font-size:0px">
+ + style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px;background-color:#F6F6F6;width:640px" + cellspacing="0" cellpadding="0" bgcolor="#F6F6F6" align="center"> -
@@ -458,9 +458,6 @@ cellpadding="0" border="0" role="presentation" style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px">
-
+ style="mso-table-lspace:0pt;mso-table-rspace:0pt;border-collapse:collapse;border-spacing:0px;table-layout:fixed !important;width:100%;background-color:#F0F0F0;background-repeat:repeat;background-position:center top">