Guest cap $5 -> $2: GUEST_BUDGET default, emails, docs, tests

This commit is contained in:
inference-bot committed 2026-11-08 20:12:47 +00:00
1 parent 0f12c63f5e
commit 6be8e2d632
6 files changed
+45 -45

No files matched your search

+9 -9
View File
@@ -112,7 +112,7 @@ m.listmonk_sync = rec_listmonk
m.send_email = rec_email
def seed_gift(conn, email, active=1, credits=5.0, balance=0.0):
def seed_gift(conn, email, active=1, credits=2.0, balance=0.0):
conn.execute(
"INSERT INTO members (email, key_token, cloudron_user_id, slug, active, "
"balance, credit_balance, account_type, guest_expires_at) "
@@ -160,11 +160,11 @@ def main():
# --- 3-8. the full cancel flow ------------------------------------------
conn = m.get_db()
seed_gift(conn, "invited@x.org", active=1, credits=5.0)
seed_gift(conn, "invited@x.org", active=1, credits=2.0)
# the grant row production writes at provisioning (add_credits on the
# guest reference) — the return is audited against it
conn.execute("INSERT INTO credit_ledger (email, delta, reason, reference) "
"VALUES ('invited@x.org', 5.0, 'guest account — $5 credit from a member', "
"VALUES ('invited@x.org', 2.0, 'guest account — $2 credit from a member', "
"'guest:invited@x.org')")
conn.commit()
conn.close()
@@ -186,9 +186,9 @@ def main():
led = ledger_rows(conn, "invited@x.org")
grants = [r for r in led if r[2] == "guest:invited@x.org"]
returns = [r for r in led if r[2] == "guest-return:invited@x.org"]
check("cancel: ledger holds the $5 grant and ONE negative return row",
len(grants) == 1 and grants[0][0] == 5.0 and len(returns) == 1
and returns[0][0] == -5.0, str(led))
check("cancel: ledger holds the $2 grant and ONE negative return row",
len(grants) == 1 and grants[0][0] == 2.0 and len(returns) == 1
and returns[0][0] == -2.0, str(led))
check("cancel: return reason names the cancellation and the guest reference",
len(returns) == 1 and "cancelled by recipient" in returns[0][1]
and "guest:invited@x.org" in returns[0][1], str(returns))
@@ -198,7 +198,7 @@ def main():
g and g[0] == "member-one@x.org" and g[1] == "invited@x.org"
and g[2] == "cancelled by recipient", str(g))
check("cancel: result reports the returned amount",
out.get("status") == "cancelled" and out.get("credits_returned") == 5.0, str(out))
out.get("status") == "cancelled" and out.get("credits_returned") == 2.0, str(out))
conn.close()
# --- 9. idempotence: the second cancel is a no-op -----------------------
@@ -260,11 +260,11 @@ def main():
}
check("status: cancelled guest reads ended + cancelled + amount returned",
st_cancelled["ended"] and st_cancelled["cancelled"]
and st_cancelled["credits_returned"] == 5.0, str(st_cancelled))
and st_cancelled["credits_returned"] == 2.0, str(st_cancelled))
# live guest: active with remaining credits
conn = m.get_db()
seed_gift(conn, "live@x.org", active=1, credits=5.0)
seed_gift(conn, "live@x.org", active=1, credits=2.0)
conn.commit()
conn.close()
st_live = {