The Send-gift control sits in the members-view toolbar: recipient email + name + inviting member (datalist of member emails), proxied to the portal's /admin/provision-gift which enforces the abuse rules and returns clear refusals. Gift rows carry the 'gift' pill in the Source column (inviter + expiry in the tooltip); the pre-built Guests section shows inviter, expiry, credits and ledger status as columns once the portal payload carries account_type.
134 lines
6.9 KiB
JavaScript
134 lines
6.9 KiB
JavaScript
// Harness for the admin panel's GUESTS list (gift accounts), run through the
|
|
// skill's checker alongside the chart harness:
|
|
// ~/.hermes/skills/research/inference-cooperative/scripts/check-page-js.sh \
|
|
// app/main.py admin-panel-guests-harness.js
|
|
// Exercises load() against both payload shapes — the portal's split payload
|
|
// (guests[]) and an older payload that still tags rows account_type='gift'
|
|
// inside members[] — and asserts the invariants that matter:
|
|
// * guests NEVER count as members, in either shape;
|
|
// * guests never render in the members table;
|
|
// * the guests list shows recipient, inviter, credits remaining, expiry
|
|
// and status, and hides entirely when there are no guests;
|
|
// * the Members-view switch rule keeps the section's visibility handled
|
|
// in switchView (the trap that stranded the Admin section on Models).
|
|
// The checker evals in CommonJS (no top-level await), so the body is wrapped.
|
|
const assert = (cond, msg) => { if (!cond) { console.error("FAIL: " + msg); process.exit(1); } };
|
|
const count = (s, re) => (String(s).match(re) || []).length;
|
|
const txt = (id) => String(document.getElementById(id).textContent); // stub keeps raw types; the DOM stringifies
|
|
|
|
const memberRow = (email, spend) => ({
|
|
email, username: email.split("@")[0], active: true, activated: true,
|
|
account_type: "member", spend, all_time_spend: spend * 10,
|
|
balance: 15, credit_balance: 0, credits_remaining: 0, remaining: 15 - spend,
|
|
});
|
|
|
|
async function runLoad(overview) {
|
|
globalThis.fetch = async (url) => ({
|
|
status: 200,
|
|
json: async () => (String(url).indexOf("/api/overview") !== -1 ? overview : { models: [] }),
|
|
});
|
|
await load();
|
|
}
|
|
|
|
(async () => {
|
|
// ---- Shape 1: the portal splits guests into their own list ----
|
|
await runLoad({
|
|
members: [memberRow("alice@example.com", 2), memberRow("bob@example.com", 1)],
|
|
guests: [{
|
|
email: "friend@example.com", username: "friend", active: true,
|
|
account_type: "gift", gift_inviter: "alice@example.com",
|
|
credit_balance: 5, credits_remaining: 3.5,
|
|
gift_expires_at: "2027-01-07T02:00:00", gift_status: "active",
|
|
spend: 1.5, all_time_spend: 1.5,
|
|
}],
|
|
totals: { members: 2, total_spend: 4.5, total_all_time_spend: 45,
|
|
operator_spend: 1, operator_all_time_spend: 10 },
|
|
});
|
|
assert(txt("tot-members") === "2",
|
|
"split payload: member count is 2 (got " + txt("tot-members") + ")");
|
|
assert(txt("tot-guests") === "1",
|
|
"split payload: guests count is 1");
|
|
assert(txt("tot-spend-cycle") === "$4.50",
|
|
"split payload: spend total unchanged by the guests split");
|
|
{
|
|
const rowsHtml = document.getElementById("rows").innerHTML;
|
|
assert(count(rowsHtml, /<tr>/g) === 2, "members table holds only the 2 members");
|
|
assert(rowsHtml.indexOf("friend@example.com") === -1, "guest never renders in the members table");
|
|
const g = document.getElementById("guest-rows").innerHTML;
|
|
assert(count(g, /<tr>/g) === 1, "guests list holds exactly the 1 guest");
|
|
assert(g.indexOf("friend@example.com") !== -1, "recipient email shown");
|
|
assert(g.indexOf("alice@example.com") !== -1, "inviting member shown from the ledger");
|
|
assert(g.indexOf("$3.50") !== -1, "credits remaining shown");
|
|
assert(g.indexOf("2027-01-07") !== -1, "time-box expiry date shown");
|
|
assert(/pill active[^>]*>active</.test(g), "status pill shows active");
|
|
assert(document.getElementById("guests-section").style.display === "",
|
|
"guests section visible when guests exist");
|
|
}
|
|
switchView("models");
|
|
assert(document.getElementById("guests-section").style.display === "none",
|
|
"guests section hides on the Models view (switchView owns visibility)");
|
|
switchView("members");
|
|
assert(document.getElementById("guests-section").style.display === "",
|
|
"guests section returns on the Members view");
|
|
|
|
// ---- Shape 2: older payload — gifts tagged inside members[] ----
|
|
await runLoad({
|
|
members: [
|
|
memberRow("alice@example.com", 2),
|
|
memberRow("bob@example.com", 1),
|
|
{ email: "friend@example.com", username: "friend", active: true,
|
|
account_type: "gift", gift_inviter: "alice@example.com",
|
|
credit_balance: 5, credits_remaining: 3.5, gift_expires_at: "2027-01-07T02:00:00",
|
|
gift_status: "active", spend: 0.5, all_time_spend: 5 },
|
|
],
|
|
totals: { members: 3, total_spend: 3.5, total_all_time_spend: 35,
|
|
operator_spend: 0, operator_all_time_spend: 0 },
|
|
});
|
|
assert(txt("tot-members") === "2",
|
|
"old payload: gift row subtracted from the member count (got " + txt("tot-members") + ")");
|
|
assert(txt("tot-guests") === "1", "old payload: guest derived and counted");
|
|
assert(txt("tot-spend-cycle") === "$3.00",
|
|
"old payload: guest spend excluded from the spend total (3.5 - 0.5)");
|
|
assert(document.getElementById("rows").innerHTML.indexOf("friend@example.com") === -1,
|
|
"old payload: guest still never renders in the members table");
|
|
assert(document.getElementById("guest-rows").innerHTML.indexOf("friend@example.com") !== -1,
|
|
"old payload: guest renders in the guests list");
|
|
|
|
// ---- Status vocabulary: expired and converted keep their own pills ----
|
|
await runLoad({
|
|
members: [memberRow("alice@example.com", 2)],
|
|
guests: [
|
|
{ email: "lapsed@example.com", username: null, active: false, account_type: "gift",
|
|
gift_inviter: "alice@example.com", credit_balance: 2, credits_remaining: 2,
|
|
gift_expires_at: "2026-12-01T00:00:00", gift_status: "expired", spend: 3, all_time_spend: 3 },
|
|
{ email: "joined@example.com", username: "joined", active: true, account_type: "gift",
|
|
gift_inviter: "alice@example.com", credit_balance: 1, credits_remaining: 1,
|
|
gift_expires_at: null, gift_status: "converted", spend: 4, all_time_spend: 4 },
|
|
],
|
|
totals: { members: 1, total_spend: 2, total_all_time_spend: 20,
|
|
operator_spend: 0, operator_all_time_spend: 0 },
|
|
});
|
|
{
|
|
const g = document.getElementById("guest-rows").innerHTML;
|
|
assert(/pill inactive[^>]*>expired</.test(g), "expired status renders as an inactive-class pill");
|
|
assert(/pill org[^>]*>converted</.test(g), "converted status renders as a distinct pill");
|
|
assert(g.indexOf("lapsed@example.com") !== -1, "expired guest still listed (status column carries it)");
|
|
assert(g.indexOf("2026-12-01") !== -1, "expired guest keeps its expiry date");
|
|
}
|
|
|
|
// ---- Empty list: the section disappears entirely ----
|
|
await runLoad({
|
|
members: [memberRow("alice@example.com", 2)],
|
|
guests: [],
|
|
totals: { members: 1, total_spend: 2, total_all_time_spend: 20,
|
|
operator_spend: 0, operator_all_time_spend: 0 },
|
|
});
|
|
assert(document.getElementById("guest-rows").innerHTML === "", "no guests: list is empty");
|
|
assert(document.getElementById("guests-section").style.display === "none",
|
|
"no guests: the section is hidden");
|
|
assert(txt("tot-members") === "1", "no guests: member count is the members alone");
|
|
assert(txt("tot-guests") === "0", "no guests: counter reads 0");
|
|
|
|
console.log("GUESTS HARNESS OK: exclusion, both payload shapes, columns, visibility");
|
|
})().catch((e) => { console.error("FAIL: " + (e && e.stack || e)); process.exit(1); });
|