teqo-backup/tests/unit/opsEstimateConflict.unit.spec.ts
Cursor Agent df4ee3fb76
feat(OH6): estimateVotesCas with optional baseEstimatedAt
Add CAS opt-in on vote pledge estimates: without baseEstimatedAt keep
last-write-wins; with a stale base refuse the write and stamp the
server estimatedAt for the outbox conflict toast.

Co-authored-by: Francisco Solla <fsolla@users.noreply.github.com>
2026-08-01 22:50:17 +00:00

29 lines
1.1 KiB
TypeScript

import { describe, expect, it } from 'vitest'
import {
isOpsEstimateConflictMessage,
OPS_ESTIMATE_CONFLICT_MESSAGE,
opsEstimateConflictError,
parseOpsEstimateConflictServerEstimatedAt,
} from '@/lib/schemas/votePledge'
describe('opsEstimateConflict helpers (OH6)', () => {
it('round-trips a stamped server estimatedAt through the error message', () => {
const stamped = opsEstimateConflictError('2026-08-01T12:00:00.000Z')
expect(isOpsEstimateConflictMessage(stamped.message)).toBe(true)
expect(parseOpsEstimateConflictServerEstimatedAt(stamped.message)).toBe(
'2026-08-01T12:00:00.000Z',
)
})
it('keeps the bare conflict message exact for safeMessages matching', () => {
const bare = opsEstimateConflictError(null)
expect(bare.message).toBe(OPS_ESTIMATE_CONFLICT_MESSAGE)
expect(parseOpsEstimateConflictServerEstimatedAt(bare.message)).toBeNull()
})
it('rejects unrelated messages', () => {
expect(isOpsEstimateConflictMessage('outro erro')).toBe(false)
expect(parseOpsEstimateConflictServerEstimatedAt('outro erro')).toBeNull()
})
})