| 12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364 |
- import { describe, it, expect, vi, beforeEach } from 'vitest';
- import { areaClient, areaClientManager } from '../../src/api/areaClient';
- // Mock API client
- vi.mock('../../src/api/areaClient', () => {
- const mockAreaClient = {
- $get: vi.fn(() => Promise.resolve({ status: 200, body: null })),
- $post: vi.fn(() => Promise.resolve({ status: 201, body: null })),
- ':id': {
- $put: vi.fn(() => Promise.resolve({ status: 200, body: null })),
- $delete: vi.fn(() => Promise.resolve({ status: 204, body: null })),
- },
- };
- const mockAreaClientManager = {
- get: vi.fn(() => mockAreaClient),
- init: vi.fn(() => mockAreaClient),
- reset: vi.fn(),
- };
- return {
- areaClientManager: mockAreaClientManager,
- areaClient: mockAreaClient,
- };
- });
- describe('AreaClient', () => {
- beforeEach(() => {
- vi.clearAllMocks();
- });
- it('should export areaClientManager with methods', () => {
- expect(areaClientManager).toBeDefined();
- expect(typeof areaClientManager.get).toBe('function');
- expect(typeof areaClientManager.init).toBe('function');
- expect(typeof areaClientManager.reset).toBe('function');
- });
- it('should export areaClient instance', () => {
- expect(areaClient).toBeDefined();
- expect(typeof areaClient.$get).toBe('function');
- expect(typeof areaClient.$post).toBe('function');
- expect(areaClient[':id']).toBeDefined();
- expect(typeof areaClient[':id'].$put).toBe('function');
- expect(typeof areaClient[':id'].$delete).toBe('function');
- });
- it('should initialize client via manager', () => {
- const client = areaClientManager.init();
- expect(client).toBeDefined();
- expect(areaClientManager.init).toHaveBeenCalled();
- });
- it('should get client via manager', () => {
- const client = areaClientManager.get();
- expect(client).toBeDefined();
- expect(areaClientManager.get).toHaveBeenCalled();
- });
- it('should reset client via manager', () => {
- areaClientManager.reset();
- expect(areaClientManager.reset).toHaveBeenCalled();
- });
- });
|