|
| 1 | +import { test, mock } from "node:test"; |
| 2 | +import assert from "node:assert/strict"; |
| 3 | +import esmock from "esmock"; |
| 4 | + |
| 5 | +test("access tests", async () => { |
| 6 | + const { |
| 7 | + OPERATIONS, |
| 8 | + createEmailNotification, |
| 9 | + createPushNotification, |
| 10 | + sendNotification, |
| 11 | + } = await esmock("./03.02-notifications.js", { |
| 12 | + "./03.02-send-notification.js": { |
| 13 | + sendNotification: mock.fn(), |
| 14 | + }, |
| 15 | + }); |
| 16 | + |
| 17 | + assert.deepEqual(OPERATIONS, { |
| 18 | + SEND_EMAIL: "SEND_EMAIL", |
| 19 | + SEND_PUSH_NOTIFICATION: "SEND_PUSH_NOTIFICATION", |
| 20 | + }); |
| 21 | + assert.deepEqual( |
| 22 | + createEmailNotification( |
| 23 | + "hi@example.tld", |
| 24 | + "new email notification", |
| 25 | + "This is an email notification", |
| 26 | + ), |
| 27 | + { |
| 28 | + type: "SEND_EMAIL", |
| 29 | + payload: { |
| 30 | + to: "hi@example.tld", |
| 31 | + subject: "new email notification", |
| 32 | + content: "This is an email notification", |
| 33 | + }, |
| 34 | + }, |
| 35 | + ); |
| 36 | + assert.deepEqual( |
| 37 | + createPushNotification( |
| 38 | + "hi@example.tld", |
| 39 | + "new push notification", |
| 40 | + "This is a push notification", |
| 41 | + ), |
| 42 | + { |
| 43 | + type: "SEND_PUSH_NOTIFICATION", |
| 44 | + payload: { |
| 45 | + to: "hi@example.tld", |
| 46 | + title: "new push notification", |
| 47 | + content: "This is a push notification", |
| 48 | + }, |
| 49 | + }, |
| 50 | + ); |
| 51 | + |
| 52 | + sendNotification() |
| 53 | + |
| 54 | + assert.equal(sendNotification.mock.callCount(), 1); |
| 55 | +}); |
0 commit comments