]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/notifications/comments-notifications.ts
Introduce blocklist command
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / comments-notifications.ts
1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import {
6 addVideoCommentReply,
7 addVideoCommentThread,
8 checkCommentMention,
9 CheckerBaseParams,
10 checkNewCommentOnMyVideo,
11 cleanupTests,
12 getVideoCommentThreads,
13 getVideoThreadComments,
14 MockSmtpServer,
15 prepareNotificationsTest,
16 ServerInfo,
17 updateMyUser,
18 uploadVideo,
19 waitJobs
20 } from '@shared/extra-utils'
21 import { UserNotification, VideoCommentThreadTree } from '@shared/models'
22
23 const expect = chai.expect
24
25 describe('Test comments notifications', function () {
26 let servers: ServerInfo[] = []
27 let userAccessToken: string
28 let userNotifications: UserNotification[] = []
29 let emails: object[] = []
30
31 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
32 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
33 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
34 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
35
36 before(async function () {
37 this.timeout(120000)
38
39 const res = await prepareNotificationsTest(2)
40 emails = res.emails
41 userAccessToken = res.userAccessToken
42 servers = res.servers
43 userNotifications = res.userNotifications
44 })
45
46 describe('Comment on my video notifications', function () {
47 let baseParams: CheckerBaseParams
48
49 before(() => {
50 baseParams = {
51 server: servers[0],
52 emails,
53 socketNotifications: userNotifications,
54 token: userAccessToken
55 }
56 })
57
58 it('Should not send a new comment notification after a comment on another video', async function () {
59 this.timeout(20000)
60
61 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
62 const uuid = resVideo.body.video.uuid
63
64 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
65 const commentId = resComment.body.comment.id
66
67 await waitJobs(servers)
68 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
69 })
70
71 it('Should not send a new comment notification if I comment my own video', async function () {
72 this.timeout(20000)
73
74 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
75 const uuid = resVideo.body.video.uuid
76
77 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
78 const commentId = resComment.body.comment.id
79
80 await waitJobs(servers)
81 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
82 })
83
84 it('Should not send a new comment notification if the account is muted', async function () {
85 this.timeout(20000)
86
87 await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
88
89 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
90 const uuid = resVideo.body.video.uuid
91
92 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
93 const commentId = resComment.body.comment.id
94
95 await waitJobs(servers)
96 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
97
98 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
99 })
100
101 it('Should send a new comment notification after a local comment on my video', async function () {
102 this.timeout(20000)
103
104 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
105 const uuid = resVideo.body.video.uuid
106
107 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
108 const commentId = resComment.body.comment.id
109
110 await waitJobs(servers)
111 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
112 })
113
114 it('Should send a new comment notification after a remote comment on my video', async function () {
115 this.timeout(20000)
116
117 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
118 const uuid = resVideo.body.video.uuid
119
120 await waitJobs(servers)
121
122 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
123
124 await waitJobs(servers)
125
126 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
127 expect(resComment.body.data).to.have.lengthOf(1)
128 const commentId = resComment.body.data[0].id
129
130 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
131 })
132
133 it('Should send a new comment notification after a local reply on my video', async function () {
134 this.timeout(20000)
135
136 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
137 const uuid = resVideo.body.video.uuid
138
139 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
140 const threadId = resThread.body.comment.id
141
142 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
143 const commentId = resComment.body.comment.id
144
145 await waitJobs(servers)
146 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
147 })
148
149 it('Should send a new comment notification after a remote reply on my video', async function () {
150 this.timeout(20000)
151
152 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
153 const uuid = resVideo.body.video.uuid
154 await waitJobs(servers)
155
156 {
157 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
158 const threadId = resThread.body.comment.id
159 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
160 }
161
162 await waitJobs(servers)
163
164 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
165 expect(resThread.body.data).to.have.lengthOf(1)
166 const threadId = resThread.body.data[0].id
167
168 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
169 const tree = resComments.body as VideoCommentThreadTree
170
171 expect(tree.children).to.have.lengthOf(1)
172 const commentId = tree.children[0].comment.id
173
174 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
175 })
176
177 it('Should convert markdown in comment to html', async function () {
178 this.timeout(20000)
179
180 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' })
181 const uuid = resVideo.body.video.uuid
182
183 await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText)
184
185 await waitJobs(servers)
186
187 const latestEmail = emails[emails.length - 1]
188 expect(latestEmail['html']).to.contain(expectedHtml)
189 })
190 })
191
192 describe('Mention notifications', function () {
193 let baseParams: CheckerBaseParams
194
195 before(async () => {
196 baseParams = {
197 server: servers[0],
198 emails,
199 socketNotifications: userNotifications,
200 token: userAccessToken
201 }
202
203 await updateMyUser({
204 url: servers[0].url,
205 accessToken: servers[0].accessToken,
206 displayName: 'super root name'
207 })
208
209 await updateMyUser({
210 url: servers[1].url,
211 accessToken: servers[1].accessToken,
212 displayName: 'super root 2 name'
213 })
214 })
215
216 it('Should not send a new mention comment notification if I mention the video owner', async function () {
217 this.timeout(10000)
218
219 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
220 const uuid = resVideo.body.video.uuid
221
222 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
223 const commentId = resComment.body.comment.id
224
225 await waitJobs(servers)
226 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
227 })
228
229 it('Should not send a new mention comment notification if I mention myself', async function () {
230 this.timeout(10000)
231
232 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
233 const uuid = resVideo.body.video.uuid
234
235 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
236 const commentId = resComment.body.comment.id
237
238 await waitJobs(servers)
239 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
240 })
241
242 it('Should not send a new mention notification if the account is muted', async function () {
243 this.timeout(10000)
244
245 await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
246
247 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
248 const uuid = resVideo.body.video.uuid
249
250 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
251 const commentId = resComment.body.comment.id
252
253 await waitJobs(servers)
254 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
255
256 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
257 })
258
259 it('Should not send a new mention notification if the remote account mention a local account', async function () {
260 this.timeout(20000)
261
262 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
263 const uuid = resVideo.body.video.uuid
264
265 await waitJobs(servers)
266 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
267 const threadId = resThread.body.comment.id
268
269 await waitJobs(servers)
270 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
271 })
272
273 it('Should send a new mention notification after local comments', async function () {
274 this.timeout(10000)
275
276 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
277 const uuid = resVideo.body.video.uuid
278
279 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
280 const threadId = resThread.body.comment.id
281
282 await waitJobs(servers)
283 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
284
285 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
286 const commentId = resComment.body.comment.id
287
288 await waitJobs(servers)
289 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
290 })
291
292 it('Should send a new mention notification after remote comments', async function () {
293 this.timeout(20000)
294
295 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
296 const uuid = resVideo.body.video.uuid
297
298 await waitJobs(servers)
299
300 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
301 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
302 const server2ThreadId = resThread.body.comment.id
303
304 await waitJobs(servers)
305
306 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
307 expect(resThread2.body.data).to.have.lengthOf(1)
308 const server1ThreadId = resThread2.body.data[0].id
309 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
310
311 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
312 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
313
314 await waitJobs(servers)
315
316 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
317 const tree = resComments.body as VideoCommentThreadTree
318
319 expect(tree.children).to.have.lengthOf(1)
320 const commentId = tree.children[0].comment.id
321
322 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
323 })
324
325 it('Should convert markdown in comment to html', async function () {
326 this.timeout(10000)
327
328 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
329 const uuid = resVideo.body.video.uuid
330
331 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
332 const threadId = resThread.body.comment.id
333
334 await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText)
335
336 await waitJobs(servers)
337
338 const latestEmail = emails[emails.length - 1]
339 expect(latestEmail['html']).to.contain(expectedHtml)
340 })
341 })
342
343 after(async function () {
344 MockSmtpServer.Instance.kill()
345
346 await cleanupTests(servers)
347 })
348 })