import { describe, it, expect, beforeEach, vi } from 'vitest'; import { get, post } from '../../src/lib/api.js'; describe('Conversation Tracker API Paths', () => { beforeEach(() => { // Mock fetch globally global.fetch = vi.fn(); // Mock localStorage global.localStorage = { getItem: vi.fn(() => 'mock-token'), setItem: vi.fn(), removeItem: vi.fn(), }; }); it('should call /api/conversations/dates without double prefix', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => ['2026-04-19'], headers: new Headers(), }); await get('/conversations/dates'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/dates'), expect.any(Object) ); expect(global.fetch).not.toHaveBeenCalledWith( expect.stringContaining('/api/api/'), expect.any(Object) ); }); it('should call /api/conversations/summary/:date correctly', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => ({ summary: 'test' }), headers: new Headers(), }); await get('/conversations/summary/2026-04-19'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/summary/2026-04-19'), expect.any(Object) ); expect(global.fetch).not.toHaveBeenCalledWith( expect.stringContaining('/api/api/'), expect.any(Object) ); }); it('should call /api/conversations/list correctly', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => [], headers: new Headers(), }); await get('/conversations/list?date=2026-04-19'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/list?date=2026-04-19'), expect.any(Object) ); }); it('should call search endpoint correctly', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => [], headers: new Headers(), }); await get('/conversations/search?q=test'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/search?q=test'), expect.any(Object) ); }); it('should call stats endpoint correctly', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => ({ top_projects: [], top_tools: [] }), headers: new Headers(), }); await get('/conversations/stats'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/stats'), expect.any(Object) ); }); it('should call conversation detail endpoint correctly', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => ({ session_id: 'test' }), headers: new Headers(), }); await get('/conversations/test-session-id'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/test-session-id'), expect.any(Object) ); }); it('should call trigger endpoint correctly', async () => { global.fetch.mockResolvedValueOnce({ ok: true, json: async () => ({ status: 'ok' }), headers: new Headers(), }); await post('/conversations/trigger'); expect(global.fetch).toHaveBeenCalledWith( expect.stringContaining('/api/conversations/trigger'), expect.objectContaining({ method: 'POST', }) ); }); });