diff options
author | Chocobozzz <me@florianbigard.com> | 2023-08-17 08:59:21 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2023-08-17 08:59:21 +0200 |
commit | c380e3928517eb5311b38cf257816642617d7a33 (patch) | |
tree | 2ea9b70ebca16b5d109bcce98fe7f944dad89319 /packages/tests/src/api/notifications/comments-notifications.ts | |
parent | a8ca6190fb462bf6eb5685cfc1d8ae444164a487 (diff) | |
parent | 3a4992633ee62d5edfbb484d9c6bcb3cf158489d (diff) | |
download | PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.gz PeerTube-c380e3928517eb5311b38cf257816642617d7a33.tar.zst PeerTube-c380e3928517eb5311b38cf257816642617d7a33.zip |
Merge branch 'feature/esm-and-nx' into develop
Diffstat (limited to 'packages/tests/src/api/notifications/comments-notifications.ts')
-rw-r--r-- | packages/tests/src/api/notifications/comments-notifications.ts | 300 |
1 files changed, 300 insertions, 0 deletions
diff --git a/packages/tests/src/api/notifications/comments-notifications.ts b/packages/tests/src/api/notifications/comments-notifications.ts new file mode 100644 index 000000000..5647d1286 --- /dev/null +++ b/packages/tests/src/api/notifications/comments-notifications.ts | |||
@@ -0,0 +1,300 @@ | |||
1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ | ||
2 | |||
3 | import { expect } from 'chai' | ||
4 | import { UserNotification } from '@peertube/peertube-models' | ||
5 | import { cleanupTests, PeerTubeServer, waitJobs } from '@peertube/peertube-server-commands' | ||
6 | import { MockSmtpServer } from '@tests/shared/mock-servers/mock-email.js' | ||
7 | import { prepareNotificationsTest, CheckerBaseParams, checkNewCommentOnMyVideo, checkCommentMention } from '@tests/shared/notifications.js' | ||
8 | |||
9 | describe('Test comments notifications', function () { | ||
10 | let servers: PeerTubeServer[] = [] | ||
11 | let userToken: string | ||
12 | let userNotifications: UserNotification[] = [] | ||
13 | let emails: object[] = [] | ||
14 | |||
15 | const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>' | ||
16 | const expectedHtml = '<strong>hello</strong> <a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer">world</a>' + | ||
17 | ', </p>what do you think about peertube?' | ||
18 | |||
19 | before(async function () { | ||
20 | this.timeout(120000) | ||
21 | |||
22 | const res = await prepareNotificationsTest(2) | ||
23 | emails = res.emails | ||
24 | userToken = res.userAccessToken | ||
25 | servers = res.servers | ||
26 | userNotifications = res.userNotifications | ||
27 | }) | ||
28 | |||
29 | describe('Comment on my video notifications', function () { | ||
30 | let baseParams: CheckerBaseParams | ||
31 | |||
32 | before(() => { | ||
33 | baseParams = { | ||
34 | server: servers[0], | ||
35 | emails, | ||
36 | socketNotifications: userNotifications, | ||
37 | token: userToken | ||
38 | } | ||
39 | }) | ||
40 | |||
41 | it('Should not send a new comment notification after a comment on another video', async function () { | ||
42 | this.timeout(30000) | ||
43 | |||
44 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
45 | |||
46 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | ||
47 | const commentId = created.id | ||
48 | |||
49 | await waitJobs(servers) | ||
50 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) | ||
51 | }) | ||
52 | |||
53 | it('Should not send a new comment notification if I comment my own video', async function () { | ||
54 | this.timeout(30000) | ||
55 | |||
56 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
57 | |||
58 | const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' }) | ||
59 | const commentId = created.id | ||
60 | |||
61 | await waitJobs(servers) | ||
62 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) | ||
63 | }) | ||
64 | |||
65 | it('Should not send a new comment notification if the account is muted', async function () { | ||
66 | this.timeout(30000) | ||
67 | |||
68 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) | ||
69 | |||
70 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
71 | |||
72 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | ||
73 | const commentId = created.id | ||
74 | |||
75 | await waitJobs(servers) | ||
76 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' }) | ||
77 | |||
78 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) | ||
79 | }) | ||
80 | |||
81 | it('Should send a new comment notification after a local comment on my video', async function () { | ||
82 | this.timeout(30000) | ||
83 | |||
84 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
85 | |||
86 | const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | ||
87 | const commentId = created.id | ||
88 | |||
89 | await waitJobs(servers) | ||
90 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) | ||
91 | }) | ||
92 | |||
93 | it('Should send a new comment notification after a remote comment on my video', async function () { | ||
94 | this.timeout(30000) | ||
95 | |||
96 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
97 | |||
98 | await waitJobs(servers) | ||
99 | |||
100 | await servers[1].comments.createThread({ videoId: uuid, text: 'comment' }) | ||
101 | |||
102 | await waitJobs(servers) | ||
103 | |||
104 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | ||
105 | expect(data).to.have.lengthOf(1) | ||
106 | |||
107 | const commentId = data[0].id | ||
108 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' }) | ||
109 | }) | ||
110 | |||
111 | it('Should send a new comment notification after a local reply on my video', async function () { | ||
112 | this.timeout(30000) | ||
113 | |||
114 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
115 | |||
116 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' }) | ||
117 | |||
118 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) | ||
119 | |||
120 | await waitJobs(servers) | ||
121 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) | ||
122 | }) | ||
123 | |||
124 | it('Should send a new comment notification after a remote reply on my video', async function () { | ||
125 | this.timeout(30000) | ||
126 | |||
127 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
128 | await waitJobs(servers) | ||
129 | |||
130 | { | ||
131 | const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' }) | ||
132 | const threadId = created.id | ||
133 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' }) | ||
134 | } | ||
135 | |||
136 | await waitJobs(servers) | ||
137 | |||
138 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | ||
139 | expect(data).to.have.lengthOf(1) | ||
140 | |||
141 | const threadId = data[0].id | ||
142 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) | ||
143 | |||
144 | expect(tree.children).to.have.lengthOf(1) | ||
145 | const commentId = tree.children[0].comment.id | ||
146 | |||
147 | await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' }) | ||
148 | }) | ||
149 | |||
150 | it('Should convert markdown in comment to html', async function () { | ||
151 | this.timeout(30000) | ||
152 | |||
153 | const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } }) | ||
154 | |||
155 | await servers[0].comments.createThread({ videoId: uuid, text: commentText }) | ||
156 | |||
157 | await waitJobs(servers) | ||
158 | |||
159 | const latestEmail = emails[emails.length - 1] | ||
160 | expect(latestEmail['html']).to.contain(expectedHtml) | ||
161 | }) | ||
162 | }) | ||
163 | |||
164 | describe('Mention notifications', function () { | ||
165 | let baseParams: CheckerBaseParams | ||
166 | const byAccountDisplayName = 'super root name' | ||
167 | |||
168 | before(async function () { | ||
169 | baseParams = { | ||
170 | server: servers[0], | ||
171 | emails, | ||
172 | socketNotifications: userNotifications, | ||
173 | token: userToken | ||
174 | } | ||
175 | |||
176 | await servers[0].users.updateMe({ displayName: 'super root name' }) | ||
177 | await servers[1].users.updateMe({ displayName: 'super root 2 name' }) | ||
178 | }) | ||
179 | |||
180 | it('Should not send a new mention comment notification if I mention the video owner', async function () { | ||
181 | this.timeout(30000) | ||
182 | |||
183 | const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } }) | ||
184 | |||
185 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | ||
186 | |||
187 | await waitJobs(servers) | ||
188 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) | ||
189 | }) | ||
190 | |||
191 | it('Should not send a new mention comment notification if I mention myself', async function () { | ||
192 | this.timeout(30000) | ||
193 | |||
194 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
195 | |||
196 | const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' }) | ||
197 | |||
198 | await waitJobs(servers) | ||
199 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) | ||
200 | }) | ||
201 | |||
202 | it('Should not send a new mention notification if the account is muted', async function () { | ||
203 | this.timeout(30000) | ||
204 | |||
205 | await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' }) | ||
206 | |||
207 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
208 | |||
209 | const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | ||
210 | |||
211 | await waitJobs(servers) | ||
212 | await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' }) | ||
213 | |||
214 | await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' }) | ||
215 | }) | ||
216 | |||
217 | it('Should not send a new mention notification if the remote account mention a local account', async function () { | ||
218 | this.timeout(30000) | ||
219 | |||
220 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
221 | |||
222 | await waitJobs(servers) | ||
223 | const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' }) | ||
224 | |||
225 | await waitJobs(servers) | ||
226 | |||
227 | const byAccountDisplayName = 'super root 2 name' | ||
228 | await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' }) | ||
229 | }) | ||
230 | |||
231 | it('Should send a new mention notification after local comments', async function () { | ||
232 | this.timeout(30000) | ||
233 | |||
234 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
235 | |||
236 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' }) | ||
237 | |||
238 | await waitJobs(servers) | ||
239 | await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' }) | ||
240 | |||
241 | const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' }) | ||
242 | |||
243 | await waitJobs(servers) | ||
244 | await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) | ||
245 | }) | ||
246 | |||
247 | it('Should send a new mention notification after remote comments', async function () { | ||
248 | this.timeout(30000) | ||
249 | |||
250 | const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
251 | |||
252 | await waitJobs(servers) | ||
253 | |||
254 | const text1 = `hello @user_1@${servers[0].host} 1` | ||
255 | const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 }) | ||
256 | |||
257 | await waitJobs(servers) | ||
258 | |||
259 | const { data } = await servers[0].comments.listThreads({ videoId: uuid }) | ||
260 | expect(data).to.have.lengthOf(1) | ||
261 | |||
262 | const byAccountDisplayName = 'super root 2 name' | ||
263 | const threadId = data[0].id | ||
264 | await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' }) | ||
265 | |||
266 | const text2 = `@user_1@${servers[0].host} hello 2 @root@${servers[0].host}` | ||
267 | await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 }) | ||
268 | |||
269 | await waitJobs(servers) | ||
270 | |||
271 | const tree = await servers[0].comments.getThread({ videoId: uuid, threadId }) | ||
272 | |||
273 | expect(tree.children).to.have.lengthOf(1) | ||
274 | const commentId = tree.children[0].comment.id | ||
275 | |||
276 | await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' }) | ||
277 | }) | ||
278 | |||
279 | it('Should convert markdown in comment to html', async function () { | ||
280 | this.timeout(30000) | ||
281 | |||
282 | const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } }) | ||
283 | |||
284 | const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' }) | ||
285 | |||
286 | await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText }) | ||
287 | |||
288 | await waitJobs(servers) | ||
289 | |||
290 | const latestEmail = emails[emails.length - 1] | ||
291 | expect(latestEmail['html']).to.contain(expectedHtml) | ||
292 | }) | ||
293 | }) | ||
294 | |||
295 | after(async function () { | ||
296 | MockSmtpServer.Instance.kill() | ||
297 | |||
298 | await cleanupTests(servers) | ||
299 | }) | ||
300 | }) | ||