mirror of
https://github.com/simplex-chat/simplex-chat.git
synced 2026-10-16 00:10:56 +00:00
* badges: webapp (#7433) * badges: service migrations, store and catalog * badges: BTCPay provider and settlement poller * badges: web listener and /api endpoints * web: checkout single-page app * badges: tests and BTCPay fixtures * badges: README and ini reference * badges: fix hex16 build on GHC 8.10.7 * badges: Stripe card lane * badges: fix Stripe card checkout, add theming * badges: add a discount row to the order summary * badges: site navbar, embedding, theme, Forget move * badges: use SB code prefix in web checkout * badges: rename sxb app namespace to sb * badges: embed checkout nav via site; keep original app navbar * badges: post iframe height, apply site background when embedded * badges: embed dark surfaces, steadier iframe height * badges: hide app footer when embedded * badges: size embedded body to content, not viewport * badges: declare color-scheme to stop reload flash * badges: fade shell in on load, no reload blank * badges: prerender app shell into index.html * badges: pre-paint theme, hide shell on deep reload * badges: logo returns to landing client-side * badges: embedded wizard back, buy-a-code, resume * badges: signal app-managed screens, resume across reload * badges: rebuild wizard history on deep load so Back walks it * badges: carry welcome-page height as the iframe floor * badges: keep selection on Buy a code; rename to Your codes * badges: read web shell as UTF-8, not locale * badges: resume the exact paid order after Stripe card redirect * badges: move docker deploy under scripts * badges: add serve_webapp toggle and webapp export * badges: wire split webapp deploy in docker config * badges: quiet agent logs by default * badges: resume card redirect in the embedded frame * badges: migrate Stripe adapter to PaymentIntents * badges: correct Stripe restricted key scopes in ini example * badges: card via Payment Element and PaymentIntents * badges: fix stale Checkout Session wording in Stripe adapter * badges: fix stale CheckoutActions reference in card comment * badges: order shell stylesheet before bootstrap script * badges: remove development card stand-in * badges: theme the Stripe card form with the site palette * badges: exclude web from the Haskell build stage * badges: unify invoice cancel and mark canceled * badges: default log level to info * badges: unify closed-invoice buy-again button * badges: mute agent connection logs at info level * badges: show purchase time in local timezone in Your codes * badges: log service events on own channel, quiet agent * badges: fold service migrations into one baseline * badges: run compose on postgres over host network * badges: use high-res hero art * badges: add web CI to catch stale builds * badges: rebuild web shell from committed source * badges: normalize invoice-code link and columns * badges: drop unused columns, rename index * badges: note deferred receipt_hash in migrations * badges: apply code-review fixes * badges: reduce comments across service and web --------- Co-authored-by: Evgeny Poberezkin <evgeny@poberezkin.com> Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> * badges: improve web page (#7546) * badges: improve web page * improve layout * improve layout * fix * small changes --------- Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> * badges: read one issuer key from the ini * badges: move and group the service tests * badges: service fixes (#7567) * badges: match the redeem error wording in tests * badges: drop unused imports in the bot tests * badges: cancel Stripe orders when they expire * badges: correct the Stripe config and docs * badges: refuse to revoke a redeemed code * badges: make the fake Stripe cancel like Stripe * badges: limit replayed webhook deliveries --------- Co-authored-by: sh <37271604+shumvgolove@users.noreply.github.com> Co-authored-by: Evgeny @ SimpleX Chat <259188159+evgeny-simplex@users.noreply.github.com> Co-authored-by: shum <github.shum@liber.li> Co-authored-by: spaced4ndy <8711996+spaced4ndy@users.noreply.github.com>
136 lines
6.4 KiB
TypeScript
136 lines
6.4 KiB
TypeScript
import assert from "node:assert/strict";
|
|
import { headingOf, installPage, inViewOf, timedTest, until } from "./boot.js";
|
|
import type { StubElement } from "./stub-dom.js";
|
|
|
|
const monthTest = timedTest(2000);
|
|
|
|
const page = installPage();
|
|
const { app, storage, fetches } = page;
|
|
await import("../src/main.js");
|
|
|
|
const SESSION_KEY = "sb.session.v1";
|
|
|
|
const inView = (): StubElement => inViewOf(app);
|
|
const heading = headingOf;
|
|
function continueButton(p: StubElement): StubElement {
|
|
const go = p.all("button.primary")[0];
|
|
assert.ok(go, "the panel must carry a primary button");
|
|
return go;
|
|
}
|
|
function choice(p: StubElement, startsWith: string): StubElement {
|
|
const found = p.all("button.choice").find((c) => c.textContent.startsWith(startsWith));
|
|
assert.ok(found, `no choice card starting with ${startsWith}: ${p.all("button.choice").map((c) => c.textContent).join(" | ")}`);
|
|
return found;
|
|
}
|
|
function session(): Record<string, unknown> {
|
|
return JSON.parse(storage.getItem(SESSION_KEY) ?? "{}") as Record<string, unknown>;
|
|
}
|
|
|
|
function walkToDurations(level: string): StubElement {
|
|
while (heading(inView()) !== "Support SimpleX") inView().all("button.back")[0]!.click();
|
|
continueButton(inView()).click();
|
|
assert.equal(heading(inView()), "Choose your badge");
|
|
choice(inView(), level).click();
|
|
continueButton(inView()).click();
|
|
assert.equal(heading(inView()), "How long?");
|
|
return inView();
|
|
}
|
|
|
|
// ------------------------------------------------------------------ selection
|
|
|
|
monthTest("main: choosing 1 month marks that card and ENABLES Continue", () => {
|
|
const durations = walkToDurations("Supporter");
|
|
const one = choice(durations, "1 month");
|
|
assert.deepEqual(
|
|
durations.all("button.choice").map((c) => c.getAttribute("aria-pressed")),
|
|
["false", "false", "false"],
|
|
"nothing is chosen before the click",
|
|
);
|
|
assert.ok(continueButton(durations).hasAttribute("disabled"), "and Continue waits for an answer");
|
|
|
|
one.click();
|
|
const after = inView();
|
|
assert.equal(choice(after, "1 month").getAttribute("aria-pressed"), "true",
|
|
"the cheapest card must mark itself chosen — the empty string could never do that");
|
|
assert.deepEqual(
|
|
after.all("button.choice").filter((c) => c.getAttribute("aria-pressed") === "true").length, 1,
|
|
"and it is the only one chosen",
|
|
);
|
|
assert.equal(continueButton(after).hasAttribute("disabled"), false,
|
|
"Continue must enable: a buyer who wants one month was otherwise stuck on the duration list with a dead button");
|
|
assert.notEqual(session().offerId, "", "the stored answer is a key of its own, not the empty string");
|
|
});
|
|
|
|
// ----------------------------------------------------------------- clearing
|
|
|
|
monthTest("main: changing the level clears the duration and disables Continue again", () => {
|
|
// The clear is an explicit offerId: undefined that saveSession drops on stringify, not an empty string, which once made "chosen" and "unchosen" the same value.
|
|
const durations = walkToDurations("Legend");
|
|
choice(durations, "12 months").click();
|
|
assert.equal(continueButton(inView()).hasAttribute("disabled"), false);
|
|
assert.equal(session().offerId, "offer_12m");
|
|
|
|
while (heading(inView()) !== "Choose your badge") inView().all("button.back")[0]!.click();
|
|
choice(inView(), "Supporter").click();
|
|
assert.equal("offerId" in session(), false,
|
|
`the stored session must have no offerId at all: ${JSON.stringify(session())}`);
|
|
|
|
continueButton(inView()).click();
|
|
const fresh = inView();
|
|
assert.equal(heading(fresh), "How long?");
|
|
assert.deepEqual(fresh.all("button.choice").map((c) => c.getAttribute("aria-pressed")),
|
|
["false", "false", "false"], "nothing carries over from the level that was abandoned");
|
|
assert.ok(continueButton(fresh).hasAttribute("disabled"), "and the question is asked again");
|
|
});
|
|
|
|
// ------------------------------------------------------------------ upgrades
|
|
|
|
monthTest("main: a session stored by an older build as offerId \"\" loads as nothing chosen", () => {
|
|
// A legacy empty-string offerId is ambiguous, so it is read as "not answered" rather than stranding the buyer on a Continue that never enables.
|
|
storage.setItem(SESSION_KEY, JSON.stringify({ step: "months", priceId: "price_legend", offerId: "" }));
|
|
while (heading(inView()) !== "Support SimpleX") inView().all("button.back")[0]!.click();
|
|
continueButton(inView()).click();
|
|
continueButton(inView()).click();
|
|
const durations = inView();
|
|
assert.equal(heading(durations), "How long?");
|
|
assert.deepEqual(durations.all("button.choice").map((c) => c.getAttribute("aria-pressed")),
|
|
["false", "false", "false"], "the legacy value marks no card");
|
|
assert.ok(continueButton(durations).hasAttribute("disabled"));
|
|
|
|
choice(durations, "1 month").click();
|
|
assert.equal(continueButton(inView()).hasAttribute("disabled"), false);
|
|
});
|
|
|
|
// ---------------------------------------------------------------- the charge
|
|
|
|
// This test runs last because paying takes the wizard off the root with no way back to it.
|
|
monthTest("main: paying for one month sends NO offerId, and one month's price", async () => {
|
|
// The one-month offer names no row in CATALOG.offers, so offerId is omitted; sending the sentinel would come back catalog_changed.
|
|
const durations = walkToDurations("Supporter");
|
|
choice(durations, "1 month").click();
|
|
continueButton(inView()).click();
|
|
const orderSummary = inView();
|
|
assert.equal(heading(orderSummary), "Check your order");
|
|
assert.ok(orderSummary.textContent.includes("1 month"), `the order summary must summarise one month: ${orderSummary.textContent}`);
|
|
assert.ok(orderSummary.textContent.includes("$7.00"),
|
|
"one supporter month is 700 minor units, which is what the buyer is shown and charged");
|
|
|
|
const before = fetches.length;
|
|
page.respondWith({
|
|
status: 200,
|
|
body: {
|
|
invoiceId: "inv_1m", badgeType: "supporter", months: 1,
|
|
amount: 700, currency: "usd", expiresAt: "2026-08-28T13:00:00Z",
|
|
address: "48HqK2Xm", cryptoAmount: "0.02", cryptoCurrency: "xmr",
|
|
},
|
|
});
|
|
orderSummary.all("button.primary")[0]!.click();
|
|
await until(() => fetches.length > before, "the invoice request");
|
|
const sent = fetches.find((f) => f.url.includes("/api/invoice"))!;
|
|
const body = JSON.parse(String(sent.init!.body)) as Record<string, unknown>;
|
|
assert.equal(body.priceId, "price_supporter");
|
|
assert.equal("offerId" in body, false,
|
|
`a one-month order carries no offerId at all, and got: ${JSON.stringify(body)}`);
|
|
assert.equal(body.method, "xmr");
|
|
});
|