Files
Jyotisha/frontend/tests/admin-payments-contract.test.ts
T
ClaudeandClaude Fable 5.2 936ece8b50
Independent Staging Quality Gate / validate-python (push) Successful in 9m1s
Independent Staging Quality Gate / validate-frontend (push) Successful in 11m11s
Independent Staging Quality Gate / publish (push) Failing after 1m19s
fix: admin page stays above the phone keyboard; room for the menu button (BUG-1916)
The admin shell is its own scroller at full screen height, so the keyboard
hid the field being typed into and the page could not scroll far enough.
While the keyboard is open the shell takes the visible height and the
focused field is scrolled into view.

Co-Authored-By: Claude Fable 5.2 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01DbBXp2Vp62Ur3C7yRWQdSq
2026-11-16 02:59:31 +08:00

74 lines
4.7 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 packagesRoute = readFileSync(new URL("src/app/api/admin/packages/route.ts", root), "utf8");
const paymentPage = 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 paymentManagement = readFileSync(new URL("src/components/admin/payment-management.tsx", root), "utf8");
const adminApp = readFileSync(new URL("src/components/admin/admin-app.tsx", root), "utf8");
const globalsCss = readFileSync(new URL("src/app/globals.css", root), "utf8");
test("支付后台接口使用 self-hosted PostgreSQL 联表且不依赖 Supabase builder", () => {
assert.match(route, /requirePermission\("billing\.orders\.read"\)/);
assert.match(route, /queryAdminRows<PaymentOrderRow>/);
assert.match(route, /from public\.payment_orders o/);
assert.match(route, /left join public\.payment_packages p on p\.id = o\.package_id/);
assert.match(route, /left join identity\.users u on u\.id = o\.user_id/);
assert.match(route, /count\(\*\) over\(\)::text as total_count/);
assert.match(route, /order by o\.created_at desc, o\.order_no asc/);
assert.doesNotMatch(route, /createAdminSupabaseClient|auth\.admin|\.from\(|\.range\(|count: "exact"/);
assert.doesNotMatch(route, /userId|user_id:|raw_notify_payload|SUPABASE_SERVICE_ROLE_KEY/);
});
test("支付接口使用参数化筛选、独立日期统计与 ISO 日期输出", () => {
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, /\$\$\{values\.length\}/);
assert.match(route, /statsValues/);
assert.match(route, /created_at\.toISOString\(\)/);
assert.match(route, /paid_at\?\.toISOString\(\) \?\? null/);
assert.match(route, /支付记录服务暂时不可用/);
assert.match(route, /hasMore/);
});
test("支付管理页只保留概览、默认折叠的 Z-Pay 配置与支付记录", () => {
assert.match(paymentPage, /PaymentManagement/);
for (const component of ["List", "Card", "Collapse", "Table", "Form", "Tag", "Alert", "Statistic"]) assert.match(paymentManagement, new RegExp(`\\b${component}\\b`));
assert.match(paymentManagement, /支付概览/);
assert.match(paymentManagement, /<Collapse[\s\S]*defaultActiveKey=\{\[\]\}[\s\S]*label: "Z-Pay(易支付)渠道配置"/);
assert.match(paymentManagement, /children: \([\s\S]*测试可用性(当前已保存配置)[\s\S]*保存配置[\s\S]*<Form<EpaySettingsForm>/);
assert.match(paymentManagement, /支付记录/);
assert.match(paymentManagement, /\/api\/admin\/payments/);
assert.doesNotMatch(paymentManagement, /套餐列表|套餐设置|添加套餐|\/api\/admin\/packages|PackageManagement/);
});
test("统一商品资源进入导航且旧套餐 API 明确跳转", () => {
assert.match(adminApp, /name: "products", list: "\/admin\/products"[\s\S]*name: "subscriptions"/);
assert.match(adminApp, /ShoppingOutlined/);
assert.match(packagesPage, /PackageManagement/);
assert.match(packagesRoute, /NextResponse\.redirect\(new URL\(replacement, request\.url\), 308\)/);
});
test("旧套餐写 API 已删除,不再假成功写脱节表", () => {
assert.doesNotMatch(packagesRoute, /payment_packages|queryAdminRows|insert into|update public/);
for (const method of ["POST", "PATCH", "DELETE"]) {
assert.match(packagesRoute, new RegExp(`export function ${method}\\(\\)`));
}
assert.match(packagesRoute, /status: 410/);
assert.match(packagesRoute, /replacement/);
});
test("后台使用独立的全视口纵向滚动容器而不修改全局聊天溢出边界", () => {
// 原值:/<div className="admin-app-shell">/;新值:带 ref(键盘弹出时缩短外壳);原因:BUG-1916。
assert.match(adminApp, /<div className="admin-app-shell" ref=\{shellRef\}>[\s\S]*<ConfigProvider/);
assert.match(globalsCss, /html, body \{[^}]*overflow: hidden;/);
// BUG-698: vh base, dvh upgrade behind a feature query (see viewport-unit-fallback-contract).
assert.match(globalsCss, /\.admin-app-shell \{ height: 100vh; min-height: 0; overflow-y: auto; \}/);
assert.match(globalsCss, /@supports \(height: 1dvh\)[\s\S]*?\.admin-app-shell \{ height: 100dvh; \}/);
assert.match(globalsCss, /\.admin-app-shell > \*, \.admin-app-shell \.ant-layout \{ min-height: 100%; \}/);
});