|
| 1 | +// Copyright (c) 2025 ObjectStack. Licensed under the Apache-2.0 license. |
| 2 | + |
| 3 | +/** |
| 4 | + * #25190 — `renderNotification`, the renderer that took a template body inline, |
| 5 | + * is retired from this package's published entry (ruling 6335348115 on #25082, |
| 6 | + * F2 B3; ADR-0087 `runtime-export-retired`). The hole-placement rule is judged |
| 7 | + * by the `sys_notification_template` save hooks, and a body handed straight to |
| 8 | + * it was never saved, so it was the one door the rule could not see. |
| 9 | + * `interpolate` stays on the entry: it renders a plain-text face, which the |
| 10 | + * rule judges at no door. |
| 11 | + * |
| 12 | + * Pinned both ways: the entry no longer names it (the template store and the |
| 13 | + * channels stay), and a stored template row still renders through a channel |
| 14 | + * built from the entry — the html body with every hole encoded, the subject |
| 15 | + * (the plain-text face) verbatim. |
| 16 | + */ |
| 17 | + |
| 18 | +import { describe, it, expect } from 'vitest'; |
| 19 | +import * as entry from './index.js'; |
| 20 | + |
| 21 | +describe('service-messaging entry: the body-taking renderer is retired (#25190)', () => { |
| 22 | + it('the published entry does not export renderNotification', () => { |
| 23 | + expect('renderNotification' in entry).toBe(false); |
| 24 | + }); |
| 25 | + |
| 26 | + it('THE CONTROL: the entry still exports the template store, the plain-text face and the channels that render', () => { |
| 27 | + expect(typeof entry.NotificationTemplateStore).toBe('function'); |
| 28 | + expect(typeof entry.interpolate).toBe('function'); |
| 29 | + expect(entry.TEMPLATE_OBJECT).toBe('sys_notification_template'); |
| 30 | + expect(typeof entry.createEmailChannel).toBe('function'); |
| 31 | + expect(typeof entry.createSmsChannel).toBe('function'); |
| 32 | + }); |
| 33 | + |
| 34 | + it('a stored html template row still renders through the email channel', async () => { |
| 35 | + const row = { |
| 36 | + organization_id: 'org_1', |
| 37 | + topic: 'deal.won', |
| 38 | + channel: 'email', |
| 39 | + locale: 'en', |
| 40 | + is_active: true, |
| 41 | + format: 'html', |
| 42 | + subject: 'Won {{ payload.title }}', |
| 43 | + body: '<h1>{{ payload.title }}</h1>', |
| 44 | + }; |
| 45 | + const data = { |
| 46 | + async findOne(object: string, query: any) { |
| 47 | + const w = query?.where ?? {}; |
| 48 | + if (object === 'sys_user') return w.id === 'user_1' ? { email: 'ada@example.com' } : null; |
| 49 | + if (object === entry.TEMPLATE_OBJECT) { |
| 50 | + return row.organization_id === w.organization_id && row.topic === w.topic |
| 51 | + && row.channel === w.channel && row.locale === w.locale ? row : null; |
| 52 | + } |
| 53 | + return null; |
| 54 | + }, |
| 55 | + } as any; |
| 56 | + const sent: any[] = []; |
| 57 | + const ch = entry.createEmailChannel({ |
| 58 | + getEmail: () => ({ async send(input: any) { sent.push(input); return { id: 'email_row_1' }; } }) as any, |
| 59 | + getData: () => data, |
| 60 | + store: new entry.NotificationTemplateStore({ getData: () => data }), |
| 61 | + }); |
| 62 | + const logger = { info: () => {}, warn: () => {}, error: () => {} }; |
| 63 | + |
| 64 | + const r = await ch.send({ logger } as any, { |
| 65 | + channel: 'email', |
| 66 | + recipient: 'user_1', |
| 67 | + notification: { |
| 68 | + notificationId: 'evt_1', |
| 69 | + organizationId: 'org_1', |
| 70 | + topic: 'deal.won', |
| 71 | + title: 'A<b>', |
| 72 | + body: '', |
| 73 | + severity: 'info', |
| 74 | + recipients: ['user_1'], |
| 75 | + payload: { title: 'A<b>' }, |
| 76 | + }, |
| 77 | + } as any); |
| 78 | + |
| 79 | + expect(r.ok).toBe(true); |
| 80 | + expect(sent).toEqual([{ to: 'ada@example.com', subject: 'Won A<b>', html: '<h1>A<b></h1>', organizationId: 'org_1' }]); |
| 81 | + }); |
| 82 | +}); |
0 commit comments