import { initPayment, getPaymentResult } from './adhesionService';
import http from '@/http';

jest.mock('@/http', () => ({
  __esModule: true,
  default: {
    get: jest.fn(),
    post: jest.fn(),
  },
}));

describe('adhesionService', () => {
  beforeEach(() => {
    jest.clearAllMocks();
  });

  describe('initPayment', () => {
    it('shouldCallInitPaymentEndpoint', async () => {
      const mockResponse = { success: true, token: 'TOKEN_123' };
      (http.post as jest.Mock).mockResolvedValueOnce({ data: mockResponse });

      const payload = {
        type: 'particulier',
        cotisationType: 'classique',
        amount: 1000,
        firstName: 'Jean',
        lastName: 'Dupont',
        email: 'jean@example.com',
        address: '12 rue de Brest',
        postalCode: '29000',
        city: 'Quimper',
      };

      const result = await initPayment(payload);

      expect(http.post).toHaveBeenCalledWith('/adhesion/init-payment', payload);
      expect(result).toEqual(mockResponse);
    });
  });

  describe('getPaymentResult', () => {
    it('shouldCallPaymentResultEndpoint', async () => {
      const mockResponse = { success: true, status: 'PAID', firstName: 'Jean', amount: 1000 };
      (http.get as jest.Mock).mockResolvedValueOnce({ data: mockResponse });

      const result = await getPaymentResult('MY_TOKEN');

      expect(http.get).toHaveBeenCalledWith('/adhesion/payment-result?token=MY_TOKEN');
      expect(result).toEqual(mockResponse);
    });
  });
});
