test: guest onboarding, logged-in isolation, optional real_name
Add guest-onboarding and logged-in-and-isolation specs; remove moicen-unionid-chain; MOICEN_E2E_EXPECTED_REAL_NAME for 欢迎回来+姓名; CI secret; workers=1; longer goto timeouts. Made-with: Cursor
This commit is contained in:
@@ -0,0 +1,81 @@
|
||||
import { test, expect } from '@playwright/test';
|
||||
|
||||
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
|
||||
const expectedRealName = process.env.MOICEN_E2E_EXPECTED_REAL_NAME?.trim();
|
||||
|
||||
test.describe('已登录用户与串号防护', () => {
|
||||
test.skip(!moicenUnionid, '需要 MOICEN_E2E_UNIONID(Secret 或 .env.e2e)');
|
||||
|
||||
test('login2_with_unionid 后不应停留在未登录占位,应出现身份或工作台', async ({
|
||||
page,
|
||||
}) => {
|
||||
const q = new URLSearchParams({
|
||||
unionid: moicenUnionid!,
|
||||
status: '2',
|
||||
});
|
||||
await page.goto(`/?${q.toString()}`, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 60_000,
|
||||
});
|
||||
await expect(page.locator('#app')).toBeVisible({ timeout: 60_000 });
|
||||
await expect(
|
||||
page.getByText('请返回微信小程序完成登录')
|
||||
).not.toBeVisible({ timeout: 90_000 });
|
||||
await expect(
|
||||
page.getByText(/请选择您的登录身份|欢迎回来|进入工作台/)
|
||||
).toBeVisible({ timeout: 90_000 });
|
||||
});
|
||||
|
||||
test('已登录后 URL 中异主 unionid 应被剥离(不串号)', async ({ page }) => {
|
||||
const q = new URLSearchParams({
|
||||
unionid: moicenUnionid!,
|
||||
status: '2',
|
||||
});
|
||||
await page.goto(`/?${q.toString()}`, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 60_000,
|
||||
});
|
||||
await expect(
|
||||
page.getByText(/请选择您的登录身份|欢迎回来|进入工作台/)
|
||||
).toBeVisible({ timeout: 90_000 });
|
||||
|
||||
const poisonUnionid = 'e2eStrangerUnionidNotCurrentUser001';
|
||||
const pathBefore = new URL(page.url()).pathname || '/';
|
||||
await page.goto(
|
||||
`${pathBefore}?unionid=${encodeURIComponent(poisonUnionid)}&status=2`,
|
||||
{ waitUntil: 'domcontentloaded', timeout: 60_000 }
|
||||
);
|
||||
await page.waitForURL(
|
||||
(u) => !u.toString().includes(poisonUnionid),
|
||||
{ timeout: 45_000 }
|
||||
);
|
||||
expect(page.url()).not.toContain(poisonUnionid);
|
||||
await expect(
|
||||
page.getByText('请返回微信小程序完成登录')
|
||||
).not.toBeVisible();
|
||||
});
|
||||
|
||||
test('可选:工作台「欢迎回来」展示配置的真实姓名(自己的数据)', async ({
|
||||
page,
|
||||
}) => {
|
||||
test.skip(
|
||||
!expectedRealName,
|
||||
'未设置 MOICEN_E2E_EXPECTED_REAL_NAME 时跳过(与库中 real_name 一致,如 阿难)'
|
||||
);
|
||||
const q = new URLSearchParams({
|
||||
unionid: moicenUnionid!,
|
||||
status: '2',
|
||||
});
|
||||
await page.goto(`/?${q.toString()}`, {
|
||||
waitUntil: 'domcontentloaded',
|
||||
timeout: 60_000,
|
||||
});
|
||||
if (await page.getByText('请选择您的登录身份').isVisible().catch(() => false)) {
|
||||
await page.locator('.van-grid-item').first().click();
|
||||
}
|
||||
await expect(page.getByText('欢迎回来')).toBeVisible({ timeout: 120_000 });
|
||||
await expect(page.getByText(expectedRealName!)).toBeVisible({
|
||||
timeout: 30_000,
|
||||
});
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user