taler-typescript-core

Wallet core logic and WebUIs for various components
Log | Files | Refs | Submodules | README | LICENSE

commit cdf370a57faa47660a42844a4f24aeb537177f77
parent e0ffc5d245a62380c46f12f0936e7f38476083b0
Author: Florian Dold <dold@taler.net>
Date:   Mon, 23 Nov 2026 17:35:46 +0100

harness: exercise fountain management and pagination in Chromium

Diffstat:
Apackages/taler-harness/src/integrationtests/test-merchant-webui-fountains.ts | 448+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
Mpackages/taler-harness/src/integrationtests/testrunner.ts | 6++++++
2 files changed, 454 insertions(+), 0 deletions(-)

diff --git a/packages/taler-harness/src/integrationtests/test-merchant-webui-fountains.ts b/packages/taler-harness/src/integrationtests/test-merchant-webui-fountains.ts @@ -0,0 +1,448 @@ +/* + This file is part of GNU Taler + (C) 2026 Taler Systems S.A. + + GNU Taler is free software; you can redistribute it and/or modify it under the + terms of the GNU General Public License as published by the Free Software + Foundation; either version 3, or (at your option) any later version. + + GNU Taler is distributed in the hope that it will be useful, but WITHOUT ANY + WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR + A PARTICULAR PURPOSE. See the GNU General Public License for more details. + + You should have received a copy of the GNU General Public License along with + GNU Taler; see the file COPYING. If not, see <http://www.gnu.org/licenses/> + */ + +import assert from "node:assert/strict"; +import { readFileSync } from "node:fs"; +import { + AbsoluteTime, + Duration, + LibtoolVersion, + Result, + succeedOrThrow, + TalerProtocolTimestamp, + TalerUriAction, + TalerUris, + TokenFamilyKind, +} from "@gnu-taler/taler-util"; +import { WalletApiOperation } from "@gnu-taler/taler-wallet-core"; +import type { GlobalTestState } from "../harness/harness.js"; +import { assertNoUnexpectedErrorBanner } from "../harness/merchant-webui-browser.js"; +import { withMerchantPortal } from "./merchant-webui-environment.js"; + +/** Create in the portal, import in a real wallet, edit and revoke in the portal. */ +export async function runMerchantWebuiFountainsTest(t: GlobalTestState) { + await withMerchantPortal( + t, + async ({ api, token, walletClient, webuiUrl, page }) => { + for (const kind of [ + TokenFamilyKind.Discount, + TokenFamilyKind.Subscription, + ]) { + succeedOrThrow( + await api.createTokenFamily(token, { + kind, + slug: kind, + name: kind, + description: kind, + valid_after: TalerProtocolTimestamp.now(), + valid_before: AbsoluteTime.toProtocolTimestamp( + AbsoluteTime.addDuration( + AbsoluteTime.now(), + Duration.fromSpec({ days: 30 }), + ), + ), + duration: { d_us: 86400_000_000 }, + validity_granularity: { d_us: 86400_000_000 }, + }), + ); + } + const sidebar = page.getByRole("complementary"); + assert.equal( + await sidebar + .getByRole("link", { name: "Fountains", exact: true }) + .count(), + 0, + ); + await page.goto(`${webuiUrl}#/personalization`); + const enableFountains = page.getByLabel("Enable fountains", { + exact: true, + }); + assert.equal(await enableFountains.count(), 0); + await page.getByLabel("Show advanced tools").check(); + assert.equal(await enableFountains.isChecked(), false); + await page.getByRole("button", { name: "Save preferences" }).click(); + await page.goto(`${webuiUrl}#/fountains/new`); + await page + .getByRole("main") + .getByRole("link", { name: "Personalization" }) + .click(); + await enableFountains.check(); + await page.getByRole("button", { name: "Save preferences" }).click(); + await page.reload(); + await sidebar + .getByRole("link", { name: "Fountains", exact: true }) + .click(); + await page + .getByText( + "No fountains yet. Create one to distribute discounts or passes.", + ) + .waitFor(); + await page + .getByRole("button", { name: "Create fountain", exact: true }) + .click(); + await page + .getByLabel("Description", { exact: true }) + .fill("Campus promotion"); + const named = LibtoolVersion.isCompatible( + succeedOrThrow(await api.getConfig()).version, + "46:0:0", + ); + if (named) + await page.getByLabel("Name", { exact: true }).fill("Campus benefits"); + for (const [index, kind] of [ + TokenFamilyKind.Discount, + TokenFamilyKind.Subscription, + ].entries()) { + await page + .getByRole("button", { name: "Add grant", exact: true }) + .click(); + await page.locator(`#fountain-family-${index}`).selectOption(kind); + await page + .locator(`#fountain-tokens_per_period_limit-${index}`) + .fill("3"); + await page + .locator(`#fountain-tokens_per_period_stash-${index}`) + .fill("2"); + await page.locator(`#fountain-key_window_size-${index}`).fill("1"); + } + await page.evaluate(() => (globalThis as any).scrollTo(0, 0)); + await page.screenshot({ + path: `${t.testDir}/fountain-form-desktop.png`, + fullPage: true, + }); + await page.setViewportSize({ width: 390, height: 844 }); + await page.evaluate(() => (globalThis as any).scrollTo(0, 0)); + await page.screenshot({ + path: `${t.testDir}/fountain-form-mobile.png`, + fullPage: true, + }); + assert.ok( + await page.evaluate( + () => + (globalThis as any).document.documentElement.scrollWidth <= + (globalThis as any).innerWidth, + ), + ); + const invalidStash = page.locator("#fountain-tokens_per_period_stash-1"); + await invalidStash.fill("4"); + await page + .getByRole("button", { name: "Create fountain", exact: true }) + .click(); + await page + .getByText("The stocking target must not exceed the per-period limit.") + .waitFor(); + assert.ok( + await invalidStash.evaluate( + (el: any) => + el === el.ownerDocument.activeElement && + el.getBoundingClientRect().top >= 0 && + el.getBoundingClientRect().top < + el.ownerDocument.defaultView.innerHeight, + ), + ); + assert.equal(await invalidStash.getAttribute("aria-invalid"), "true"); + await invalidStash.fill("2"); + // A failed list refresh must not discard a successful creation's one-time code. + const listPath = /\/private\/fountains(?:\?.*)?$/; + await page.route(listPath, async (route) => { + if (route.request().method() !== "GET") return route.continue(); + return route.fulfill({ + status: 503, + contentType: "application/json", + body: JSON.stringify({ code: 1 }), + }); + }); + await Promise.all([ + page.waitForResponse( + (response) => + new URL(response.url()).pathname.endsWith("/private/fountains") && + response.status() === 503, + ), + page + .getByRole("button", { name: "Create fountain", exact: true }) + .click(), + ]); + await page + .getByRole("heading", { name: "Fountain created", exact: true }) + .waitFor(); + await page.unroute(listPath); + const uri = await page + .getByLabel("Wallet import URI", { exact: true }) + .innerText(); + const parsed = Result.orUndefined( + TalerUris.parseRestricted(uri, TalerUriAction.Fountain), + ); + assert.ok(parsed); + await page + .getByRole("img", { name: "Fountain import QR code" }) + .waitFor(); + await page + .getByRole("button", { name: "Copy URI", exact: true }) + .waitFor(); + assert.equal(await page.locator("a[download]").count(), 2); + await page.evaluate(() => (globalThis as any).scrollTo(0, 0)); + await page.screenshot({ + path: `${t.testDir}/fountain-created-mobile.png`, + fullPage: true, + }); + assert.ok( + await page.evaluate( + () => + (globalThis as any).document.documentElement.scrollWidth <= + (globalThis as any).innerWidth, + ), + ); + const persisted = await page.evaluate(() => { + const w = globalThis as any; + return JSON.stringify([ + w.localStorage, + w.sessionStorage, + w.location.href, + w.history.state, + ]); + }); + assert.ok(!persisted.includes(parsed.fountainSecret)); + const imported = await walletClient.call( + WalletApiOperation.ImportFountain, + { talerFountainUri: uri }, + ); + await walletClient.call(WalletApiOperation.RefreshFountain, { + fountainId: imported.fountainId, + }); + assert.equal( + (await walletClient.call(WalletApiOperation.ListDiscounts, {})) + .discounts[0]?.tokensAvailable, + 2, + ); + assert.equal( + (await walletClient.call(WalletApiOperation.ListSubscriptions, {})) + .subscriptions.length, + 1, + ); + await page + .getByRole("button", { name: "I have saved it — Done", exact: true }) + .click(); + await page + .getByRole("heading", { name: "Campus promotion", exact: true }) + .waitFor(); + assert.ok( + !(await page.locator("body").innerText()).includes( + parsed.fountainSecret, + ), + ); + await page.reload(); + await page + .getByRole("button", { name: "Edit fountain", exact: true }) + .click(); + await page + .getByLabel("Description", { exact: true }) + .fill("Campus updated"); + if (named) + await page.getByLabel("Name", { exact: true }).fill("Campus rewards"); + await page.locator("#fountain-tokens_per_period_stash-0").fill("3"); + await page + .getByRole("button", { name: "Save changes", exact: true }) + .click(); + await page + .getByRole("heading", { name: "Campus updated", exact: true }) + .waitFor(); + const details = succeedOrThrow( + await api.getFountainDetails(token, parsed.fountainId), + ); + assert.equal(details.description, "Campus updated"); + if (named) assert.equal(details.name, "Campus rewards"); + assert.equal(details.grants[0].tokens_per_period_stash, 3); + await walletClient.call(WalletApiOperation.RefreshFountain, { + fountainId: imported.fountainId, + }); + assert.equal( + (await walletClient.call(WalletApiOperation.ListDiscounts, {})) + .discounts[0]?.tokensAvailable, + 3, + ); + await page.goto(`${webuiUrl}#/fountains`); + await page.getByRole("button", { name: "Delete", exact: true }).click(); + const revoke = page.getByRole("dialog"); + assert.ok( + await revoke + .getByRole("button", { name: "Cancel" }) + .evaluate((el: any) => el === el.ownerDocument.activeElement), + ); + assert.ok( + await revoke + .getByRole("button", { name: "Delete fountain" }) + .isDisabled(), + ); + const idInput = revoke.getByLabel( + "Enter the fountain ID to confirm deletion.", + ); + await idInput.fill("incorrect"); + assert.ok( + await revoke + .getByRole("button", { name: "Delete fountain" }) + .isDisabled(), + ); + await page + .context() + .grantPermissions(["clipboard-read", "clipboard-write"]); + await page.evaluate( + (id: string) => (globalThis as any).navigator.clipboard.writeText(id), + parsed.fountainId, + ); + await idInput.press("Control+a"); + await idInput.press("Control+v"); + await page + .getByRole("button", { name: "Delete fountain", exact: true }) + .click(); + await page + .getByText( + "No fountains yet. Create one to distribute discounts or passes.", + ) + .waitFor(); + assert.equal( + succeedOrThrow(await api.listFountains(token)).fountains.length, + 0, + ); + assert.equal( + ( + await walletClient.call(WalletApiOperation.RefreshFountain, { + fountainId: imported.fountainId, + }) + ).status, + "revoked", + ); + await assertNoUnexpectedErrorBanner(page); + assert.ok( + !readFileSync(`${t.testDir}/wallet-wallet-stderr.log`, "utf8").includes( + parsed.fountainSecret, + ), + ); + }, + ); +} +runMerchantWebuiFountainsTest.suites = ["web", "merchant", "merchant-webui"]; +runMerchantWebuiFountainsTest.timeoutMs = 120_000; + +export async function runMerchantWebuiFountainPagesTest(t: GlobalTestState) { + await withMerchantPortal(t, async ({ api, token, page, webuiUrl }) => { + await page.goto(`${webuiUrl}#/personalization`); + await page.getByLabel("Show advanced tools").check(); + await page.getByLabel("Enable fountains", { exact: true }).check(); + await page.getByRole("button", { name: "Save preferences" }).click(); + const created: { fountain_id: string; description: string }[] = []; + const seedTo = async (size: number) => { + while (created.length < size) { + const description = `Campaign ${created.length + 1}`; + const { fountain_id } = succeedOrThrow( + await api.createFountain(token, { + description, + name: `Promotion ${created.length + 1}`, + poll_freq: { d_us: 3600_000_000 }, + grants: [], + }), + ); + created.push({ fountain_id, description }); + } + }; + const next = page.getByRole("button", { name: "Next", exact: true }); + const previous = page.getByRole("button", { + name: "Previous", + exact: true, + }); + const campaign = (number: number) => + page.getByRole("link", { name: `Campaign ${number}`, exact: true }); + const rows = page.getByRole("main").getByRole("listitem"); + await page.goto(`${webuiUrl}#/fountains`); + await page.getByText(/No fountains yet/).waitFor(); + await seedTo(20); + await page.reload(); + await campaign(20).waitFor(); + assert.equal(await rows.count(), 20); + assert.equal(await next.count(), 0); + await seedTo(21); + await page.reload(); + await next.click(); + await campaign(1).waitFor(); + assert.equal(await rows.count(), 1); + assert.ok(await next.isDisabled()); + await previous.click(); + await campaign(21).waitFor(); + await seedTo(41); + await page.reload(); + await campaign(41).waitFor(); + const laterPages = /\/private\/fountains\?[^/]*offset=/; + await page.route(laterPages, (r) => + r.fulfill({ status: 503, json: { code: 1 } }), + ); + await next.click(); + await page.getByText("Could not load fountains").waitFor(); + await campaign(41).waitFor(); + await page.unroute(laterPages); + await page.getByRole("button", { name: "Refresh", exact: true }).click(); + await campaign(21).waitFor(); + assert.equal(await rows.count(), 20); + await next.click(); + await campaign(1).click(); + await page + .getByRole("heading", { name: "Campaign 1", exact: true }) + .waitFor(); + await page.goBack(); + await page.getByText("Page 3", { exact: true }).waitFor(); + assert.equal(await rows.count(), 1); + await page.getByRole("button", { name: "Delete", exact: true }).click(); + await page + .getByLabel("Enter the fountain ID to confirm deletion.") + .fill(created[0].fountain_id); + await page + .getByRole("button", { name: "Delete fountain", exact: true }) + .click(); + await page.getByText("Page 2", { exact: true }).waitFor(); + await campaign(21).waitFor(); + assert.equal(await rows.count(), 20); + assert.ok(await next.isDisabled()); + await previous.click(); + await campaign(41).waitFor(); + + // v43 has no cursor or ordering guarantee. Page the full response locally. + await page.route("**/config", async (route) => { + const response = await route.fetch(); + await route.fulfill({ + response, + json: { ...(await response.json()), version: "43:0:31" }, + }); + }); + let requests = 0; + await page.route(/\/private\/fountains(?:\?.*)?$/, (route) => { + requests++; + assert.equal(new URL(route.request().url()).search, ""); + return route.fulfill({ json: { fountains: created } }); + }); + await page.reload(); + await campaign(41).waitFor(); + await next.click(); + await campaign(21).waitFor(); + await next.click(); + await campaign(1).waitFor(); + assert.equal(requests, 1); + await assertNoUnexpectedErrorBanner(page); + }); +} +runMerchantWebuiFountainPagesTest.suites = [ + "web", + "merchant", + "merchant-webui", +]; +runMerchantWebuiFountainPagesTest.timeoutMs = 120_000; diff --git a/packages/taler-harness/src/integrationtests/testrunner.ts b/packages/taler-harness/src/integrationtests/testrunner.ts @@ -332,6 +332,10 @@ import { } from "./test-merchant-webui-mfa.js"; import { runMerchantWebuiKycSwapTest } from "./test-merchant-webui-kyc-swap.js"; import { runMerchantWebuiBootstrapTest } from "./test-merchant-webui-bootstrap.js"; +import { + runMerchantWebuiFountainsTest, + runMerchantWebuiFountainPagesTest, +} from "./test-merchant-webui-fountains.js"; import { runMerchantWebuiChallengeDevicesTest } from "./test-merchant-webui-challenge-devices.js"; import { runMerchantWebuiSimpleTest } from "./test-merchant-webui-simple.js"; import { runWireMetadataTest } from "./test-wire-metadata.js"; @@ -532,6 +536,8 @@ const allTests: TestMainFunction[] = [ runMerchantWebuiPasswordResetMfaTest, runMerchantWebuiKycSwapTest, runMerchantWebuiSimpleTest, + runMerchantWebuiFountainsTest, + runMerchantWebuiFountainPagesTest, runMerchantWebuiChallengeDevicesTest, runMerchantSelfProvisionInactiveAccountPermissionsTest, runWithdrawalExternalTest,