Files
wehub-resource-sync 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
chore: import upstream snapshot with attribution
2026-07-13 12:39:48 +08:00

35 lines
1.4 KiB
JavaScript

import { describe, expect, it } from 'vitest';
import { AuthRequiredError, CommandExecutionError } from '@jackwener/opencli/errors';
import { assertOk } from './utils.js';
describe('assertOk', () => {
it('returns silently on code 0', () => {
expect(() => assertOk({ code: 0 })).not.toThrow();
});
it('maps expired cookie codes (7, 37) to AuthRequiredError', () => {
expect(() => assertOk({ code: 7, message: 'expired' })).toThrow(AuthRequiredError);
expect(() => assertOk({ code: 37, message: 'expired' })).toThrow(AuthRequiredError);
});
it('maps code 24 (identity mismatch) to AuthRequiredError with recruiter-only hint', () => {
try {
assertOk({ code: 24, message: '请切换身份后再试' });
throw new Error('assertOk should have thrown');
} catch (err) {
expect(err).toBeInstanceOf(AuthRequiredError);
expect(String(err.message)).toContain('招聘端');
}
});
it('falls through to CommandExecutionError for other non-zero codes', () => {
expect(() => assertOk({ code: 99, message: 'something else' }))
.toThrow(CommandExecutionError);
});
it('throws CommandExecutionError on malformed (non-object) response', () => {
expect(() => assertOk(null)).toThrow(CommandExecutionError);
expect(() => assertOk('not-an-object')).toThrow(CommandExecutionError);
});
});