|
1 | 1 | // Copyright (c) 2026 ObjectStack. Licensed under the Apache-2.0 license. |
2 | 2 |
|
3 | 3 | import { describe, it, expect } from 'vitest'; |
4 | | -import type { SendEmailInput, SendTemplateInput } from './email-service'; |
| 4 | +import type { IEmailService, SendEmailInput, SendTemplateInput } from './email-service'; |
5 | 5 |
|
6 | 6 | /** |
7 | 7 | * Commit b706af987 (Decision 2 of #11303) — `SendEmailInput` is widened with an |
@@ -77,3 +77,35 @@ describe('Email Service Contract — SendTemplateInput.org retired', () => { |
77 | 77 | expect(input.template).toBe('auth.password_reset'); |
78 | 78 | }); |
79 | 79 | }); |
| 80 | + |
| 81 | +/** |
| 82 | + * `IEmailService.isConfigured` — the OPTIONAL deliverability member, shaped |
| 83 | + * like `ISmsService.isConfigured()`. Two contract facts pinned here: |
| 84 | + * - an implementation without the member stays assignable (the widening is |
| 85 | + * additive; absent reads as "unknown", never as delivering); |
| 86 | + * - when present it is a zero-argument function returning `boolean`. |
| 87 | + */ |
| 88 | +describe('Email Service Contract — isConfigured (optional deliverability member)', () => { |
| 89 | + const base = { |
| 90 | + send: async () => ({ id: 'e1', status: 'sent' as const }), |
| 91 | + sendTemplate: async () => ({ id: 'e1', status: 'sent' as const }), |
| 92 | + renderTemplate: async () => ({ subject: 's', html: 'h', text: 't' }), |
| 93 | + }; |
| 94 | + |
| 95 | + it('keeps an implementation without isConfigured assignable (absent = unknown)', () => { |
| 96 | + const legacy: IEmailService = { ...base }; |
| 97 | + expect(legacy.isConfigured).toBeUndefined(); |
| 98 | + }); |
| 99 | + |
| 100 | + it('accepts isConfigured(): boolean and refuses a non-boolean answer at compile time', () => { |
| 101 | + const svc: IEmailService = { ...base, isConfigured: () => false }; |
| 102 | + expect(svc.isConfigured?.()).toBe(false); |
| 103 | + |
| 104 | + type Member = NonNullable<IEmailService['isConfigured']>; |
| 105 | + const ok: Member = () => true; |
| 106 | + // @ts-expect-error isConfigured answers a boolean, not a string |
| 107 | + const bad: Member = () => 'yes'; |
| 108 | + expect(ok()).toBe(true); |
| 109 | + expect(typeof bad).toBe('function'); |
| 110 | + }); |
| 111 | +}); |
0 commit comments