import { vi } from 'vitest'

vi.mock('../../lib/prisma', () => ({
  prisma: {
    pricingConfig: { findMany: vi.fn().mockResolvedValue([]) },
    planFeature: { findMany: vi.fn().mockResolvedValue([]) },
  },
}))

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),
  createCheckout: vi.fn(),
}))

vi.mock('../../services/paypalService', () => ({
  isConfigured: vi.fn().mockReturnValue(false),
  verifyWebhookEvent: vi.fn().mockResolvedValue(false),
  createOrder: vi.fn(),
  captureOrder: vi.fn(),
}))

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

const app = createApp()

describe('subscriptions public e2e smoke', () => {
  it('lets an anonymous client inspect providers, plans, and features without crossing authenticated subscription routes', async () => {
    const providers = await request(app).get('/api/v1/subscriptions/providers')
    expect(providers.status).toBe(200)
    expect(providers.body).toEqual({ data: { amanpay: false, paypal: false } })

    const plans = await request(app).get('/api/v1/subscriptions/plans')
    expect(plans.status).toBe(200)
    expect(plans.body.data).toHaveProperty('STARTER')
    expect(plans.body.data).toHaveProperty('GROWTH')
    expect(plans.body.data).toHaveProperty('PRO')

    const features = await request(app).get('/api/v1/subscriptions/features')
    expect(features.status).toBe(200)
    expect(features.body).toEqual({ data: [] })

    const me = await request(app).get('/api/v1/subscriptions/me')
    expect(me.status).toBe(401)
  })
})
