fix(restore): återställ default branch-filer som raderades av docs-publiceringen (7e33543)
Å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.
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
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)
|
||||
})
|
||||
})
|
||||
File diff suppressed because it is too large
Load Diff
@@ -0,0 +1,83 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import {
|
||||
mergeResumeItems,
|
||||
isSalaryRunLate,
|
||||
RESUME_MAX_ROWS,
|
||||
type ResumeItem,
|
||||
} from '../resume'
|
||||
|
||||
function item(overrides: Partial<ResumeItem>): ResumeItem {
|
||||
return {
|
||||
kind: 'journal_draft',
|
||||
ref: `journal:${Math.abs(overrides.updated_at?.length ?? 1)}`,
|
||||
href: '/bookkeeping/x',
|
||||
context: null,
|
||||
updated_at: '2026-07-01T10:00:00Z',
|
||||
...overrides,
|
||||
}
|
||||
}
|
||||
|
||||
describe('mergeResumeItems', () => {
|
||||
it('orders by updated_at desc', () => {
|
||||
const merged = mergeResumeItems([
|
||||
item({ ref: 'a', updated_at: '2026-07-01T10:00:00Z' }),
|
||||
item({ ref: 'b', updated_at: '2026-07-03T10:00:00Z' }),
|
||||
item({ ref: 'c', updated_at: '2026-07-02T10:00:00Z' }),
|
||||
])
|
||||
expect(merged.map((i) => i.ref)).toEqual(['b', 'c', 'a'])
|
||||
})
|
||||
|
||||
it('boosts late items above newer non-late items', () => {
|
||||
const merged = mergeResumeItems([
|
||||
item({ ref: 'fresh', updated_at: '2026-07-20T10:00:00Z' }),
|
||||
item({ ref: 'late-old', late: true, updated_at: '2026-05-01T10:00:00Z' }),
|
||||
])
|
||||
expect(merged[0].ref).toBe('late-old')
|
||||
})
|
||||
|
||||
it('caps at RESUME_MAX_ROWS', () => {
|
||||
const many = Array.from({ length: 7 }, (_, i) =>
|
||||
item({ ref: `r${i}`, updated_at: `2026-07-0${i + 1}T10:00:00Z` }),
|
||||
)
|
||||
expect(mergeResumeItems(many)).toHaveLength(RESUME_MAX_ROWS)
|
||||
})
|
||||
|
||||
it('keeps late-first ordering stable within groups', () => {
|
||||
const merged = mergeResumeItems([
|
||||
item({ ref: 'late-new', late: true, updated_at: '2026-07-10T10:00:00Z' }),
|
||||
item({ ref: 'late-old', late: true, updated_at: '2026-06-10T10:00:00Z' }),
|
||||
item({ ref: 'plain', updated_at: '2026-07-22T10:00:00Z' }),
|
||||
])
|
||||
expect(merged.map((i) => i.ref)).toEqual(['late-new', 'late-old', 'plain'])
|
||||
})
|
||||
|
||||
it('does not mutate the input array', () => {
|
||||
const input = [
|
||||
item({ ref: 'a', updated_at: '2026-07-01T10:00:00Z' }),
|
||||
item({ ref: 'b', updated_at: '2026-07-02T10:00:00Z' }),
|
||||
]
|
||||
const before = [...input]
|
||||
mergeResumeItems(input)
|
||||
expect(input).toEqual(before)
|
||||
})
|
||||
})
|
||||
|
||||
describe('isSalaryRunLate', () => {
|
||||
const now = new Date('2026-07-23T12:00:00Z')
|
||||
|
||||
it('flags a run two months past its period', () => {
|
||||
expect(isSalaryRunLate(2026, 5, now)).toBe(true)
|
||||
})
|
||||
|
||||
it('does not flag last month', () => {
|
||||
expect(isSalaryRunLate(2026, 6, now)).toBe(false)
|
||||
})
|
||||
|
||||
it('does not flag the current period', () => {
|
||||
expect(isSalaryRunLate(2026, 7, now)).toBe(false)
|
||||
})
|
||||
|
||||
it('handles year boundaries', () => {
|
||||
expect(isSalaryRunLate(2025, 12, now)).toBe(true)
|
||||
})
|
||||
})
|
||||
@@ -0,0 +1,27 @@
|
||||
import { describe, it, expect } from 'vitest'
|
||||
import { visibleWorklistTotal, visibleWorklistTotalFrom } from '../visible-total'
|
||||
import type { WorklistCounts } from '../types'
|
||||
|
||||
describe('visibleWorklistTotal', () => {
|
||||
it('subtracts inbox documents for non-payers so the count matches the hidden row', () => {
|
||||
expect(visibleWorklistTotal({ total: 5, inboxDocumentCount: 3, hasAi: false })).toBe(2)
|
||||
})
|
||||
|
||||
it('keeps inbox documents for payers (the row is shown)', () => {
|
||||
expect(visibleWorklistTotal({ total: 5, inboxDocumentCount: 3, hasAi: true })).toBe(5)
|
||||
})
|
||||
|
||||
it('adds dashboard-only extras (expiring bank connections)', () => {
|
||||
expect(visibleWorklistTotal({ total: 5, inboxDocumentCount: 3, hasAi: false, extra: 2 })).toBe(4)
|
||||
})
|
||||
|
||||
it('clamps to 0 rather than rendering a negative count on a count skew', () => {
|
||||
expect(visibleWorklistTotal({ total: 1, inboxDocumentCount: 3, hasAi: false })).toBe(0)
|
||||
})
|
||||
|
||||
it('from() reads total + inbox_document off the worklist object', () => {
|
||||
const worklist = { total: 4, counts: { inbox_document: 1 } } as unknown as WorklistCounts
|
||||
expect(visibleWorklistTotalFrom(worklist, false, 1)).toBe(4) // 4 + 1 - 1
|
||||
expect(visibleWorklistTotalFrom(worklist, true, 1)).toBe(5) // 4 + 1 - 0
|
||||
})
|
||||
})
|
||||
Reference in New Issue
Block a user