Files
huike-e2e-moicen/tests/debug-anan-info.spec.ts
T
2026-05-02 08:28:35 +08:00

78 lines
2.9 KiB
TypeScript

import { expect, test } from './fixtures';
const moicenUnionid = process.env.MOICEN_E2E_UNIONID?.trim();
test.skip(!moicenUnionid, 'MOICEN_E2E_UNIONID 未设置');
function decodeJwt(token: string): any {
const raw = token.replace('Bearer ', '').trim();
const parts = raw.split('.');
if (parts.length !== 3) return null;
const b64 = parts[1].replace(/-/g, '+').replace(/_/g, '/');
return JSON.parse(Buffer.from(b64, 'base64').toString('utf8'));
}
test('提取阿难全部localStorage信息', 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 page.waitForTimeout(3000);
const rs = page.getByText('请选择您的登录身份');
if (await rs.isVisible().catch(() => false)) {
// Try to select TEACHER role (may be 2nd or 3rd grid item)
const items = page.locator('.van-grid-item');
const count = await items.count();
for (let i = 0; i < count; i++) {
const text = await items.nth(i).textContent();
console.log(`Role item ${i}: ${text?.trim()}`);
}
await items.first().click();
await page.waitForTimeout(3000);
}
const ls = await page.evaluate(() => {
const data: Record<string, string> = {};
for (let i = 0; i < localStorage.length; i++) {
const key = localStorage.key(i)!;
const val = localStorage.getItem(key)!;
if (val.length > 200) {
data[key] = val.substring(0, 200) + '...';
} else {
data[key] = val;
}
}
return data;
});
for (const [k, v] of Object.entries(ls)) {
console.log(`${k}: ${v}`);
}
// Try a real API call from the SPA's context
const auth = ls['Authorization'] || '';
const sudoerToken = ls['HtySudoerToken'] || '';
// Test API call via page fetch (uses frontend interceptor)
const result = await page.evaluate(async () => {
const resp = await fetch('/api/v1/clazz/find_all_non_repeatable_within_date_range?start=2026-05-01&end=2026-05-03', {
headers: {
'Content-Type': 'application/json',
},
});
return { status: resp.status, text: await resp.text().then(t => t.substring(0, 200)) };
});
console.log('API test via SPA:', JSON.stringify(result));
// Try direct call to admin.moicen.com
const result2 = await page.evaluate(async ({ auth, sudoerToken }) => {
const resp = await fetch('https://admin.moicen.com/api/v1/clazz/find_all_non_repeatable_within_date_range?start=2026-05-01&end=2026-05-03', {
headers: {
'Authorization': auth,
'HtySudoerToken': sudoerToken,
'HtyHost': 'admin.moicen.com',
},
});
return { status: resp.status, text: await resp.text().then(t => t.substring(0, 500)) };
}, { auth, sudoerToken });
console.log('API test direct:', JSON.stringify(result2));
});