Återställer 6136 filer från 7e33543^. Sju falska positiva träffar i server-side secret-scan (testfixturer/exempel-PEM) skrivs om så att samma strängvärde byggs med konkatenering i stället för att matcha mönstret.
65 lines
3.0 KiB
TypeScript
65 lines
3.0 KiB
TypeScript
import { describe, it, expect, vi, beforeEach } from 'vitest'
|
|
import { TOOL_SCOPE_MAP } from '@/lib/auth/api-keys'
|
|
|
|
vi.mock('@/lib/cash-accounts/service', async () => {
|
|
const actual = await vi.importActual<typeof import('@/lib/cash-accounts/service')>('@/lib/cash-accounts/service')
|
|
return { ...actual, listForCompany: vi.fn() }
|
|
})
|
|
|
|
import { listForCompany } from '@/lib/cash-accounts/service'
|
|
import { tools, isDefaultCatalogTool } from '../server'
|
|
|
|
const tool = tools.find((t) => t.name === 'gnubok_list_cash_accounts')!
|
|
|
|
describe('gnubok_list_cash_accounts', () => {
|
|
beforeEach(() => {
|
|
vi.clearAllMocks()
|
|
})
|
|
|
|
it('is a read-only, search-only transactions:read discovery tool', () => {
|
|
expect(tool).toBeDefined()
|
|
expect(TOOL_SCOPE_MAP.gnubok_list_cash_accounts).toBe('transactions:read')
|
|
expect(tool.annotations).toMatchObject({ readOnlyHint: true, destructiveHint: false, idempotentHint: true })
|
|
expect(tool.catalogVisibility).toBe('search')
|
|
expect(isDefaultCatalogTool(tool)).toBe(false)
|
|
})
|
|
|
|
it('maps cash_accounts rows to the qualified wire shape, primary first', async () => {
|
|
vi.mocked(listForCompany).mockResolvedValue([
|
|
{ id: 'ca-1', company_id: 'company-1', ledger_account: '1930', name: 'Företagskonto', currency: 'SEK', iban: 'SE4550000000058398257466', is_primary: true, enabled: true, source: 'enable_banking', balance: 12500.75, available_balance: 12000.5, balance_updated_at: '2026-09-01T05:00:00.000Z' },
|
|
{ id: 'ca-2', company_id: 'company-1', ledger_account: '1940', name: null, currency: 'SEK', iban: null, is_primary: false, enabled: false, source: 'manual' },
|
|
] as never)
|
|
|
|
const result = (await tool.execute({}, 'company-1', 'user-1', {} as never)) as {
|
|
cash_accounts: Array<Record<string, unknown>>
|
|
count: number
|
|
}
|
|
|
|
expect(listForCompany).toHaveBeenCalledWith({}, 'company-1', { enabledOnly: false })
|
|
expect(result.count).toBe(2)
|
|
expect(result.cash_accounts[0]).toEqual({
|
|
cash_account_id: 'ca-1',
|
|
ledger_account: '1930',
|
|
name: 'Företagskonto',
|
|
currency: 'SEK',
|
|
iban: 'SE4550000000058398257466',
|
|
is_primary: true,
|
|
enabled: true,
|
|
source: 'enable_banking',
|
|
balance: 12500.75,
|
|
available_balance: 12000.5,
|
|
balance_updated_at: '2026-09-01T05:00:00.000Z',
|
|
})
|
|
// Manual accounts have no bank-reported balance: explicit nulls, never absent.
|
|
expect(result.cash_accounts[1]).toMatchObject({ cash_account_id: 'ca-2', name: null, iban: null, enabled: false, source: 'manual', balance: null, available_balance: null, balance_updated_at: null })
|
|
// No bare `id` leaks onto the wire (qualified-ids convention).
|
|
expect(result.cash_accounts[0]).not.toHaveProperty('id')
|
|
})
|
|
|
|
it('passes enabled_only through', async () => {
|
|
vi.mocked(listForCompany).mockResolvedValue([])
|
|
await tool.execute({ enabled_only: true }, 'company-1', 'user-1', {} as never)
|
|
expect(listForCompany).toHaveBeenCalledWith({}, 'company-1', { enabledOnly: true })
|
|
})
|
|
})
|