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 @@+ |
|