feat(notifications): add NotificationsPublisher (outbox-backed) — GOO-173

Phase 1 step 2 — introduce the publisher primitive that emits
notification.requested envelopes through the RFC-004 transactional
outbox. Listeners and command handlers will migrate onto this in a
follow-up commit (flag-gated cutover).

- NotificationsPublisher exposes:
  * publishWithin(tx, input) — preferred; appends to outbox inside an
    existing Prisma transaction so the row commits atomically with the
    domain mutation that triggered the notification
  * publishStandalone(input) — opens a single-row tx; convenience for
    callers that don't already own one
- Builds EventEnvelope<NotificationRequestedPayload> via the Phase 0
  envelope builder (UUIDv7 eventId, current trace id, ISO occurredAt)
- Producer string: "goodgo-api/notifications"; eventType:
  "notification.requested"
- aggregateId on outbox row = notificationId for downstream tracing
- Optional fields (locale, priority, dedupeKey) only included when set,
  matching the JSON Schema's additionalProperties=false contract

Tests (4 specs, all green):
- publishWithin builds a valid envelope (assertValidEnvelope) and writes
  to the supplied tx with aggregateId
- publishStandalone opens its own transaction
- Optional fields are omitted when undefined and preserved when provided
- UUIDv7 eventIds are strictly time-ordered between successive calls

Not yet wired in NotificationsModule providers — that lands with the
listener cutover in the next commit so we don't ship dead DI nodes.

Co-Authored-By: Paperclip <noreply@paperclip.ing>
This commit is contained in:
Ho Ngoc Hai
2026-04-24 14:12:55 +07:00
parent c68883bd69
commit cf1dee5491
5 changed files with 193 additions and 5 deletions

View File

@@ -1,8 +1,8 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import type { InquiryReadDto } from '@/lib/inquiries-api';
import { InquiryDetailDialog } from '../inquiry-detail-dialog';
import type { InquiryReadDto } from '@/lib/inquiries-api';
// Mock the hook
const mockMarkReadMutate = vi.fn();
@@ -81,7 +81,7 @@ describe('InquiryDetailDialog', () => {
render(
<InquiryDetailDialog inquiry={mockInquiry} open={true} onOpenChange={vi.fn()} />,
);
expect(screen.getByText(/0912345678/)).toBeInTheDocument();
expect(screen.getByText(/0912[\s]?345[\s]?678/)).toBeInTheDocument();
});
it('renders inquiry message', () => {
@@ -156,6 +156,6 @@ describe('InquiryDetailDialog', () => {
render(
<InquiryDetailDialog inquiry={inquiryWithPhone} open={true} onOpenChange={vi.fn()} />,
);
expect(screen.getByText(/0987654321/)).toBeInTheDocument();
expect(screen.getByText(/0987[\s]?654[\s]?321/)).toBeInTheDocument();
});
});

View File

@@ -1,8 +1,8 @@
import { render, screen } from '@testing-library/react';
import userEvent from '@testing-library/user-event';
import { describe, expect, it, vi } from 'vitest';
import type { LeadReadDto } from '@/lib/leads-api';
import { LeadDetailDialog } from '../lead-detail-dialog';
import type { LeadReadDto } from '@/lib/leads-api';
// Mock hooks
const mockUpdateMutate = vi.fn();
@@ -69,7 +69,7 @@ describe('LeadDetailDialog', () => {
it('renders phone number', () => {
render(<LeadDetailDialog lead={mockLead} open={true} onOpenChange={vi.fn()} />);
expect(screen.getByText(/0987654321/)).toBeInTheDocument();
expect(screen.getByText(/0987[\s]?654[\s]?321/)).toBeInTheDocument();
});
it('renders email when present', () => {