Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update emails to point to new Grant Details page #2705

Merged
merged 11 commits into from
Mar 8, 2024
15 changes: 15 additions & 0 deletions packages/server/__tests__/email/email.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -417,6 +417,21 @@ describe('Email sender', () => {
expect(body).to.include(name);
expect(body).to.include(moment(openDate).format('MMMM Do YYYY'));
});
it('links to Grants.gov when Grant Details page is not live', async () => {
const agencies = await db.getAgency(fixtures.agencies.accountancy.id);
const agency = agencies[0];
agency.matched_grants = [fixtures.grants.healthAide];
const body = await email.buildDigestBody({ name: 'Saved search test', openDate: '2021-08-05', matchedGrants: agency.matched_grants });
expect(body).to.include(`https://www.grants.gov/search-results-detail/${fixtures.grants.healthAide.grant_id}`.replaceAll('/', '/'));
});
it('links to Grant Finder when Grant Details page is live', async () => {
process.env.NEW_GRANT_DETAILS_PAGE_ENABLED = 'true';
const agencies = await db.getAgency(fixtures.agencies.accountancy.id);
const agency = agencies[0];
agency.matched_grants = [fixtures.grants.healthAide];
const body = await email.buildDigestBody({ name: 'Saved search test', openDate: '2021-08-05', matchedGrants: agency.matched_grants });
expect(body).to.include(`${process.env.WEBSITE_DOMAIN}/grant/${fixtures.grants.healthAide.grant_id}`.replaceAll('/', '/'));
});
});
context('getAndSendGrantForSavedSearch', () => {
it('Sends an email for a saved search', async () => {
Expand Down
32 changes: 25 additions & 7 deletions packages/server/src/lib/email.js
Original file line number Diff line number Diff line change
Expand Up @@ -152,10 +152,17 @@ function sendWelcomeEmail(email, httpOrigin) {
});
}

function getGrantDetail(grant, emailNotificationType) {
const grantDetailTemplate = fileSystem.readFileSync(path.join(__dirname, '../static/email_templates/_grant_detail.html'));
function buildGrantDetailUrl(grantId, emailNotificationType) {
const grantDetailUrl = new URL(process.env.WEBSITE_DOMAIN);
grantDetailUrl.pathname = `grant/${grantId}`;
grantDetailUrl.searchParams.set('utm_source', 'usdr-grants');
grantDetailUrl.searchParams.set('utm_medium', 'email');
grantDetailUrl.searchParams.set('utm_campaign', emailNotificationType);
grantDetailUrl.searchParams.set('utm_content', 'grant-details');
return grantDetailUrl;
}

const description = grant.description.substring(0, 380).replace(/(<([^>]+)>)/ig, '');
function buildGrantsUrl(emailNotificationType) {
const grantsUrl = new URL(process.env.WEBSITE_DOMAIN);
if (emailNotificationType === notificationType.grantDigest) {
grantsUrl.pathname = 'grants';
Expand All @@ -165,6 +172,12 @@ function getGrantDetail(grant, emailNotificationType) {
grantsUrl.searchParams.set('utm_source', 'subscription');
grantsUrl.searchParams.set('utm_medium', 'email');
grantsUrl.searchParams.set('utm_campaign', emailNotificationType);
return grantsUrl;
}

function getGrantDetail(grant, emailNotificationType) {
const grantDetailTemplate = fileSystem.readFileSync(path.join(__dirname, '../static/email_templates/_grant_detail.html'));
const description = grant.description.substring(0, 380).replace(/(<([^>]+)>)/ig, '');
const grantDetail = mustache.render(
grantDetailTemplate.toString(), {
title: grant.title,
Expand All @@ -177,8 +190,13 @@ function getGrantDetail(grant, emailNotificationType) {
award_ceiling: grant.award_ceiling || 'Not available',
// estimated_funding: grant.estimated_funding, TODO: add once field is available in the database.
cost_sharing: grant.cost_sharing,
link_url: `https://www.grants.gov/search-results-detail/${grant.grant_id}`,
grants_url: grantsUrl.toString(),
link_url: process.env.NEW_GRANT_DETAILS_PAGE_ENABLED === 'true'
? buildGrantDetailUrl(grant.grant_id, notificationType).toString()
: `https://www.grants.gov/search-results-detail/${grant.grant_id}`,
link_description: process.env.NEW_GRANT_DETAILS_PAGE_ENABLED === 'true'
? 'Grant Finder'
: 'Grants.gov',
grants_url: buildGrantsUrl(notificationType).toString(),
view_grant_label: emailNotificationType === notificationType.grantDigest ? undefined : 'View My Grants',
},
);
Expand Down Expand Up @@ -218,10 +236,10 @@ async function sendGrantAssignedNotficationForAgency(assignee_agency, grantDetai
// TODO: add plain text version of the email
const emailPlain = emailHTML.replace(/<[^>]+>/g, '');
const emailSubject = `Grant Assigned to ${assignee_agency.name}`;
const assginees = await db.getSubscribersForNotification(assignee_agency.id, notificationType.grantAssignment);
const assignees = await db.getSubscribersForNotification(assignee_agency.id, notificationType.grantAssignment);

const inputs = [];
assginees.forEach((assignee) => inputs.push(
assignees.forEach((assignee) => inputs.push(
Comment on lines -221 to +242
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Good catch 🎩

{
toAddress: assignee.email,
emailHTML,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@
style="Margin:0;padding-bottom:16px;">
<p
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:24px;color:#000000;font-size:16px">
{{{description}}}<span>... View on <a style="color:#0068D6;text-decoration:none;" href="{{link_url}}">Grants.gov</a></span>
{{{description}}}<span>... View on <a style="color:#0068D6;text-decoration:none;" href="{{link_url}}">{{ link_description }}</a></span>
TylerHendrickson marked this conversation as resolved.
Show resolved Hide resolved
</p>
</td>
</tr>
Expand Down
3 changes: 3 additions & 0 deletions terraform/prod.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,9 @@ api_log_retention_in_days = 30
api_datadog_environment_variables = {
DD_PROFILING_ENABLED = true,
}
api_container_environment = {
NEW_GRANT_DETAILS_PAGE_ENABLED = false,
}

// Postgres
postgres_enabled = true
Expand Down
3 changes: 3 additions & 0 deletions terraform/staging.tfvars
Original file line number Diff line number Diff line change
Expand Up @@ -66,6 +66,9 @@ api_log_retention_in_days = 14
api_datadog_environment_variables = {
DD_PROFILING_ENABLED = true,
}
api_container_environment = {
NEW_GRANT_DETAILS_PAGE_ENABLED = true,
}

// Postgres
postgres_enabled = true
Expand Down
Loading