import { describe, it, expect } from 'vitest'; import { extractErrorCode } from './api.server'; describe('extractErrorCode', () => { it('returns the code string when error has a code property', () => { expect(extractErrorCode({ code: 'DOCUMENT_NOT_FOUND' })).toBe('DOCUMENT_NOT_FOUND'); }); it('returns undefined when error is undefined', () => { expect(extractErrorCode(undefined)).toBeUndefined(); }); it('returns undefined when error is null', () => { expect(extractErrorCode(null)).toBeUndefined(); }); it('returns undefined when error is a plain string', () => { expect(extractErrorCode('oops')).toBeUndefined(); }); it('returns undefined when error object has no code property', () => { expect(extractErrorCode({ message: 'fail' })).toBeUndefined(); }); });