import { describe, it, expect, vi, beforeEach } from 'vitest'
import { apiClient, queryDocument, ingestDocument } from '../../lib/api'

describe('API client basics', () => {
  it('has a baseURL containing /api/v1', () => {
    expect(apiClient.defaults.baseURL).toContain('/api/v1')
  })

  it('queryDocument posts and returns data', async () => {
    const mockPost = vi.spyOn(apiClient, 'post')
    mockPost.mockResolvedValueOnce({ data: { keywords: [], answer: '', sources: [] } })
    const res = await queryDocument({ question: 'test' })
    expect(res).toHaveProperty('answer')
  })

  it('ingestDocument posts and returns data', async () => {
    const mockPost = vi.spyOn(apiClient, 'post')
    mockPost.mockResolvedValueOnce({ data: { document_id: 'doc1', chunk_count: 1, filename: 'a.txt' } })
    const file = new File(['data'], 'a.txt', { type: 'text/plain' })
    const res = await ingestDocument(file)
    expect(res).toHaveProperty('document_id')
  })
})
