Files
accounted/lib/transactions/__tests__/underlag-status.test.ts
T
Jakob WennbergandClaude Fable 5 0521c385d2 feat(transactions): underlag status badges + attach dialog; auto-expire stale pending ops (#712)
* feat(transactions): per-row underlag status + attach-document dialog

- New "Matcha mot underlag" dialog on /transactions (inbox pick or fresh
  upload), the tx→doc mirror of the Documents view's matcher
- Per-row Underlag/Underlag saknas badges on booked history rows, driven
  by computeJeUnderlagStatus — same posted-only, exemption-aware scope as
  the worklist count so badge and count never disagree
- attach-document route + commit dispatcher now propagate the doc onto
  the verifikation when the tx is already booked (BFL 5 kap 6 §), with a
  409 guard for docs consumed by a different verifikation, idempotent
  re-attach (no same-value rewrite under period lock), and an honest 409
  when the period-lock trigger blocks the propagation
- Booking-dialog doc links also pin the doc to the transaction row
  (first linked doc wins) via the link route's new transaction_id param

messages/{sv,en}.json also carries the strings for the pending-ops
expiry UI that lands in the next commit.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* feat(pending-operations): auto-expire stale staged operations after 30 days

- New daily cron (02:30 UTC, vercel.json + both docker crontabs) flips
  >30-day-old pending ops to rejected with the dispatcher's
  { auto_rejected: true, reason: 'expired' } result_data shape — rows are
  never deleted, the table is the audit trail
- /pending renders an "Utgick automatiskt" badge + detail line for these,
  orders terminal tabs by resolved_at so a fresh expiry sweep isn't
  buried, and adds a first-time-reviewer explainer
- Origin labels spell out where a proposal came from (AI chat, MCP key,
  API, cron) instead of the raw actor_label
- agent_chat actor type added to PendingOperationActorType/AuditLogEntry
  (DB CHECK already widened in 20260519090000) and to the agent filter
- ApprovalCard notes that ignoring a proposal is safe

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* docs(mcp): surface the client telemetry marker in connect instructions

Tag the connector URLs shown in ApiKeysPanel, the connect-claude doc and
the gnubok-mcp README with ?client=<surface> (claude-connector /
claude-code) and GNUBOK_CLIENT=claude-desktop for the npm bridge.
Telemetry-only — the server already reads the param/header; this just
lets us measure which Claude surface connected.

The claude mcp add copy blocks quote the URL: an unquoted ? in the query
string trips zsh globbing ("no matches found").

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

* review: fix stale-closure badge flip + zod-validate link route body (PR #712)

- handleDocumentAttached read journal_entry_id off the render-time
  transactions snapshot; if the list changed while the attach dialog was
  open the optimistic badge flip was silently skipped. Read it off the
  dialog's own subject (attachDocTx) instead.
- POST /api/documents/[id]/link now validates the body against the new
  LinkDocumentSchema (uuid-strict, all four fields) instead of a bare
  presence check on journal_entry_id — same canonical VALIDATION_ERROR
  envelope. Test fixtures switched to real UUIDs accordingly.

Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>

---------

Co-authored-by: Claude Fable 5 <noreply@anthropic.com>
2026-06-11 11:13:51 +02:00

67 lines
2.0 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { computeJeUnderlagStatus } from '../underlag-status'
describe('computeJeUnderlagStatus', () => {
it('marks entries with a current-version document as has', () => {
const result = computeJeUnderlagStatus(
[{ id: 'je-1', source_type: 'bank_transaction' }],
new Set(['je-1']),
new Set(),
)
expect(result['je-1']).toBe('has')
})
it('marks doc-requiring entries without documents as missing', () => {
const result = computeJeUnderlagStatus(
[
{ id: 'je-1', source_type: 'bank_transaction' },
{ id: 'je-2', source_type: 'manual' },
{ id: 'je-3', source_type: 'import' },
],
new Set(),
new Set(),
)
expect(result).toEqual({ 'je-1': 'missing', 'je-2': 'missing', 'je-3': 'missing' })
})
it('respects journal_entry_no_doc_required exemptions', () => {
const result = computeJeUnderlagStatus(
[{ id: 'je-1', source_type: 'manual' }],
new Set(),
new Set(['je-1']),
)
expect(result['je-1']).toBe('none')
})
it('never flags system-generated source types (exempt by omission)', () => {
const result = computeJeUnderlagStatus(
[
{ id: 'je-1', source_type: 'vat_settlement' },
{ id: 'je-2', source_type: 'invoice_payment' },
{ id: 'je-3', source_type: 'year_end' },
],
new Set(),
new Set(),
)
expect(result).toEqual({ 'je-1': 'none', 'je-2': 'none', 'je-3': 'none' })
})
it('treats null source_type as no statement', () => {
const result = computeJeUnderlagStatus(
[{ id: 'je-1', source_type: null }],
new Set(),
new Set(),
)
expect(result['je-1']).toBe('none')
})
it('has wins over missing when both a doc and a needs-doc source type are present', () => {
const result = computeJeUnderlagStatus(
[{ id: 'je-1', source_type: 'manual' }],
new Set(['je-1']),
new Set(['je-1']),
)
expect(result['je-1']).toBe('has')
})
})