// Payment Flow End-to-End Tests

import request from 'supertest';
import app from '@/integration/api-gateway/app';
import { createTestSovereignBank, createTestBankAccount, cleanDatabase } from '@/__tests__/utils/test-db';
import { testPrisma } from '@/__tests__/utils/test-db';
import { createAuthHeaders } from '@/__tests__/utils/test-auth';

describe('Payment Flow E2E', () => {
  beforeEach(async () => {
    await cleanDatabase();
  });

  afterAll(async () => {
    await testPrisma.$disconnect();
  });

  it('should complete a full payment flow', async () => {
    const bank = await createTestSovereignBank();
    const sourceAccount = await createTestBankAccount({
      sovereignBankId: bank.id,
      balance: '1000.00',
    });
    const destAccount = await createTestBankAccount({
      sovereignBankId: bank.id,
      balance: '500.00',
    });

    // Note: This test assumes payment routes are implemented
    // Adjust based on actual API structure
    const response = await request(app)
      .post('/api/payments')
      .set(createAuthHeaders({ sovereignBankId: bank.id }))
      .send({
        sourceAccountId: sourceAccount.id,
        destinationAccountId: destAccount.id,
        amount: '100.00',
        currencyCode: 'USD',
        paymentType: 'transfer',
      });

    // Verify response
    expect([200, 201]).toContain(response.status);
    
    // Verify balances updated
    const updatedSource = await testPrisma.bankAccount.findUnique({
      where: { id: sourceAccount.id },
    });
    const updatedDest = await testPrisma.bankAccount.findUnique({
      where: { id: destAccount.id },
    });

    expect(updatedSource?.balance.toString()).toBe('900.00');
    expect(updatedDest?.balance.toString()).toBe('600.00');
  });
});

