Files
Jyotisha/frontend/tests/admin-payments-contract.test.ts
T
linmeng 1b8d6fcce6
Staging Backend Quality Gate (push the reviewed main SHA to staging to auto-deploy) / validate (push) Failing after 5m10s
Staging Backend Quality Gate (push the reviewed main SHA to staging to auto-deploy) / publish-and-deploy (push) Has been skipped
feat: add configurable payments and Gitea staging delivery
Add database-backed administrators, configurable Alipay packages, idempotent payment settlement and platform reporting. Standardize Gitea workflows on the xiaoxin runner so reviewed staging commits are tested, packaged, and deployed by immutable image digest.
2026-07-27 20:19:05 +08:00

39 lines
1.8 KiB
TypeScript

import assert from "node:assert/strict";
import { readFileSync } from "node:fs";
import test from "node:test";
const root = new URL("../", import.meta.url);
const route = readFileSync(new URL("src/app/api/admin/payments/route.ts", root), "utf8");
const page = readFileSync(new URL("src/app/admin/payments/page.tsx", root), "utf8");
const packagesPage = readFileSync(new URL("src/app/admin/packages/page.tsx", root), "utf8");
const migration = readFileSync(new URL("supabase/migrations/20260727030000_payment_admin_stats.sql", root), "utf8");
test("支付后台接口只允许管理员并查询平台订单", () => {
assert.match(route, /isAdminUser\(user\)/);
assert.match(route, /from\("payment_orders"\)/);
assert.match(route, /auth\.admin\.getUserById/);
assert.match(route, /payment_packages\(name\)/);
assert.match(route, /order_no|orderNo/);
assert.doesNotMatch(route, /SUPABASE_SERVICE_ROLE_KEY/);
assert.doesNotMatch(route, /raw_notify_payload/);
});
test("支付接口包含筛选、统计和分页契约", () => {
for (const field of ["status", "from", "to", "limit", "offset"]) assert.match(route, new RegExp(field));
for (const field of ["totalOrders", "paidOrders", "pendingOrders", "failedExpiredOrders", "paidAmountCents", "grantedCredits"]) assert.match(route, new RegExp(field));
assert.match(route, /max\(100\)/);
assert.match(route, /count: "exact"/);
assert.match(route, /hasMore/);
assert.match(migration, /get_payment_order_stats/);
assert.match(migration, /status = 'paid'/);
});
test("后台支付页面与现有套餐页有入口", () => {
assert.match(page, /平台支付统计/);
assert.match(page, /支付记录/);
assert.match(page, /paidAmountCents/);
assert.match(page, /上一页/);
assert.match(page, /下一页/);
assert.match(packagesPage, /href="\/admin\/payments"/);
});