Skip to content

Commit 60dbdc2

Browse files
committed
[skip ci] migrate 03.02
1 parent aa49d3f commit 60dbdc2

5 files changed

Lines changed: 86 additions & 82 deletions

File tree

src/03.02-notifications.js

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,28 @@
1+
export { sendNotification } from "./03.02-send-notification.js";
2+
3+
export const OPERATIONS = {
4+
SEND_EMAIL: "SEND_EMAIL",
5+
SEND_PUSH_NOTIFICATION: "SEND_PUSH_NOTIFICATION",
6+
};
7+
8+
export function createEmailNotification(to, subject, content) {
9+
return {
10+
type: OPERATIONS.SEND_EMAIL,
11+
payload: {
12+
to,
13+
subject,
14+
content,
15+
},
16+
};
17+
}
18+
19+
export function createPushNotification(to, title, content) {
20+
return {
21+
type: OPERATIONS.SEND_PUSH_NOTIFICATION,
22+
payload: {
23+
to,
24+
title,
25+
content,
26+
},
27+
};
28+
}

src/03.02-notifications.test.js

Lines changed: 55 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,55 @@
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+
});

src/03.02-send-notification.js

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
export async function sendNotification() {
2+
// Send something to an API
3+
}

src/unmigrated/03.02-notifications.cjs

Lines changed: 0 additions & 37 deletions
This file was deleted.

src/unmigrated/03.02-notifications.test.js

Lines changed: 0 additions & 45 deletions
This file was deleted.

0 commit comments

Comments
 (0)