20925f6c65
Part (a) of #2187. A twelfth worklist category, skattekonto_payment_due: the earliest upcoming skattekonto charge whose sum exceeds the last synced saldo, computed once in lib/worklist (server-side twin of the /skattekonto page's Nästa dragning math) and rendered as one Betala row on Hem with the shortfall, bankgiro 5050-1055, the OCR reference and the due date. The row appears only when money has to move: a saldo that covers the charge yields nothing, and no upcoming charge yields nothing. Ignored rows take part, since Skatteverket draws them regardless of our flag. Without a balance snapshot the full charge is the amount. Without an org number the row keeps its bankgiro and date and drops the OCR. No table, route or migration: /api/worklist/counts picks the category up through getWorklistCounts, and Hem passes the computed row into the same options wave as the expense payouts. Part (b), a betalfil for the skattekonto payment, stays a follow-up: the existing payment-file route is AGI-scoped. Claude-Session: https://claude.ai/code/session_0179bdetHyofL6ATfQxB5wP5 Co-authored-by: Jakob Wennberg <311770904+jakobwennberg-oss@users.noreply.github.com> Co-authored-by: Claude Fable 5.1 <noreply@anthropic.com>
86 lines
3.5 KiB
TypeScript
86 lines
3.5 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),
|
|
countExpensePayoutsDue: vi.fn().mockResolvedValue(2),
|
|
countSkattekontoPaymentDue: 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,
|
|
expense_payout: 2,
|
|
skattekonto_payment_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('takes the expense-payout count from a caller-supplied list instead of rescanning', async () => {
|
|
const { countExpensePayoutsDue } = await import('../categories')
|
|
const people = [{ key: 'owner:Anna' }, { key: 'emp-1' }, { key: 'emp-2' }] as never[]
|
|
const { counts } = await getWorklistCounts(supabase, 'company-1', {
|
|
expensePayoutsDue: Promise.resolve(people),
|
|
})
|
|
expect(counts.expense_payout).toBe(3)
|
|
expect(countExpensePayoutsDue).not.toHaveBeenCalled()
|
|
})
|
|
|
|
it('takes the skattekonto payment count from a caller-supplied value instead of rescanning', async () => {
|
|
const { countSkattekontoPaymentDue } = await import('../categories')
|
|
const due = { due: '2026-09-12', amount: 1000 } as never
|
|
const withDue = await getWorklistCounts(supabase, 'company-1', {
|
|
skattekontoPaymentDue: Promise.resolve(due),
|
|
})
|
|
expect(withDue.counts.skattekonto_payment_due).toBe(1)
|
|
// null is a value ("nothing to pay in"), not an absent option.
|
|
const without = await getWorklistCounts(supabase, 'company-1', { skattekontoPaymentDue: null })
|
|
expect(without.counts.skattekonto_payment_due).toBe(0)
|
|
expect(countSkattekontoPaymentDue).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 + 2 (people owed for utlägg) + 1
|
|
// (skattekonto payment), without the 2 suggested matches.
|
|
expect(total).toBe(33)
|
|
})
|
|
})
|