import { vi } from 'vitest'

vi.mock('../../lib/prisma', () => ({ prisma: {} }))
vi.mock('../../lib/redis', () => ({ redis: { on: vi.fn(), get: vi.fn(), set: vi.fn(), del: vi.fn(), quit: vi.fn() } }))
vi.mock('../../services/amanpayService', () => ({
  isConfigured: vi.fn().mockReturnValue(false),
  verifyWebhookSignature: vi.fn().mockReturnValue(false),
}))
vi.mock('../../services/paypalService', () => ({
  isConfigured: vi.fn().mockReturnValue(false),
  verifyWebhookEvent: vi.fn().mockResolvedValue(false),
}))

import { describe, expect, it } from 'vitest'
import request from 'supertest'
import { createApp } from '../../app'

const app = createApp()

describe('payments webhook public e2e smoke', () => {
  it('does not process anonymous AmanPay webhook payloads without a valid provider configuration/signature', async () => {
    const res = await request(app)
      .post('/api/v1/payments/webhooks/amanpay')
      .send({ transaction_id: 'untrusted_txn', status: 'PAID' })

    expect(res.status).toBe(401)
    expect(res.body).toEqual({ error: 'invalid_signature' })
  })
})
