Files
accounted/lib/pending-operations/__tests__/company-settings-executor.test.ts
T
Mattsson e11f70b347 Bug/gh issues fiz (#1103)
* refactor: optimize page loading and data fetching

* fix: resolve recurring production runtime errors

* feat: add MCP company and customer updates

* fix: handle year-end tax adjustments

* feat: harden annual report compliance

* fix: expand invoice logo and font support

* fix: sanitize API route error responses

* fix: sanitize user-facing error messages

* feat: persist onboarding and tax assessment notices

* fix: reduce cloud backup audit churn

* feat: refine invoice editor layout

* fix: show saved tax adjustments in INK2

* fix: complete annual report API mappings

* docs: record operational safeguards and decisions

* fix: harden annual report review findings

* fix: adjust column span for description based on VAT registration

* New css class name
2026-07-21 23:00:15 +02:00

98 lines
2.6 KiB
TypeScript

import { beforeEach, describe, expect, it, vi } from 'vitest'
import type { PendingOperation } from '@/types'
import { createQueuedMockSupabase } from '@/tests/helpers'
import { commitPendingOperation } from '../commit'
function makePendingOp(params: Record<string, unknown>): PendingOperation {
return {
id: 'op-settings-1',
user_id: 'user-1',
company_id: 'company-1',
operation_type: 'update_company_settings',
status: 'pending',
title: 'Update company settings',
params,
preview_data: {},
result_data: null,
actor_type: 'api_key',
actor_id: 'key-1',
actor_label: 'Test key',
risk_level: 'medium',
agent_metadata: null,
rejection_category: null,
rejection_reason: null,
created_at: '2026-07-21T00:00:00Z',
resolved_at: null,
updated_at: '2026-07-21T00:00:00Z',
}
}
beforeEach(() => {
vi.clearAllMocks()
})
describe('commitPendingOperation: update_company_settings', () => {
it('updates only validated settings for the selected company', async () => {
const { supabase, enqueue } = createQueuedMockSupabase()
enqueue({ data: { id: 'op-settings-1' } })
enqueue({
data: {
bank_name: 'Testbanken',
clearing_number: '1234',
account_number: '1234567',
bankgiro: '5050-1055',
plusgiro: null,
swish: null,
iban: null,
bic: null,
default_our_reference: 'Test Contact',
},
})
enqueue({ data: null })
const result = await commitPendingOperation(
supabase as never,
'user-1',
'company-1',
makePendingOp({
changes: {
bank_name: 'Testbanken',
bankgiro: '5050-1055',
default_our_reference: 'Test Contact',
},
}),
)
expect(result.status).toBe('committed')
expect(result.data).toMatchObject({
company_id: 'company-1',
bankgiro: '5050-1055',
contact_person: 'Test Contact',
})
expect(supabase.from).toHaveBeenNthCalledWith(2, 'company_settings')
})
it('rejects tampered staged fields at the commit boundary', async () => {
const { supabase, enqueue } = createQueuedMockSupabase()
enqueue({ data: { id: 'op-settings-1' } })
enqueue({ data: null })
const result = await commitPendingOperation(
supabase as never,
'user-1',
'company-1',
makePendingOp({
changes: {
company_id: 'other-company',
bankgiro: '5050-1055',
},
}),
)
expect(result.status).toBe('failed')
expect(result.http_status).toBe(400)
expect(result.error).toMatch(/unrecognized key/i)
expect(supabase.from).toHaveBeenCalledTimes(2)
})
})