delivery-sms-honest.test.ts69 lines · main
1/**
2 * Offline SMS honesty + email branding HTML (no Doltgres).
3 * Full path: bun scripts/sms-polish-proof.mjs (needs local engine DB).
4 */
5import { describe, expect, test } from 'bun:test';
6
7import {
8 buildBrivenEngineAuthEmailHtml,
9 sendBrivenEngineSms,
10 sendBrivenEngineSmsTest,
11} from './delivery.js';
12
13describe('briven-engine SMS honest delivery (offline)', () => {
14 test('test helper rejects non-E.164 phone without hitting provider', async () => {
15 const r = await sendBrivenEngineSmsTest({
16 projectId: 'p_any',
17 phoneNumber: '5551234',
18 });
19 expect(r.ok).toBe(false);
20 expect(r.mode).toBe('error');
21 expect(r.message?.toLowerCase()).toContain('e.164');
22 });
23
24 test('SMS without projectId is not a silent success', async () => {
25 const r = await sendBrivenEngineSms({
26 phoneNumber: '+15551234567',
27 userInputCode: '123456',
28 type: 'PASSWORDLESS_LOGIN',
29 });
30 expect(r.ok).toBe(false);
31 expect(r.mode).toBe('log');
32 expect(r.channel).toBe('sms');
33 expect(r.engine).toBe('briven-engine');
34 expect(r.message?.toLowerCase()).toMatch(/project/);
35 });
36});
37
38describe('briven-engine auth email branding HTML', () => {
39 test('includes sender name, accent color, and escaped body', () => {
40 const html = buildBrivenEngineAuthEmailHtml({
41 body: 'Your code: 123456\nExpires soon.',
42 branding: {
43 logoUrl: null,
44 primaryColor: '#FFFD74',
45 senderName: 'Konnos',
46 },
47 });
48 expect(html).toContain('Konnos');
49 expect(html).toContain('#FFFD74');
50 expect(html).toContain('Your code: 123456');
51 expect(html).not.toContain('<script>');
52 });
53
54 test('escapes HTML in body and drops unsafe logo URLs', () => {
55 const html = buildBrivenEngineAuthEmailHtml({
56 body: '<b>hi</b>',
57 branding: {
58 logoUrl: 'https://example.com/x.png" onerror="alert(1)',
59 primaryColor: '#112233',
60 senderName: 'App <x>',
61 },
62 });
63 expect(html).toContain('&lt;b&gt;hi&lt;/b&gt;');
64 expect(html).toContain('App &lt;x&gt;');
65 expect(html).not.toContain('onerror');
66 expect(html).not.toContain('<img');
67 });
68});
69