teqo/tests/unit/notificationPushScheduleConventions.unit.spec.ts
Cursor Agent fb75f7235b
fix(P5-P1): schedule campaign notification push after txn commit
queueMicrotask under req.transactionID raced withPayloadTransaction
commit. Register after-commit callbacks, soft-fail missing notification
rows on send, and pin the schedule with a convention unit spec.
2026-08-03 04:40:38 +00:00

28 lines
1.2 KiB
TypeScript

import { readFileSync } from 'node:fs'
import { resolve } from 'node:path'
import { describe, expect, it } from 'vitest'
// Pass 5 P1: notification push must not be scheduled with `queueMicrotask` while
// the create still rides `req.transactionID` — microtasks flush before
// `withPayloadTransaction` commits. The create module must route txn-bound
// sends through `onPayloadTransactionCommit`.
describe('notification push schedule (Pass 5 P1)', () => {
const source = readFileSync(
resolve(process.cwd(), 'src/utilities/notification/createCampaignNotification.ts'),
'utf8',
)
it('registers push on withPayloadTransaction commit when a transactionID is present', () => {
expect(source).toMatch(/onPayloadTransactionCommit\s*\(/)
expect(source).toMatch(/req\?\.transactionID/)
})
it('does not schedule sendCampaignPush via queueMicrotask unconditionally', () => {
// Unconditional microtask around send was the P1 bug. A microtask only on
// the no-transaction branch remains allowed; the send call must not appear
// as the sole queueMicrotask body without a transactionID guard above it.
expect(source).not.toMatch(
/queueMicrotask\s*\(\s*\(\)\s*=>\s*\{\s*void sendCampaignPushForNotification/,
)
})
})