Files
sb-front/src/api/accountApi.spec.js
T

70 lines
2.5 KiB
JavaScript
Raw Normal View History

import { describe, it, expect, vi } from 'vitest'
vi.mock('@/api/http', () => ({
default: {
get: vi.fn(() => Promise.resolve({})),
post: vi.fn(() => Promise.resolve({})),
put: vi.fn(() => Promise.resolve({})),
delete: vi.fn(() => Promise.resolve({})),
},
}))
import http from '@/api/http'
import { accountApi } from '@/api/accountApi'
describe('accountApi 가계부 CRUD 와이어링', () => {
it('list → GET /account/entries (필터 params)', () => {
accountApi.list({ year: 2026, month: 6, type: 'EXPENSE' })
expect(http.get).toHaveBeenCalledWith('/account/entries', {
params: { year: 2026, month: 6, type: 'EXPENSE', category: undefined, walletId: undefined, keyword: undefined, tagId: undefined },
})
})
it('create → POST /account/entries', () => {
const payload = { type: 'EXPENSE', amount: 1000, category: '식비' }
accountApi.create(payload)
expect(http.post).toHaveBeenCalledWith('/account/entries', payload)
})
it('update → PUT /account/entries/:id', () => {
accountApi.update(42, { amount: 2000 })
expect(http.put).toHaveBeenCalledWith('/account/entries/42', { amount: 2000 })
})
it('remove → DELETE /account/entries/:id', () => {
accountApi.remove(42)
expect(http.delete).toHaveBeenCalledWith('/account/entries/42')
})
it('summary → GET /account/summary', () => {
accountApi.summary({ year: 2026, month: 6 })
expect(http.get).toHaveBeenCalledWith('/account/summary', { params: { year: 2026, month: 6 } })
})
it('netWorth → GET /account/networth', () => {
accountApi.netWorth()
expect(http.get).toHaveBeenCalledWith('/account/networth')
})
it('budgetStatus → GET /account/budgets/status', () => {
accountApi.budgetStatus({ year: 2026, month: 6 })
expect(http.get).toHaveBeenCalledWith('/account/budgets/status', { params: { year: 2026, month: 6 } })
})
it('pendingCount → GET /account/entries/pending/count', () => {
accountApi.pendingCount()
expect(http.get).toHaveBeenCalledWith('/account/entries/pending/count')
})
it('confirmEntry → POST /account/entries/:id/confirm (payload 기본값 {})', () => {
accountApi.confirmEntry(7)
expect(http.post).toHaveBeenCalledWith('/account/entries/7/confirm', {})
})
it('createWallet → POST /account/wallets', () => {
const payload = { name: '주거래', type: 'ASSET' }
accountApi.createWallet(payload)
expect(http.post).toHaveBeenCalledWith('/account/wallets', payload)
})
})