37 lines
1.0 KiB
JavaScript
37 lines
1.0 KiB
JavaScript
import { createPinia, setActivePinia } from 'pinia'
|
|
import { beforeEach, describe, expect, it, vi } from 'vitest'
|
|
import { stockApi } from '../api/stock'
|
|
import { useStockStore } from './stock'
|
|
|
|
vi.mock('../api/stock', () => ({
|
|
stockApi: {
|
|
getAll: vi.fn(),
|
|
getWarning: vi.fn(),
|
|
getById: vi.fn(),
|
|
getAllLogs: vi.fn(),
|
|
getLogs: vi.fn(),
|
|
updateWarning: vi.fn()
|
|
}
|
|
}))
|
|
|
|
describe('stock store warning settings', () => {
|
|
beforeEach(() => {
|
|
setActivePinia(createPinia())
|
|
vi.clearAllMocks()
|
|
stockApi.updateWarning.mockResolvedValue({ data: null })
|
|
stockApi.getAll.mockResolvedValue({
|
|
data: { items: [{ material_id: 1, warning_stock: 8 }], total: 1 }
|
|
})
|
|
stockApi.getWarning.mockResolvedValue({ data: { items: [], total: 0 } })
|
|
})
|
|
|
|
it('refreshes inventory state after changing a warning threshold', async () => {
|
|
const store = useStockStore()
|
|
|
|
await store.updateWarningStock(1, 8)
|
|
|
|
expect(store.stockList).toEqual([{ material_id: 1, warning_stock: 8 }])
|
|
expect(store.warningList).toEqual([])
|
|
})
|
|
})
|