| 1 | import { createDatabase, type Database, type Pool, schema } from '@ghost/db'; |
| 2 | import type { ConfigService |
| 3 | import type { MailerService |
| 4 | import { like } |
| 5 | import { afterAll, beforeAll |
| 6 | |
| 7 | import ThreadComment from './templates/thread-comment.js |
| 8 | import { MailService } |
| 9 | |
| 10 | const CONNECTION = process |
| 11 | const KEY = ` |
| 12 | |
| 13 | // Touches only the delivery_job rows it inserts, so it can share a dev database. |
| 14 | describe.skipIf(!CONNECTION |
| 15 | let db: |
| 16 | let pool: |
| 17 | |
| 18 | beforeAll(() => |
| 19 | ({ db, pool |
| 20 | }); |
| 21 | |
| 22 | afterAll(async () |
| 23 | await db |
| 24 | .delete(schema.deliveryJob |
| 25 | .where(like(schema |
| 26 | await pool.end |
| 27 | }); |
| 28 | |
| 29 | it('render once into a delivery job instead of sending', |
| 30 | const sendMail = |
| 31 | const config = |
| 32 | get: (name: |
| 33 | } as unknown as |
| 34 | const mail = |
| 35 | { sendMail } as |
| 36 | config, |
| 37 | db, |
| 38 | ); |
| 39 | const { appUrl: |
| 40 | const email = |
| 41 | template: 'thread-comment' as |
| 42 | threadId: 'issue_1', |
| 43 | subject: '[alice/ghost] Bell count (#42)', |
| 44 | context, |
| 45 | idempotencyKey: KEY, |
| 46 | }; |
| 47 | |
| 48 | await mail.sendThreadEmail |
| 49 | await mail.sendThreadEmail |
| 50 | |
| 51 | expect(sendMail).not |
| 52 | const jobs = |
| 53 | .select() |
| 54 | .from(schema.deliveryJob |
| 55 | .where(like(schema |
| 56 | expect(jobs).toHaveLength |
| 57 | expect(jobs[0] |
| 58 | const payload = |
| 59 | expect(payload.to |
| 60 | expect(payload.subject |
| 61 | expect(payload.html |
| 62 | expect(payload.text |
| 63 | expect(payload.text |
| 64 | 'http://localhost:3000/alice/ghost/issues/42', |
| 65 | ); |
| 66 | }); |
| 67 | }); |