area-client.test.ts 2.0 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364
  1. import { describe, it, expect, vi, beforeEach } from 'vitest';
  2. import { areaClient, areaClientManager } from '../../src/api/areaClient';
  3. // Mock API client
  4. vi.mock('../../src/api/areaClient', () => {
  5. const mockAreaClient = {
  6. $get: vi.fn(() => Promise.resolve({ status: 200, body: null })),
  7. $post: vi.fn(() => Promise.resolve({ status: 201, body: null })),
  8. ':id': {
  9. $put: vi.fn(() => Promise.resolve({ status: 200, body: null })),
  10. $delete: vi.fn(() => Promise.resolve({ status: 204, body: null })),
  11. },
  12. };
  13. const mockAreaClientManager = {
  14. get: vi.fn(() => mockAreaClient),
  15. init: vi.fn(() => mockAreaClient),
  16. reset: vi.fn(),
  17. };
  18. return {
  19. areaClientManager: mockAreaClientManager,
  20. areaClient: mockAreaClient,
  21. };
  22. });
  23. describe('AreaClient', () => {
  24. beforeEach(() => {
  25. vi.clearAllMocks();
  26. });
  27. it('should export areaClientManager with methods', () => {
  28. expect(areaClientManager).toBeDefined();
  29. expect(typeof areaClientManager.get).toBe('function');
  30. expect(typeof areaClientManager.init).toBe('function');
  31. expect(typeof areaClientManager.reset).toBe('function');
  32. });
  33. it('should export areaClient instance', () => {
  34. expect(areaClient).toBeDefined();
  35. expect(typeof areaClient.$get).toBe('function');
  36. expect(typeof areaClient.$post).toBe('function');
  37. expect(areaClient[':id']).toBeDefined();
  38. expect(typeof areaClient[':id'].$put).toBe('function');
  39. expect(typeof areaClient[':id'].$delete).toBe('function');
  40. });
  41. it('should initialize client via manager', () => {
  42. const client = areaClientManager.init();
  43. expect(client).toBeDefined();
  44. expect(areaClientManager.init).toHaveBeenCalled();
  45. });
  46. it('should get client via manager', () => {
  47. const client = areaClientManager.get();
  48. expect(client).toBeDefined();
  49. expect(areaClientManager.get).toHaveBeenCalled();
  50. });
  51. it('should reset client via manager', () => {
  52. areaClientManager.reset();
  53. expect(areaClientManager.reset).toHaveBeenCalled();
  54. });
  55. });