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

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

  describe('getOrders', () => {
    it('should return orders', async () => {
      const orders = await commerceService.getOrders();

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

  describe('getOrderDetails', () => {
    it('should return order details', async () => {
      const order = await commerceService.getOrderDetails('order-1');

      expect(order).toBeDefined();
      expect(order).toHaveProperty('id');
      expect(order).toHaveProperty('status');
      expect(order).toHaveProperty('total_amount');
    });
  });

  describe('getSalesStats', () => {
    it('should return sales statistics', async () => {
      const stats = await commerceService.getSalesStats();

      expect(stats).toBeDefined();
      expect(stats).toHaveProperty('total_revenue');
      expect(stats).toHaveProperty('total_orders');
      expect(stats).toHaveProperty('views');
      expect(stats).toHaveProperty('conversion');
    });
  });

  describe('requestRefund', () => {
    it('should request refund successfully', async () => {
      const result = await commerceService.requestRefund(
        'order-1',
        'Defective product',
      );

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