|
| 1 | +import { describe, it, expect } from 'vitest'; |
| 2 | +import { |
| 3 | + XposedOrNotError, |
| 4 | + ValidationError, |
| 5 | + RateLimitError, |
| 6 | + NotFoundError, |
| 7 | + NetworkError, |
| 8 | + TimeoutError, |
| 9 | + ApiError, |
| 10 | +} from '../src/errors/index.js'; |
| 11 | + |
| 12 | +describe('XposedOrNotError', () => { |
| 13 | + it('has correct properties', () => { |
| 14 | + const error = new XposedOrNotError('Test error', 'TEST_CODE', 500); |
| 15 | + expect(error.message).toBe('Test error'); |
| 16 | + expect(error.code).toBe('TEST_CODE'); |
| 17 | + expect(error.statusCode).toBe(500); |
| 18 | + expect(error.name).toBe('XposedOrNotError'); |
| 19 | + }); |
| 20 | +}); |
| 21 | + |
| 22 | +describe('ValidationError', () => { |
| 23 | + it('has correct properties', () => { |
| 24 | + const error = new ValidationError('Invalid email', 'email'); |
| 25 | + expect(error.message).toBe('Invalid email'); |
| 26 | + expect(error.field).toBe('email'); |
| 27 | + expect(error.code).toBe('VALIDATION_ERROR'); |
| 28 | + expect(error.name).toBe('ValidationError'); |
| 29 | + }); |
| 30 | +}); |
| 31 | + |
| 32 | +describe('RateLimitError', () => { |
| 33 | + it('has correct defaults', () => { |
| 34 | + const error = new RateLimitError(); |
| 35 | + expect(error.statusCode).toBe(429); |
| 36 | + expect(error.code).toBe('RATE_LIMIT_EXCEEDED'); |
| 37 | + }); |
| 38 | + |
| 39 | + it('includes retryAfter', () => { |
| 40 | + const error = new RateLimitError('Too many requests', 60); |
| 41 | + expect(error.retryAfter).toBe(60); |
| 42 | + }); |
| 43 | +}); |
| 44 | + |
| 45 | +describe('NotFoundError', () => { |
| 46 | + it('has correct defaults', () => { |
| 47 | + const error = new NotFoundError(); |
| 48 | + expect(error.statusCode).toBe(404); |
| 49 | + expect(error.code).toBe('NOT_FOUND'); |
| 50 | + }); |
| 51 | +}); |
| 52 | + |
| 53 | +describe('NetworkError', () => { |
| 54 | + it('has correct properties', () => { |
| 55 | + const cause = new Error('Connection refused'); |
| 56 | + const error = new NetworkError('Network failed', cause); |
| 57 | + expect(error.code).toBe('NETWORK_ERROR'); |
| 58 | + expect(error.cause).toBe(cause); |
| 59 | + }); |
| 60 | +}); |
| 61 | + |
| 62 | +describe('TimeoutError', () => { |
| 63 | + it('has correct properties', () => { |
| 64 | + const error = new TimeoutError(); |
| 65 | + expect(error.code).toBe('TIMEOUT'); |
| 66 | + }); |
| 67 | +}); |
| 68 | + |
| 69 | +describe('ApiError', () => { |
| 70 | + it('has correct properties', () => { |
| 71 | + const error = new ApiError('Server error', 500, { detail: 'Internal error' }); |
| 72 | + expect(error.statusCode).toBe(500); |
| 73 | + expect(error.response).toEqual({ detail: 'Internal error' }); |
| 74 | + }); |
| 75 | +}); |
0 commit comments