import { beforeEach, describe, expect, it, vi } from 'vitest' import { TicketTopicsApi } from './TicketTopicsApi' import type { ApiClient } from '../../core/ApiClient' import type { TicketTopic } from './types' function createMockClient(): ApiClient { return { setAccessToken: vi.fn().mockReturnThis(), request: vi.fn(), get: vi.fn(), post: vi.fn(), put: vi.fn(), patch: vi.fn(), delete: vi.fn(), } } describe('TicketTopicsApi', () => { let client: ReturnType let api: TicketTopicsApi beforeEach(() => { client = createMockClient() api = new TicketTopicsApi(client) }) it('archives via POST /ticket-topics/:id/archive with { archive: true }', async () => { const topic = { id: 't1' } as TicketTopic vi.mocked(client.post).mockResolvedValue(topic) const result = await api.archive('t1') expect(client.post).toHaveBeenCalledWith( '/ticket-topics/t1/archive', { archive: true }, undefined, ) expect(result).toEqual(topic) }) it('unarchives via POST /ticket-topics/:id/archive with { archive: false }', async () => { vi.mocked(client.post).mockResolvedValue({ id: 't1' } as TicketTopic) await api.unarchive('t1') expect(client.post).toHaveBeenCalledWith( '/ticket-topics/t1/archive', { archive: false }, undefined, ) }) it('archive/unarchive stay bound when destructured', async () => { vi.mocked(client.post).mockResolvedValue({ id: 't1' } as TicketTopic) const { archive, unarchive } = api await archive('t1') await unarchive('t1') expect(client.post).toHaveBeenCalledTimes(2) }) })