import assert from 'node:assert/strict'; import test from 'node:test'; import { createActivityBusinessEvent } from './business-events.ts'; import type { ActivityRecord } from '../api/types.ts'; function activity(overrides: Partial = {}): ActivityRecord { return { id: 'activity-1', activityCode: 'ACT2607-001', organizationId: 'org-1', primaryEntityType: 'opportunity', primaryEntityId: 'opp-1', primaryRecordLabel: 'EN-001 Project', relatedRecords: [], customerId: 'customer-1', contactId: null, leadId: null, opportunityId: 'opp-1', quotationId: null, activityType: 'follow_up', subject: 'Follow up', description: 'Pricing detail', ownerId: 'owner-1', ownerName: 'Owner', assignedToId: 'assignee-1', assignedToName: 'Assignee', scheduledStartAt: '2026-07-13T00:00:00.000Z', scheduledEndAt: null, dueAt: null, completedAt: null, cancelledAt: null, skippedAt: null, status: 'scheduled', effectiveStatus: 'scheduled', priority: 'normal', outcomeSummary: 'Sensitive outcome', cancellationReason: null, skipReason: null, nextAction: 'Call buyer', branchId: 'branch-1', productType: 'crane', isInternalOnly: false, isPricingSensitive: true, parentActivityId: null, metadata: null, createdBy: 'user-1', createdByName: 'User', createdAt: '2026-07-13T00:00:00.000Z', updatedBy: 'user-1', updatedByName: 'User', updatedAt: '2026-07-13T00:00:00.000Z', deletedAt: null, canViewPricingSensitiveContent: false, isContentRedacted: true, ...overrides }; } test('activity business event redacts pricing-sensitive narrative fields', () => { const event = createActivityBusinessEvent({ eventType: 'activity.completed', activity: activity(), actorUserId: 'user-1' }); assert.equal(event.visibility.pricingSensitive, true); assert.equal(event.payload.description, null); assert.equal(event.payload.outcomeSummary, null); assert.equal(event.payload.contentRedacted, true); }); test('activity business event preserves correlation and related context', () => { const event = createActivityBusinessEvent({ eventType: 'activity.created', activity: activity({ isPricingSensitive: false, description: 'Normal note' }), actorUserId: 'user-1', correlationId: 'corr-1' }); assert.equal(event.correlationId, 'corr-1'); assert.equal(event.primaryRecord.type, 'opportunity'); assert.equal(event.relatedRecords.some((record) => record.type === 'customer'), true); assert.equal(event.payload.description, 'Normal note'); });