Files

19 lines
1.1 KiB
JavaScript

import assert from 'node:assert/strict'
import test from 'node:test'
import { isTimestampOlderThan, webhookEventClaimDecision } from '../src/reliability.js'
test('completed webhooks deduplicate while failed and expired processing events can resume', () => {
const now = Date.parse('2026-08-01T12:00:00.000Z')
assert.equal(webhookEventClaimDecision({ status: 'completed' }, now), 'duplicate')
assert.equal(webhookEventClaimDecision({ status: 'failed' }, now), 'claim')
assert.equal(webhookEventClaimDecision({ status: 'processing', processingAt: '2026-08-01T11:59:30.000Z' }, now), 'busy')
assert.equal(webhookEventClaimDecision({ status: 'processing', processingAt: '2026-08-01T11:57:00.000Z' }, now), 'claim')
})
test('missing timestamps are due and recent maintenance timestamps are not', () => {
const now = Date.parse('2026-08-01T12:00:00.000Z')
assert.equal(isTimestampOlderThan(undefined, 60_000, now), true)
assert.equal(isTimestampOlderThan('2026-08-01T11:58:00.000Z', 60_000, now), true)
assert.equal(isTimestampOlderThan('2026-08-01T11:59:30.000Z', 60_000, now), false)
})