import { describe, it, expect, vi, beforeEach } from 'vitest';
import { searchService } from './searchService';

describe('searchService', () => {
  beforeEach(() => {
    vi.clearAllMocks();
  });

  describe('global', () => {
    it('should return search results', async () => {
      const results = await searchService.global('neon');

      expect(results).toBeDefined();
      expect(results).toHaveProperty('tracks');
      expect(results).toHaveProperty('users');
      expect(results).toHaveProperty('courses');
      expect(results).toHaveProperty('playlists');
      expect(results).toHaveProperty('total');
      expect(Array.isArray(results.tracks)).toBe(true);
      expect(Array.isArray(results.users)).toBe(true);
      expect(Array.isArray(results.courses)).toBe(true);
    });

    it('should filter results by query', async () => {
      const results = await searchService.global('Cyber');

      expect(results.tracks.length).toBeGreaterThan(0);
      expect(results.users.length).toBeGreaterThan(0);
    });

    it('should return empty results for no matches', async () => {
      const results = await searchService.global('NonExistentQuery12345');

      expect(results.total).toBe(0);
      expect(results.tracks.length).toBe(0);
      expect(results.users.length).toBe(0);
    });

    it('should handle pagination', async () => {
      const results = await searchService.global('test', undefined, 2);

      expect(results).toBeDefined();
      expect(results).toHaveProperty('total');
    });
  });
});
