Skip to content

Commit

Permalink
Merge pull request #5480 from mozilla/MNTOR-3919-2
Browse files Browse the repository at this point in the history
MNTOR-3919: getting setter for churn email state (Part 2)
  • Loading branch information
mansaj authored Jan 13, 2025
2 parents 178f115 + 9d7c486 commit 536da05
Showing 1 changed file with 41 additions and 0 deletions.
41 changes: 41 additions & 0 deletions src/db/tables/subscribers.ts
Original file line number Diff line number Diff line change
Expand Up @@ -551,6 +551,33 @@ async function markFirstDataBrokerRemovalFixedEmailAsJustSent(
}

/* c8 ignore stop */

// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */
async function markChurnPreventionEmailAsJustSent(
subscriberId: SubscriberRow["id"],
) {
const affectedSubscribers = await knex("subscribers")
.update({
// @ts-ignore knex.fn.now() results in it being set to a date,
// even if it's not typed as a JS date object:
churn_prevention_email_sent_at: knex.fn.now(),
// @ts-ignore knex.fn.now() results in it being set to a date,
// even if it's not typed as a JS date object:
updated_at: knex.fn.now(),
})
.where("id", subscriberId)
.returning("*");

if (affectedSubscribers.length !== 1) {
throw new Error(
`Attempted to mark 1 user as having just been sent the churn prevention email, but instead found [${affectedSubscribers.length}] matching its ID.`,
);
}
}

/* c8 ignore stop */

// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */
async function markMonthlyActivityPlusEmailAsJustSent(
Expand Down Expand Up @@ -669,6 +696,18 @@ async function isSubscriberPlus(subscriberId: SubscriberRow["id"]) {
}
/* c8 ignore stop */

// Not covered by tests; mostly side-effects. See test-coverage.md#mock-heavy
/* c8 ignore start */
async function getChurnPreventionEmailSentAt(
subscriberId: SubscriberRow["id"],
) {
const res = await knex("subscribers")
.select("churn_prevention_email_sent_at")
.where("id", subscriberId);
return res?.[0]?.["churn_prevention_email_sent_at"] ?? null;
}
/* c8 ignore stop */

export {
getOnerepProfileId,
getSubscribersByHashes,
Expand All @@ -685,6 +724,7 @@ export {
getPotentialSubscribersWaitingForFirstDataBrokerRemovalFixedEmail,
getFreeSubscribersWaitingForMonthlyEmail,
getPlusSubscribersWaitingForMonthlyEmail,
markChurnPreventionEmailAsJustSent,
markFirstDataBrokerRemovalFixedEmailAsJustSent,
markMonthlyActivityPlusEmailAsJustSent,
deleteUnverifiedSubscribers,
Expand All @@ -693,6 +733,7 @@ export {
deleteOnerepProfileId,
incrementSignInCountForEligibleFreeUser,
getSignInCount,
getChurnPreventionEmailSentAt,
unresolveAllBreaches,
isSubscriberPlus,
knex as knexSubscribers,
Expand Down

0 comments on commit 536da05

Please sign in to comment.