Files
huike-e2e-moicen/tests/core-full-chain.spec.ts
T
weli d85027a933 feat(e2e): 核心全链路用例与辅助模块
新增 smoke-http、core-full-chain(访客深链守卫、登录黄金路径、可选健康 URL);抽出 music-room-session 辅助;Playwright 忽略本地 admin_debug;CI 注入可选 MOICEN_HEALTHCHECK_URL。

Made-with: Cursor
2026-04-28 11:53:48 +08:00

86 lines
3.0 KiB
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { expect, test } from './fixtures';
import {
decodeJwtPayload,
establishSession,
extractOrgIdFromTokenPayload,
resolveOrgContextForCoursePage,
waitForCourseRealmVisible,
} from './helpers/music-room-session';
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
/** 可选:仓库 Variables `MOICEN_HEALTHCHECK_URL`(如 `https://api.example/health`),未配置则 skip */
const moicenHealthcheckUrl = process.env.MOICEN_HEALTHCHECK_URL?.trim();
test.describe('核心全链路(访客)', () => {
/**
* `main.ts`:未带 Registered 链时访问非 `/`、`/guest/*` 会 replace 到 `/`,最终应呈现访客占位。
*/
test('未登录深链 /course 最终回到访客首页', async ({ page }) => {
await page.goto('/course', {
waitUntil: 'domcontentloaded',
timeout: 60_000,
});
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
await page.waitForURL((u) => new URL(u).pathname === '/', {
timeout: 60_000,
});
await expect(
page.getByText('请返回微信小程序完成登录')
).toBeVisible({ timeout: 60_000 });
});
});
test.describe('核心全链路(已登录 → 教学资源)', () => {
test.describe.configure({ timeout: 180_000 });
test.skip(!moicenUnionid, '需要 MOICEN_E2E_UNIONIDSecret 或 .env.e2e');
test('黄金路径:会话建立 → 深链进入课程体系壳层 → JWT 与 CurrentOrgId 闭环', async ({
page,
}) => {
await establishSession(page, moicenUnionid!);
if (
await page.getByText('请返回微信小程序完成登录').isVisible().catch(() => false)
) {
test.skip(true, '当前 unionid 会话未处于可用登录态');
}
await resolveOrgContextForCoursePage(page);
const storage = await page.evaluate(() => ({
currentOrgId: window.localStorage.getItem('CurrentOrgId'),
authorization: window.localStorage.getItem('Authorization'),
}));
expect(storage.authorization, '登录深链后应有 Authorization').toBeTruthy();
const payload = decodeJwtPayload(storage.authorization!);
expect(payload).not.toBeNull();
const jwtOrgId = extractOrgIdFromTokenPayload(payload);
expect(jwtOrgId).toBeTruthy();
if (storage.currentOrgId) {
expect(storage.currentOrgId).toBe(jwtOrgId);
}
await page.goto('/course', {
waitUntil: 'domcontentloaded',
timeout: 90_000,
});
await expect(page.locator('#app')).toBeVisible({ timeout: 90_000 });
await waitForCourseRealmVisible(page);
await expect(page.getByText('请求失败,点击重新加载')).toHaveCount(0, {
timeout: 45_000,
});
});
});
test('可选:MOICEN_HEALTHCHECK_URL 可达', async ({ request }) => {
test.skip(!moicenHealthcheckUrl, '未配置 MOICEN_HEALTHCHECK_URL(仓库 Variables');
const res = await request.get(moicenHealthcheckUrl!);
expect(
res.ok(),
`HTTP ${res.status()} ${res.statusText()} ${moicenHealthcheckUrl}`
).toBeTruthy();
});