9b395f5cc3
E2E Headed Chrome / e2e-headed (macos-15) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (ubuntu-latest) (push) Has been cancelled
E2E Headed Chrome / e2e-headed (windows-latest) (push) Has been cancelled
CI / build (macos-latest) (push) Has been cancelled
CI / build (ubuntu-latest) (push) Has been cancelled
CI / build (windows-latest) (push) Has been cancelled
CI / unit-test (push) Has been cancelled
CI / bun-test (push) Has been cancelled
CI / adapter-test (push) Has been cancelled
CI / smoke-test (macos-latest) (push) Has been cancelled
CI / smoke-test (ubuntu-latest) (push) Has been cancelled
Security Audit / audit (push) Has been cancelled
Build Chrome Extension / build (push) Has been cancelled
Trigger Website Rebuild (Docs Updated) / dispatch (push) Has been cancelled
42 lines
1.8 KiB
JavaScript
42 lines
1.8 KiB
JavaScript
import { describe, expect, it, vi } from 'vitest';
|
|
import { fetchDanjuanAll } from './danjuan-utils.js';
|
|
describe('fetchDanjuanAll', () => {
|
|
it('throws when no Danjuan accounts are visible', async () => {
|
|
const mockPage = {
|
|
evaluate: vi.fn().mockResolvedValue({ _emptyAccounts: true }),
|
|
};
|
|
await expect(fetchDanjuanAll(mockPage)).rejects.toThrow('No fund accounts found');
|
|
});
|
|
it('throws when any account detail request fails', async () => {
|
|
const mockPage = {
|
|
evaluate: vi.fn().mockResolvedValue({
|
|
detailErrors: [
|
|
{ accountName: '默认账户', accountId: 'acc-1', error: 403 },
|
|
],
|
|
}),
|
|
};
|
|
await expect(fetchDanjuanAll(mockPage)).rejects.toThrow('Failed to fetch Danjuan account details: 默认账户 (acc-1): 403');
|
|
});
|
|
it('returns the combined snapshot when all account details succeed', async () => {
|
|
const snapshot = {
|
|
asOf: '2026-03-25',
|
|
totalAssetAmount: 100,
|
|
totalAssetDailyGain: 1,
|
|
totalAssetHoldGain: 2,
|
|
totalAssetTotalGain: 3,
|
|
totalFundMarketValue: 80,
|
|
accounts: [{ accountId: 'acc-1', accountName: '默认账户' }],
|
|
holdings: [{ accountId: 'acc-1', fdCode: '000001', fdName: '示例基金' }],
|
|
detailErrors: [],
|
|
};
|
|
const mockPage = {
|
|
evaluate: vi.fn().mockResolvedValue(snapshot),
|
|
};
|
|
await expect(fetchDanjuanAll(mockPage)).resolves.toMatchObject({
|
|
asOf: '2026-03-25',
|
|
accounts: [{ accountId: 'acc-1', accountName: '默认账户' }],
|
|
holdings: [{ accountId: 'acc-1', fdCode: '000001', fdName: '示例基金' }],
|
|
});
|
|
});
|
|
});
|