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:
parent
fd52b4660a
commit
1dbbfc78b5
57
muse-studio/e2e/account-usage.spec.ts
Normal file
57
muse-studio/e2e/account-usage.spec.ts
Normal 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 });
|
||||
});
|
||||
Loading…
x
Reference in New Issue
Block a user