import { describe, it, expect, vi, beforeEach } from 'vitest'
import { setActivePinia, createPinia } from 'pinia'
import { useExpensesStore } from '@/stores/expensesStore'
import { expenseService } from '@/services/expenseService'
import type { Expense } from '@/types/expense'

vi.mock('@/services/expenseService', () => {
    return {
        expenseService: {
            getExpenses: vi.fn(),
            createExpense: vi.fn(),
            updateExpense: vi.fn(),
            deleteExpense: vi.fn(),
            settleExpenseSplit: vi.fn(),
            getExpense: vi.fn(),
        },
    }
})

const mockExpenses: Expense[] = [
    {
        id: 1,
        description: 'Test',
        total_amount: '10.00',
        currency: 'USD',
        split_type: 'EQUAL',
        list_id: null,
        group_id: 1,
        item_id: null,
        paid_by_user_id: 1,
        created_by_user_id: 1,
        created_at: '',
        updated_at: '',
        version: 1,
        splits: [],
        overall_settlement_status: 'unpaid',
        isRecurring: false,
        is_recurring: false,
    } as unknown as Expense,
]

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

    it('fetchExpenses stores data', async () => {
        const store = useExpensesStore()
            ; (expenseService.getExpenses as any).mockResolvedValue(mockExpenses)

        await store.fetchExpenses({ group_id: 1 })

        expect(store.expenses).toEqual(mockExpenses)
        expect(store.isLoading).toBe(false)
        expect(store.error).toBeNull()
    })
}) 