Files
accounted/lib/worklist/__tests__/aggregate.test.ts
T
Jakob Wennberg 1e91c126ff fix(worklist): count unbooked skattekonto rows in the Att göra badge and Hem list (#2180) (#2227)
The Transaktioner inbox lists unbooked skattekonto rows next to unbooked
bank rows, but the sidebar badge and the Hem "Att göra" list counted bank
rows only, so a migrated tax account waited in the inbox unseen.

- lib/worklist: new category book_skattekonto with the inbox's own
  predicate (status = 'booked', no verifikat, not ignored); aggregate
  includes it in counts and total.
- Hem: a "Bokföra skattekontohändelser" row under Bokför, deep-linking to
  /transactions?source=skatteverket.
- Sidebar badge hook: the same third head-count query, summed into the
  /transactions badge.
- DashboardNav subscribes to skattekonto_transactions realtime changes;
  migration adds the table to the supabase_realtime publication so a
  booked or ignored row drops the badge without a manual refresh.

Closes #2180


Claude-Session: https://claude.ai/code/session_01QPQLwHNEiQfiCNLSMzXMiQ

Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com>
Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
2026-09-03 17:17:41 +02:00

58 lines
2.1 KiB
TypeScript

import { describe, it, expect, vi, beforeEach } from 'vitest'
import type { SupabaseClient } from '@supabase/supabase-js'
vi.mock('../categories', () => ({
countUnbookedTransactions: vi.fn().mockResolvedValue(4),
countUnbookedSkattekontoRows: vi.fn().mockResolvedValue(7),
countInboxDocuments: vi.fn().mockResolvedValue(6),
countSuggestedMatches: vi.fn().mockResolvedValue(2),
countSupplierInvoicesAwaitingApproval: vi.fn().mockResolvedValue(1),
countVerifikatMissingDocument: vi.fn().mockResolvedValue(3),
countOverdueInvoices: vi.fn().mockResolvedValue(5),
countDeadlinesNeedingAction: vi.fn().mockResolvedValue(1),
countPendingOperations: vi.fn().mockResolvedValue(2),
countReconciliationDue: vi.fn().mockResolvedValue(1),
}))
import { getWorklistCounts } from '../aggregate'
const supabase = {} as SupabaseClient
beforeEach(() => {
vi.clearAllMocks()
})
describe('getWorklistCounts', () => {
it('aggregates every category', async () => {
const { counts } = await getWorklistCounts(supabase, 'company-1')
expect(counts).toEqual({
book_transaction: 4,
book_skattekonto: 7,
inbox_document: 6,
suggested_match: 2,
supplier_invoice_approval: 1,
verifikat_missing_document: 3,
overdue_invoice: 5,
deadline_action: 1,
pending_operations: 2,
reconciliation_due: 1,
})
})
it('takes the suggested-match count from a caller-supplied list instead of rescanning', async () => {
const { countSuggestedMatches } = await import('../categories')
const matches = [{ transactionId: 't1' }, { transactionId: 't2' }, { transactionId: 't3' }] as never[]
const { counts } = await getWorklistCounts(supabase, 'company-1', {
suggestedMatches: Promise.resolve(matches),
})
expect(counts.suggested_match).toBe(3)
expect(countSuggestedMatches).not.toHaveBeenCalled()
})
it('excludes suggested_match from the total (subset of book_transaction)', async () => {
const { total } = await getWorklistCounts(supabase, 'company-1')
// 4 + 7 + 6 + 1 + 3 + 5 + 1 + 2 + 1, without the 2 suggested matches.
expect(total).toBe(30)
})
})