| 1 | import { createTransport } from 'nodemailer'; |
| 2 | import { proxyTransport } |
| 3 | |
| 4 | describe('proxyTransport', () |
| 5 | const fetchMock = |
| 6 | beforeEach(() => |
| 7 | vi.stubGlobal('fetch |
| 8 | fetchMock.mockReset(); |
| 9 | }); |
| 10 | |
| 11 | it('posts the rendered mail to the relay', |
| 12 | fetchMock.mockResolvedValue({ |
| 13 | |
| 14 | await createTransport( |
| 15 | proxyTransport('https://relay.test', |
| 16 | ).sendMail({ |
| 17 | from: 'Ghost <noreply@ghost.local>', |
| 18 | to: 'user@example.com', |
| 19 | subject: 'Verify your email', |
| 20 | html: '<p>hi</p>', |
| 21 | }); |
| 22 | |
| 23 | const [url, |
| 24 | expect(url).toBe |
| 25 | expect(JSON.parse |
| 26 | to: 'user@example.com', |
| 27 | from: 'Ghost <noreply@ghost.local>', |
| 28 | subject: 'Verify your email', |
| 29 | htmlBody: '<p>hi</p>', |
| 30 | secret: 's3cret', |
| 31 | }); |
| 32 | }); |
| 33 | |
| 34 | it('fails the send when the relay rejects', |
| 35 | fetchMock.mockResolvedValue({ |
| 36 | ok: false, |
| 37 | status: 502, |
| 38 | text: async () |
| 39 | }); |
| 40 | |
| 41 | await expect( |
| 42 | createTransport(proxyTransport('https://relay.test |
| 43 | from: 'a@b.c', |
| 44 | to: 'user@example.com', |
| 45 | subject: 's', |
| 46 | html: 'x', |
| 47 | }), |
| 48 | ).rejects.toThrow( |
| 49 | }); |
| 50 | }); |