Files
accounted/lib/skatteverket/__tests__/sync-order.test.ts
T
admin e7f0070e84
masterplan-lock / check (push) Successful in 19s
ci / sonar (push) Failing after 21s
security / scan (push) Failing after 1m37s
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.
2026-11-10 09:37:22 +01:00

34 lines
1.1 KiB
TypeScript

import { describe, it, expect } from 'vitest'
import { orderByStalestSync } from '../sync-order'
describe('orderByStalestSync', () => {
const work = [
{ companyId: 'a', userId: 'u' },
{ companyId: 'b', userId: 'u' },
{ companyId: 'c', userId: 'u' },
{ companyId: 'd', userId: 'u' },
]
it('puts never-synced companies first, then the longest-ago synced, and keeps ties stable', () => {
const last = new Map<string, string | null>([
['a', '2026-08-23T01:00:00Z'],
['b', '2026-08-22T01:00:00Z'],
['c', null],
// d: no row at all
])
expect(orderByStalestSync(work, last).map((w) => w.companyId)).toEqual(['c', 'd', 'b', 'a'])
})
it('keeps the incoming order when nothing is known', () => {
expect(orderByStalestSync(work, new Map()).map((w) => w.companyId)).toEqual(['a', 'b', 'c', 'd'])
})
it('treats an unparseable timestamp as never synced', () => {
const last = new Map<string, string | null>([
['a', 'not-a-date'],
['b', '2026-08-22T01:00:00Z'],
])
expect(orderByStalestSync(work, last).map((w) => w.companyId)).toEqual(['a', 'c', 'd', 'b'])
})
})