import { describe, it, expect } from 'vitest';
import { searchItems } from './api';

/**
 * Integration tests for searchItems API function
 * 
 * These tests verify the function behavior without mocking,
 * but they require the API server to be running.
 * 
 * To run these tests:
 * 1. Start the API server: cd api && npm run start:dev
 * 2. Run tests: npm test -- api.integration.test.ts
 * 
 * Note: These tests are skipped by default. Remove .skip to run them.
 */
describe.skip('searchItems - Integration Tests', () => {
  it('should return items matching the query', async () => {
    // This test requires the API server to be running
    const result = await searchItems('rice');
    
    expect(Array.isArray(result)).toBe(true);
    
    if (result.length > 0) {
      // Verify structure of returned items
      expect(result[0]).toHaveProperty('_id');
      expect(result[0]).toHaveProperty('itemCode');
      expect(result[0]).toHaveProperty('itemName');
    }
  });

  it('should return empty array for non-existent items', async () => {
    const result = await searchItems('zzzznonexistent999');
    expect(result).toEqual([]);
  });

  it('should handle special characters in search', async () => {
    const result = await searchItems('test&special');
    expect(Array.isArray(result)).toBe(true);
  });
});
