合入主线登录和营业时段策略,对齐旧界面与 React 访问流程

This commit is contained in:
黄健铭 committed 2026-12-05 21:46:55 -08:00
commit 42395de23a
113 files changed
+1915 -558

No files matched your search

+14 -2
View File
@@ -33,7 +33,7 @@ function harness(fetcher: (url: string, init: RequestInit, attempt: number) => P
const client = new LedgerClient(env);
client.setUser('user-1');
const headers = (i: number) => calls[i].headers as Record<string, string>;
return { client, saved, calls, delays, headers, key: 'mm-pending-user-1' };
return { client, env, saved, calls, delays, headers, key: 'mm-pending-user-1' };
}
describe('读请求', () => {
@@ -50,13 +50,25 @@ describe('读请求', () => {
expect(down.calls).toHaveLength(3);
expect(down.delays).toEqual([400, 1200]);
});
it('使用中的账本收到营业时间拒绝立即退回登录页,登录表单本身显示错误', async () => {
const h = harness(() => httpError(403, '非营业时间', { code: 'BUSINESS_HOURS' }));
let locked = 0;
h.env.onBusinessHoursDenied = () => { locked++; };
await expect(h.client.api('/api/login', { member: 'assistant', password: '合成密码' })).rejects.toMatchObject({
status: 403, loginDiagnostic: { method: 'POST', path: '/api/login', status: 403 },
});
expect(locked).toBe(0);
await expect(h.client.api('/api/session')).rejects.toMatchObject({ code: 'BUSINESS_HOURS' });
await expect(h.client.api('/api/stock', { revision: 1 })).rejects.toMatchObject({ code: 'BUSINESS_HOURS' });
expect(locked).toBe(2);
});
it('明确业务拒绝不重试,保留服务端文字;登录类接口不带 X-Ledger-User', async () => {
for (const status of [400, 401, 403, 404, 409, 500]) {
const h = harness(() => httpError(status, '具体业务错误'));
await expect(h.client.api('/api/state')).rejects.toMatchObject({ status, message: '具体业务错误', confirmed: true });
expect(h.calls).toHaveLength(1);
}
const h = harness(() => ok({ user: null }));
const h = harness(url => ok({ user: url === '/api/login' ? { id: 'owner' } : null }));
await h.client.api('/api/session');
await h.client.api('/api/login', { member: 'owner', password: 'x' });
expect(h.headers(0)['X-Ledger-User']).toBeUndefined();