import { describe, expect, it, 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('../../modules/site/site.service', () => ({
  getPlatformHomepage: vi.fn(async () => ({ hero: { title: 'Rent smarter' } })),
  getPlatformPricing: vi.fn(async () => ({ prices: {}, planFeatures: {} })),
  getBrand: vi.fn(),
  getPublicVehicles: vi.fn(),
  getVehicleDetail: vi.fn(),
  getOffers: vi.fn(),
  getBookingOptions: vi.fn(),
  checkAvailability: vi.fn(),
  validatePromoCode: vi.fn(),
  createBooking: vi.fn(),
  getBooking: vi.fn(),
  initPayment: vi.fn(),
  capturePaypal: vi.fn(),
  handleContact: vi.fn(),
}))

import request from 'supertest'
import { createApp } from '../../app'

const app = createApp()

describe('site and webhook public e2e smoke', () => {
  it('allows public platform reads while leaving legacy Clerk webhook permanently disabled', async () => {
    const homepage = await request(app).get('/api/v1/site/platform/homepage')
    expect(homepage.status).toBe(200)
    expect(homepage.body.data.hero.title).toBe('Rent smarter')

    const webhook = await request(app)
      .post('/api/v1/webhooks/clerk')
      .set('content-type', 'application/json')
      .send(JSON.stringify({ type: 'organization.updated' }))
    expect(webhook.status).toBe(410)
    expect(webhook.body.error).toBe('disabled')
  })
})
