diff --git a/muse-studio/e2e/account-market-records.spec.ts b/muse-studio/e2e/account-market-records.spec.ts new file mode 100644 index 00000000..fe6b5da3 --- /dev/null +++ b/muse-studio/e2e/account-market-records.spec.ts @@ -0,0 +1,59 @@ +import { expect, test, type Page } from '@playwright/test'; + +/** + * 账户中心「我的购买 / 我的授权」记录 e2e(真实后端,MSW off)。 + * + * 前置:vite VITE_API_MOCK=false、真实 muse-server 48080。 + * 目的:补齐个人中心市场记录三件套之一/之二——购买(GET /account/purchases)、授权(GET /account/licenses), + * 与已有「我的发布」(account-publish-records.spec.ts)同源:三者皆经 AccountMarketRecordService 读 + * muse_account_record_projection 投影表。验真后端读通 + 区块渲染(反假绿)。 + * 不依赖记录条数(投影可空),故只断言契约(200/code:0)与区块存在。 + */ +const TOKEN = 'test1'; + +async function seedToken(page: Page): Promise { + 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\/purchases/.test(r.url()) && r.request().method() === 'GET', + { timeout: 15_000 } + ), + page.goto('/account'), + ]); + + // Yudao 口径:成功为 HTTP 200 + CommonResult{code:0}。 + expect(resp.status()).toBe(200); + expect((await resp.json()).code).toBe(0); + + // 「我的购买」区(市场记录三件套之一)渲染。 + 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\/licenses/.test(r.url()) && r.request().method() === 'GET', + { timeout: 15_000 } + ), + page.goto('/account'), + ]); + + // Yudao 口径:成功为 HTTP 200 + CommonResult{code:0}。 + expect(resp.status()).toBe(200); + expect((await resp.json()).code).toBe(0); + + // 「我的授权」区(市场记录三件套之二)渲染。 + await expect(page.getByRole('heading', { name: '我的授权' })).toBeVisible({ timeout: 15_000 }); +});