Skip to content

Commit 8e0a2b2

Browse files
committed
add tests
1 parent 86045b7 commit 8e0a2b2

File tree

6 files changed

+2529
-6
lines changed

6 files changed

+2529
-6
lines changed

.github/workflows/test.yml

+30
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
name: CI/CD Pipeline
2+
3+
on:
4+
push:
5+
branches:
6+
- master
7+
pull_request:
8+
branches:
9+
- master
10+
11+
jobs:
12+
test:
13+
runs-on: ubuntu-latest
14+
steps:
15+
- name: Checkout Repo
16+
uses: actions/checkout@v4
17+
18+
- uses: pnpm/action-setup@v4
19+
20+
- name: Setup Node.js 20
21+
uses: actions/setup-node@v4
22+
with:
23+
node-version: 20
24+
cache: "pnpm"
25+
26+
- name: Install Dependencies
27+
run: pnpm install
28+
29+
- name: Run tests
30+
run: pnpm test

package.json

+1
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
"private": true,
44
"scripts": {
55
"build": "turbo build",
6+
"test": "turbo test",
67
"format": "prettier --write .",
78
"docs": "typedoc",
89
"version-packages": "changeset version && pnpm install --no-frozen-lockfile && pnpm format",

packages/core/package.json

+16-1
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,10 @@
66
"main": "dist/index.js",
77
"types": "dist/index.d.ts",
88
"scripts": {
9-
"build": "tsc"
9+
"build": "tsc",
10+
"watch:build": "tsc --watch > /dev/null",
11+
"test": "node --experimental-vm-modules node_modules/jest/bin/jest.js",
12+
"watch:test": "(trap 'kill 0' SIGINT; pnpm run build -w > /dev/null & pnpm run test --watch)"
1013
},
1114
"keywords": [
1215
"nostr"
@@ -47,8 +50,20 @@
4750
"zen-push": "^0.3.1"
4851
},
4952
"devDependencies": {
53+
"@jest/globals": "^29.7.0",
5054
"@types/debug": "^4.1.12",
55+
"@types/jest": "^29.5.13",
5156
"@types/zen-observable": "^0.8.7",
57+
"jest": "^29.7.0",
58+
"jest-extended": "^4.0.2",
5259
"zen-observable": "^0.10.0"
60+
},
61+
"jest": {
62+
"roots": [
63+
"dist"
64+
],
65+
"setupFilesAfterEnv": [
66+
"jest-extended/all"
67+
]
5368
}
5469
}
+143
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,143 @@
1+
/// <reference types="jest-extended" />
2+
import { NostrEvent } from "nostr-tools";
3+
import { getInboxes, getOutboxes } from "./mailboxes.js";
4+
5+
const emptyEvent: NostrEvent = {
6+
kind: 10002,
7+
content: "",
8+
tags: [],
9+
created_at: 0,
10+
sig: "",
11+
id: "",
12+
pubkey: "",
13+
};
14+
15+
describe("Mailboxes", () => {
16+
describe("getInboxes", () => {
17+
test("should transform urls", () => {
18+
expect(
19+
Array.from(
20+
getInboxes({
21+
...emptyEvent,
22+
tags: [["r", "wss://inbox.com"]],
23+
}),
24+
),
25+
).toIncludeAllMembers(["wss://inbox.com/"]);
26+
});
27+
28+
test("should remove bad urls", () => {
29+
expect(
30+
Array.from(
31+
getInboxes({
32+
...emptyEvent,
33+
tags: [["r", "bad://inbox.com"]],
34+
}),
35+
),
36+
).toBeArrayOfSize(0);
37+
38+
expect(
39+
Array.from(
40+
getInboxes({
41+
...emptyEvent,
42+
tags: [["r", "something that is not a url"]],
43+
}),
44+
),
45+
).toBeArrayOfSize(0);
46+
47+
expect(
48+
Array.from(
49+
getInboxes({
50+
...emptyEvent,
51+
tags: [["r", "wss://inbox.com,wss://inbox.org"]],
52+
}),
53+
),
54+
).toBeArrayOfSize(0);
55+
});
56+
57+
test("without marker", () => {
58+
expect(
59+
Array.from(
60+
getInboxes({
61+
...emptyEvent,
62+
tags: [["r", "wss://inbox.com/"]],
63+
}),
64+
),
65+
).toIncludeAllMembers(["wss://inbox.com/"]);
66+
});
67+
68+
test("with marker", () => {
69+
expect(
70+
Array.from(
71+
getInboxes({
72+
...emptyEvent,
73+
tags: [["r", "wss://inbox.com/", "read"]],
74+
}),
75+
),
76+
).toIncludeAllMembers(["wss://inbox.com/"]);
77+
});
78+
});
79+
80+
describe("getOutboxes", () => {
81+
test("should transform urls", () => {
82+
expect(
83+
Array.from(
84+
getOutboxes({
85+
...emptyEvent,
86+
tags: [["r", "wss://outbox.com"]],
87+
}),
88+
),
89+
).toIncludeAllMembers(["wss://outbox.com/"]);
90+
});
91+
92+
test("should remove bad urls", () => {
93+
expect(
94+
Array.from(
95+
getOutboxes({
96+
...emptyEvent,
97+
tags: [["r", "bad://inbox.com"]],
98+
}),
99+
),
100+
).toBeArrayOfSize(0);
101+
102+
expect(
103+
Array.from(
104+
getOutboxes({
105+
...emptyEvent,
106+
tags: [["r", "something that is not a url"]],
107+
}),
108+
),
109+
).toBeArrayOfSize(0);
110+
111+
expect(
112+
Array.from(
113+
getOutboxes({
114+
...emptyEvent,
115+
tags: [["r", "wss://outbox.com,wss://inbox.org"]],
116+
}),
117+
),
118+
).toBeArrayOfSize(0);
119+
});
120+
121+
test("without marker", () => {
122+
expect(
123+
Array.from(
124+
getOutboxes({
125+
...emptyEvent,
126+
tags: [["r", "wss://outbox.com/"]],
127+
}),
128+
),
129+
).toIncludeAllMembers(["wss://outbox.com/"]);
130+
});
131+
132+
test("with marker", () => {
133+
expect(
134+
Array.from(
135+
getOutboxes({
136+
...emptyEvent,
137+
tags: [["r", "wss://outbox.com/", "write"]],
138+
}),
139+
),
140+
).toIncludeAllMembers(["wss://outbox.com/"]);
141+
});
142+
});
143+
});

0 commit comments

Comments
 (0)