124 lines
5.6 KiB
TypeScript
124 lines
5.6 KiB
TypeScript
import { closeElectronApp, expect, getStableWindow, test } from './fixtures/electron';
|
|
|
|
test.describe('Account reset-card wallet', () => {
|
|
test('redeems an available card and refreshes the authoritative point balance', async ({ launchElectronApp }) => {
|
|
const app = await launchElectronApp({ skipSetup: true });
|
|
try {
|
|
const page = await getStableWindow(app);
|
|
await expect(page.getByTestId('ai-module-selection-page')).toBeVisible();
|
|
const applicationUrl = page.url();
|
|
await page.goto('about:blank');
|
|
await app.evaluate(({ ipcMain }) => {
|
|
const requests: string[] = [];
|
|
let redeemed = false;
|
|
const result = (json: unknown) => ({ ok: true, data: { status: 200, ok: true, json } });
|
|
const points = () => ({
|
|
plan_code: 'mastery',
|
|
plan_name: '精通',
|
|
cycle_start: '2026-09-08T00:00:00Z',
|
|
cycle_end: '2026-09-15T00:00:00Z',
|
|
next_refresh_at: '2026-09-15T00:00:00Z',
|
|
weekly_allowance: '500.00',
|
|
weekly_used: redeemed ? '0.00' : '400.00',
|
|
weekly_reserved: '0.00',
|
|
weekly_remaining: redeemed ? '500.00' : '100.00',
|
|
permanent_total: '50.00',
|
|
permanent_used: '0.00',
|
|
permanent_reserved: '0.00',
|
|
permanent_remaining: '50.00',
|
|
total_remaining: redeemed ? '550.00' : '150.00',
|
|
entitlement_source: 'self',
|
|
family_shared: false,
|
|
can_manage_membership: true,
|
|
upgrade_action: 'self_service',
|
|
shared_available: null,
|
|
});
|
|
const card = () => ({
|
|
id: 'card-e2e',
|
|
status: redeemed ? 'redeemed' : 'available',
|
|
granted_at: '2026-09-08T00:00:00Z',
|
|
expires_at: '2099-09-15T00:00:00Z',
|
|
redeemed_at: redeemed ? '2026-09-09T00:00:00Z' : null,
|
|
redeemed_cycle_id: redeemed ? 'cycle-e2e' : null,
|
|
});
|
|
(globalThis as typeof globalThis & { __resetCardE2E?: { requests: string[] } }).__resetCardE2E = { requests };
|
|
ipcMain.removeHandler('hostapi:fetch');
|
|
ipcMain.handle('hostapi:fetch', async (_event, request: { path?: string; method?: string }) => {
|
|
const path = request.path ?? '';
|
|
const method = (request.method ?? 'GET').toUpperCase();
|
|
requests.push(`${method} ${path}`);
|
|
if (path === '/api/auth/session/sync') return result({
|
|
success: true,
|
|
session: {
|
|
accessToken: 'reset-card-e2e-token',
|
|
tokenType: 'Bearer',
|
|
expiresAt: Date.now() + 3_600_000,
|
|
lastActiveAt: Date.now(),
|
|
canRefresh: false,
|
|
},
|
|
});
|
|
if (path === '/api/auth/me') return result({
|
|
success: true,
|
|
user: {
|
|
username: 'reset-card-e2e',
|
|
userId: 'reset-card-e2e-user',
|
|
tenantId: null,
|
|
deptId: null,
|
|
authorities: [],
|
|
},
|
|
moduleAccess: { programming: true, design: true, robot: true },
|
|
});
|
|
if (path === '/api/works/user/agent-profile') return result({
|
|
success: true,
|
|
profile: {
|
|
display_name: '重置卡用户',
|
|
age: null,
|
|
gender: null,
|
|
avatar_url: null,
|
|
share_age_with_agents: false,
|
|
share_gender_with_agents: false,
|
|
analysis_enabled: true,
|
|
completed: true,
|
|
version: 1,
|
|
updated_at: '2026-09-08T00:00:00Z',
|
|
},
|
|
});
|
|
if (path === '/api/works/billing/points') return result({ success: true, points: points() });
|
|
if (path === '/api/works/billing/reset-cards' && method === 'GET') {
|
|
return result({ success: true, cards: [card()] });
|
|
}
|
|
if (path === '/api/works/billing/reset-cards/card-e2e/redeem' && method === 'POST') {
|
|
redeemed = true;
|
|
return result({ success: true, card: card() });
|
|
}
|
|
return { ok: false, error: { message: `Unexpected Host API request: ${method} ${path}` } };
|
|
});
|
|
});
|
|
|
|
await page.goto(applicationUrl, { waitUntil: 'domcontentloaded' });
|
|
await page.getByTestId('ai-module-option-programming').click();
|
|
await expect(page.getByTestId('main-layout')).toBeVisible();
|
|
await page.getByTestId('sidebar-member-menu-trigger').click();
|
|
await page.getByTestId('sidebar-reset-cards-menuitem').click();
|
|
|
|
await expect.poll(async () => app.evaluate(() => (
|
|
(globalThis as typeof globalThis & { __resetCardE2E?: { requests: string[] } }).__resetCardE2E?.requests
|
|
.filter((request) => request === 'GET /api/works/billing/reset-cards').length ?? 0
|
|
))).toBeGreaterThan(0);
|
|
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toContainText('可使用');
|
|
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toContainText('有效期至 2099-09-15');
|
|
await page.getByTestId('sidebar-reset-card-redeem-card-e2e').click();
|
|
await expect(page.getByTestId('sidebar-reset-card-card-e2e')).toContainText('已使用');
|
|
|
|
await page.getByTestId('sidebar-account-usage-menuitem').click();
|
|
await expect(page.getByTestId('sidebar-weekly-token-points')).toContainText('500 / 500 点');
|
|
await expect.poll(async () => app.evaluate(() => (
|
|
(globalThis as typeof globalThis & { __resetCardE2E?: { requests: string[] } }).__resetCardE2E?.requests
|
|
.filter((request) => request === 'POST /api/works/billing/reset-cards/card-e2e/redeem').length ?? 0
|
|
))).toBe(1);
|
|
} finally {
|
|
await closeElectronApp(app);
|
|
}
|
|
});
|
|
});
|