mirror of
https://github.com/fsolla/teqo.git
synced 2026-11-26 21:53:06 +00:00
Add baseUpdatedAt CAS on domain staff writes, assertCampaignDocCas helper, opsDomainOutbox with hybrid forms (Manter/Usar), and int/unit pins. Closes #176. Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
43 lines
1.3 KiB
TypeScript
43 lines
1.3 KiB
TypeScript
import { describe, expect, it } from 'vitest'
|
|
|
|
import {
|
|
collapseLeadershipUpdateOutbox,
|
|
leadershipMembershipOutboxKey,
|
|
stateDeputyMunicipalitiesOutboxKey,
|
|
} from '@/components/campaign/opsSync/opsDomainOutboxModel'
|
|
import type { OfflineTransaction } from '@tanstack/offline-transactions'
|
|
|
|
const tx = (
|
|
id: string,
|
|
leadershipId: number,
|
|
createdAtMs: number,
|
|
): OfflineTransaction =>
|
|
({
|
|
id,
|
|
mutationFnName: 'updateLeadershipInternal',
|
|
mutations: [{ key: leadershipId } as OfflineTransaction['mutations'][number]],
|
|
keys: [String(leadershipId)],
|
|
idempotencyKey: id,
|
|
createdAt: new Date(createdAtMs),
|
|
retryCount: 0,
|
|
nextAttemptAt: createdAtMs,
|
|
metadata: { leadershipId },
|
|
version: 1,
|
|
}) as OfflineTransaction
|
|
|
|
describe('opsDomainOutboxModel (OH13)', () => {
|
|
it('collapses superseded leadership updates', () => {
|
|
const collapsed = collapseLeadershipUpdateOutbox([
|
|
tx('a', 1, 1000),
|
|
tx('b', 1, 3000),
|
|
tx('c', 2, 2000),
|
|
])
|
|
|
|
expect(collapsed.map((entry) => entry.id)).toEqual(['c', 'b'])
|
|
})
|
|
|
|
it('builds stable membership and batch keys', () => {
|
|
expect(leadershipMembershipOutboxKey('municipalities', 9, 3)).toBe('municipalities:9:3')
|
|
expect(stateDeputyMunicipalitiesOutboxKey(4, [3, 1, 2], true)).toBe('4:add:1,2,3')
|
|
})
|
|
})
|