import { describe, it, expect, beforeEach, vi, afterEach } from 'vitest'
import { apiClient } from './apiClient'

describe('apiClient', () => {
    beforeEach(() => {
        // Reset token before each test
        apiClient.setToken(null)
    })

    afterEach(() => {
        vi.restoreAllMocks()
    })

    describe('setToken', () => {
        it('should set token to null initially', () => {
            // Token starts as null - we just verify setToken doesn't throw
            expect(() => apiClient.setToken(null)).not.toThrow()
        })

        it('should accept a token string', () => {
            expect(() => apiClient.setToken('test-token-123')).not.toThrow()
        })

        it('should clear token when set to null', () => {
            apiClient.setToken('some-token')
            apiClient.setToken(null)
            // No error means success
            expect(true).toBe(true)
        })
    })

    describe('api methods', () => {
        it('should expose get method', () => {
            expect(typeof apiClient.get).toBe('function')
        })

        it('should expose post method', () => {
            expect(typeof apiClient.post).toBe('function')
        })

        it('should expose put method', () => {
            expect(typeof apiClient.put).toBe('function')
        })

        it('should expose delete method', () => {
            expect(typeof apiClient.delete).toBe('function')
        })
    })
})
