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

// Mock fetch pour les tests
global.fetch = vi.fn();

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

  describe('getModerationQueue', () => {
    it('should return reports filtered by status', async () => {
      const reports = await adminService.getModerationQueue('all');

      expect(reports).toBeDefined();
      expect(Array.isArray(reports)).toBe(true);
    });

    it('should filter reports by status', async () => {
      const reports = await adminService.getModerationQueue('pending');

      expect(reports).toBeDefined();
      expect(Array.isArray(reports)).toBe(true);
      // Tous les rapports devraient avoir le statut 'pending' ou être vide
      if (reports.length > 0) {
        reports.forEach((report) => {
          expect(report.status).toBe('pending');
        });
      }
    });
  });

  describe('resolveReport', () => {
    it('should resolve a report successfully', async () => {
      const result = await adminService.resolveReport('report-1', 'approved');

      expect(result).toBeDefined();
      expect(result.success).toBe(true);
    });

    it('should handle different actions', async () => {
      const actions = ['approved', 'rejected', 'dismissed'];

      for (const action of actions) {
        const result = await adminService.resolveReport('report-1', action);
        expect(result.success).toBe(true);
      }
    });
  });

  describe('getRecentUploads', () => {
    it('should return recent uploads', async () => {
      const uploads = await adminService.getRecentUploads();

      expect(uploads).toBeDefined();
      expect(Array.isArray(uploads)).toBe(true);
    });
  });

  describe('getDashboardStats', () => {
    it('should return dashboard statistics', async () => {
      const stats = await adminService.getDashboardStats();

      expect(stats).toBeDefined();
      expect(stats).toHaveProperty('totalUsers');
      expect(stats).toHaveProperty('monthlyRevenue');
      expect(stats).toHaveProperty('activeSessions');
      expect(stats).toHaveProperty('pendingReports');
    });
  });
});
