import { describe, it, expect, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'

import { useAuthStore } from './auth'

describe('useAuthStore', () => {
  beforeEach(() => {
    setActivePinia(createPinia())
  })

  it('starts with no authenticated user', () => {
    /**
     * Test that the auth store initializes in an unauthenticated state.
     *
     * New users should not be authenticated until they log in,
     * ensuring protected routes are inaccessible by default.
     */
    const store = useAuthStore()

    expect(store.isAuthenticated).toBe(false)
    expect(store.user).toBeNull()
    expect(store.token).toBeNull()
  })

  it('tracks loading state', () => {
    /**
     * Test that the loading state ref is accessible.
     *
     * Components need to check loading state to show spinners
     * and disable buttons during async operations.
     */
    const store = useAuthStore()

    expect(store.isLoading).toBe(false)
  })

  it('tracks error state', () => {
    /**
     * Test that the error state ref is accessible.
     *
     * Components need to display error messages when
     * login or registration fails.
     */
    const store = useAuthStore()

    expect(store.error).toBeNull()
  })
})
