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