test(account): 补权益配额/用量归属真后端 e2e(UsageStats,account 面收口)

GET /account/entitlements(套餐/配额/发布能力)+ /account/usage(Token 用量/归属分布)
此前无专门 e2e(live-read 仅断言 nickname、未覆盖 UsageStats);curl 证两端 code:0 就绪。
补 account-usage.spec.ts(验 200/code:0 + 「权益与配额」/「归属分布」区块渲染)。
全量 e2e 41/0。至此个人中心 account 面真后端 e2e 全闭环(profile 读写 + 权益配额 +
用量归属 + 购买/授权/发布三件套 + 安全事件 ack)。

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
This commit is contained in:
lili 2026-06-21 13:31:00 -07:00
parent fd52b4660a
commit 1dbbfc78b5

View File

@ -0,0 +1,57 @@
import { expect, test, type Page } from '@playwright/test';
/**
* / (UsageStats )e2e(,MSW off)
*
* 前置:vite VITE_API_MOCK=false muse-server 48080
* 目的:验个人中心 UsageStats GET /account/entitlements(///)
* + GET /account/usage(Token //),
* 反假绿:live-read.spec profile nickname UsageStats, e2e
* (),(200/code:0)
*/
const TOKEN = 'test1';
async function seedToken(page: Page): Promise<void> {
await page.addInitScript((t) => {
window.localStorage.setItem('accessToken', t);
window.localStorage.setItem('tenantId', '1');
}, TOKEN);
}
test('账户中心展示权益与配额(真实后端)', async ({ page }) => {
await seedToken(page);
// 进个人中心,捕获真实权益/配额读响应(打真后端,非 mock)。
const [resp] = await Promise.all([
page.waitForResponse(
(r) => /\/account\/entitlements/.test(r.url()) && r.request().method() === 'GET',
{ timeout: 15_000 }
),
page.goto('/account'),
]);
expect(resp.status()).toBe(200);
expect((await resp.json()).code).toBe(0);
// UsageStats「权益与配额」区(套餐/配额/发布能力)渲染。
await expect(page.getByRole('heading', { name: '权益与配额' })).toBeVisible({ timeout: 15_000 });
});
test('账户中心展示用量归属分布(真实后端)', async ({ page }) => {
await seedToken(page);
// 进个人中心,捕获真实用量读响应(打真后端,非 mock)。
const [resp] = await Promise.all([
page.waitForResponse(
(r) => /\/account\/usage/.test(r.url()) && r.request().method() === 'GET',
{ timeout: 15_000 }
),
page.goto('/account'),
]);
expect(resp.status()).toBe(200);
expect((await resp.json()).code).toBe(0);
// UsageStats「归属分布」区(按归属维度的 Token 用量)渲染。
await expect(page.getByRole('heading', { name: '归属分布' })).toBeVisible({ timeout: 15_000 });
});