import { describe, it, expect, beforeAll, afterAll } from 'vitest'
import { authService } from './auth'

/**
 * Integration tests that require a running backend.
 * 
 * To run these tests:
 * 1. Start the backend: cd backend && go run ./cmd/api
 * 2. Ensure admin user exists (backend seeds it automatically)
 * 3. Run: npm test -- auth.integration
 * 
 * These tests are skipped by default in CI.
 */

const BACKEND_URL = process.env.VITE_API_URL || 'http://localhost:8214/api'
const SKIP_INTEGRATION = process.env.CI === 'true' || !process.env.RUN_INTEGRATION

describe.skipIf(SKIP_INTEGRATION)('authService Integration Tests', () => {
    describe('login with real backend', () => {
        it('should login with admin credentials', async () => {
            const result = await authService.login({
                username: 'admin',
                password: 'admin123'
            })

            expect(result.token).toBeDefined()
            expect(result.token.length).toBeGreaterThan(10)
            expect(result.expiresAt).toBeDefined()
        })

        it('should reject invalid password', async () => {
            await expect(
                authService.login({
                    username: 'admin',
                    password: 'wrongpassword'
                })
            ).rejects.toThrow()
        })

        it('should reject non-existent user', async () => {
            await expect(
                authService.login({
                    username: 'nonexistent_user_12345',
                    password: 'anypassword'
                })
            ).rejects.toThrow()
        })
    })
})
