| 1 | import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from 'node:fs'; |
| 2 | import { tmpdir } |
| 3 | import { delimiter, join |
| 4 | import type { ConfigService |
| 5 | |
| 6 | import { mailConfigured, sendmailPath |
| 7 | |
| 8 | /** Build a ConfigService stub whose getter reads the supplied settings. */ |
| 9 | const config = ( |
| 10 | ({ get: ( |
| 11 | |
| 12 | describe('sendmail fallback', () |
| 13 | const name = |
| 14 | let dir: |
| 15 | beforeAll(() => |
| 16 | dir = mkdtempSync( |
| 17 | writeFileSync(join(dir |
| 18 | }); |
| 19 | afterAll(() => |
| 20 | |
| 21 | it('finds sendmail on PATH', |
| 22 | expect(sendmailPath(config |
| 23 | }); |
| 24 | |
| 25 | it.skipIf(process |
| 26 | 'skips non-executable candidates on PATH', |
| 27 | () => { |
| 28 | const firstDir = |
| 29 | mkdirSync(firstDir); |
| 30 | writeFileSync(join(firstDir |
| 31 | |
| 32 | expect( |
| 33 | sendmailPath(config({}) |
| 34 | ).toBe(join( |
| 35 | }, |
| 36 | ); |
| 37 | |
| 38 | it('skips directories on PATH', |
| 39 | const firstDir = |
| 40 | mkdirSync(join(firstDir |
| 41 | |
| 42 | expect( |
| 43 | sendmailPath(config({}) |
| 44 | ).toBe(join( |
| 45 | }); |
| 46 | |
| 47 | it('prefers SENDMAIL_PATH', |
| 48 | expect( |
| 49 | sendmailPath(config({ |
| 50 | ).toBe('/opt/bin/msmtp' |
| 51 | }); |
| 52 | |
| 53 | it('treats empty relay and SMTP settings as unset', |
| 54 | expect( |
| 55 | mailConfigured(config({ |
| 56 | ).toBe(true); |
| 57 | }); |
| 58 | }); |