gift emails: invitation at gift time + once-only reaching-limits notice
- gift_welcome_email becomes gift_invitation_email: the ONE email a gift sends (the invitation and the guest welcome merged, not two mails at once). Subject 'You've been invited to the Inference Cooperative'; names the inviter (member slug), the $5 credits, the setup link, the Become-a-member button on BECOME_MEMBER_URL. Uses the shared PINE_LOGO_SVG instead of an inline copy. - reaching-limits email (gift_limits_email, 'Your guest access has ended — become a member to continue') wired into the sweep's gift deactivation: sent once per guest, gated by a gift_lapse_notices sent-state row (same pattern as mark_shortfall_notice_sent). Says the access ended, the account and data are kept, and membership ($15/mo via Open Collective) restores a full monthly allowance + community spaces. - catch-up pass in reconcile_gift_lifecycles: guests deactivated before the email shipped (or a failed send) get exactly one notice on a later sweep; converted guests are excluded by account_type. - sweep summary now reports gift_lapse_notices. - test_gift_lifecycle: invitation-subject assertion; send_email stub returns True (the bool is the gate's contract); new once-only + catch-up + healthy-untouched checks. 43/43.
This commit is contained in:
1 parent
0bc3cd65e7
commit
0b0bdaab6f
2 files changed
+263
-39
No files matched your search
@@ -87,8 +87,9 @@ async def rec_pin(team_id, reset_at):
|
||||
calls["pin"].append((team_id, str(reset_at)))
|
||||
|
||||
|
||||
def rec_email(to, subject, text_body, html_body=None):
|
||||
def rec_email(to, subject, text_body=None, html_body=None):
|
||||
calls["email"].append((to, subject))
|
||||
return True # send_email's contract: truthy = the send left the building
|
||||
|
||||
|
||||
async def rec_listmonk(email, subscribe):
|
||||
@@ -242,8 +243,8 @@ def main():
|
||||
calls["group"] and calls["group"][0][1] == m.GUESTS_GROUP_ID, str(calls["group"]))
|
||||
check("provision: cap set to 5.00 (one-time)",
|
||||
(calls["budget"] and calls["budget"][0][1] == 5.0), str(calls["budget"]))
|
||||
check("provision: welcome email sent",
|
||||
any("gifted access" in s for _, s in calls["email"]), str(calls["email"]))
|
||||
check("provision: invitation email sent (merged invite + welcome)",
|
||||
any("invited to the Inference Cooperative" in s for _, s in calls["email"]), str(calls["email"]))
|
||||
check("provision: newsletter subscribed",
|
||||
("gifted@x.org", True) in calls["listmonk"], str(calls["listmonk"]))
|
||||
check("provision: NO loomio/matrix calls", calls["loomio"] == 0 and calls["matrix"] == 0)
|
||||
@@ -288,9 +289,14 @@ def main():
|
||||
credits=5.0, anchor=8, expires=future)
|
||||
seed_member(conn, "depleted@x.org", account_type="gift", active=1, balance=0.0,
|
||||
credits=5.0, anchor=8, expires=future)
|
||||
for e in ("expired@x.org", "healthy@x.org", "depleted@x.org"):
|
||||
# A guest whose gift ended BEFORE the reaching-limits email shipped: the
|
||||
# sweep's catch-up pass must tell them exactly once.
|
||||
seed_member(conn, "already-gone@x.org", account_type="gift", active=0, balance=0.0,
|
||||
credits=5.0, anchor=8, expires=past)
|
||||
for e in ("expired@x.org", "healthy@x.org", "depleted@x.org", "already-gone@x.org"):
|
||||
conn.execute("INSERT INTO gifts (inviter_email, recipient_email, gift_expires_at, status) "
|
||||
"VALUES (?, ?, ?, 'active')", (inviter, e, future))
|
||||
conn.execute("UPDATE gifts SET status = 'expired' WHERE recipient_email = 'already-gone@x.org'")
|
||||
conn.commit()
|
||||
conn.close()
|
||||
|
||||
@@ -315,6 +321,16 @@ def main():
|
||||
not any(e == "uid-healthy@x.org" for e, _ in calls["group"]))
|
||||
check("lifecycle: counts report expired=1 depleted=0",
|
||||
out.get("expired") == 1 and out.get("depleted") == 0, str(out))
|
||||
check("lifecycle: reaching-limits email sent once to the expired guest",
|
||||
sum(1 for to, s in calls["email"]
|
||||
if to == "expired@x.org" and "guest access has ended" in s) == 1,
|
||||
str(calls["email"]))
|
||||
check("lifecycle: catch-up told the pre-shutdown guest exactly once",
|
||||
sum(1 for to, s in calls["email"]
|
||||
if to == "already-gone@x.org" and "guest access has ended" in s) == 1,
|
||||
str(calls["email"]))
|
||||
check("lifecycle: notice counts in the sweep result",
|
||||
out.get("lapse_notices") == 2, str(out))
|
||||
conn.close()
|
||||
|
||||
TEAM_SPEND["team-depleted@x.org"] = 5.5 # depleted: spend reached the credits
|
||||
@@ -329,6 +345,17 @@ def main():
|
||||
check("lifecycle: healthy gift STILL untouched on second pass",
|
||||
row_of(conn, "healthy@x.org", "active") == 1)
|
||||
check("lifecycle: counts report depleted=1", out.get("depleted") == 1, str(out))
|
||||
check("lifecycle: depleted guest also told once",
|
||||
sum(1 for to, s in calls["email"]
|
||||
if to == "depleted@x.org" and "guest access has ended" in s) == 1,
|
||||
str(calls["email"]))
|
||||
check("lifecycle: ONCE per guest — second sweep sent no repeat notices",
|
||||
sum(1 for to, s in calls["email"] if "guest access has ended" in s) == 1
|
||||
and m.gift_lapse_notice_sent("expired@x.org")
|
||||
and m.gift_lapse_notice_sent("already-gone@x.org"),
|
||||
str(calls["email"]))
|
||||
check("lifecycle: healthy guest never emailed",
|
||||
not any(to == "healthy@x.org" for to, _ in calls["email"]), str(calls["email"]))
|
||||
conn.close()
|
||||
|
||||
failed = [r for r in results if not r[1]]
|
||||
|
||||
Reference in new issue
Block a user