]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/notifications/comments-notifications.ts
fd009e9d9b41dd17efaa5836c15e9368a5cff862
[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 { cleanupTests, getVideoCommentThreads, getVideoThreadComments, updateMyUser } from '../../../../shared/extra-utils'
6 import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
7 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
8 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
9 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
10 import {
11 checkCommentMention,
12 CheckerBaseParams,
13 checkNewCommentOnMyVideo,
14 prepareNotificationsTest
15 } from '../../../../shared/extra-utils/users/user-notifications'
16 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
17 import { UserNotification } from '../../../../shared/models/users'
18 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
19
20 const expect = chai.expect
21
22 describe('Test comments notifications', function () {
23 let servers: ServerInfo[] = []
24 let userAccessToken: string
25 let userNotifications: UserNotification[] = []
26 let emails: object[] = []
27
28 before(async function () {
29 this.timeout(120000)
30
31 const res = await prepareNotificationsTest(2)
32 emails = res.emails
33 userAccessToken = res.userAccessToken
34 servers = res.servers
35 userNotifications = res.userNotifications
36 })
37
38 describe('Comment on my video notifications', function () {
39 let baseParams: CheckerBaseParams
40
41 before(() => {
42 baseParams = {
43 server: servers[0],
44 emails,
45 socketNotifications: userNotifications,
46 token: userAccessToken
47 }
48 })
49
50 it('Should not send a new comment notification after a comment on another video', async function () {
51 this.timeout(10000)
52
53 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
54 const uuid = resVideo.body.video.uuid
55
56 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
57 const commentId = resComment.body.comment.id
58
59 await waitJobs(servers)
60 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
61 })
62
63 it('Should not send a new comment notification if I comment my own video', async function () {
64 this.timeout(10000)
65
66 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
67 const uuid = resVideo.body.video.uuid
68
69 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
70 const commentId = resComment.body.comment.id
71
72 await waitJobs(servers)
73 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
74 })
75
76 it('Should not send a new comment notification if the account is muted', async function () {
77 this.timeout(10000)
78
79 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
80
81 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
82 const uuid = resVideo.body.video.uuid
83
84 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
85 const commentId = resComment.body.comment.id
86
87 await waitJobs(servers)
88 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
89
90 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
91 })
92
93 it('Should send a new comment notification after a local comment on my video', async function () {
94 this.timeout(10000)
95
96 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
97 const uuid = resVideo.body.video.uuid
98
99 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
100 const commentId = resComment.body.comment.id
101
102 await waitJobs(servers)
103 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
104 })
105
106 it('Should send a new comment notification after a remote comment on my video', async function () {
107 this.timeout(10000)
108
109 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
110 const uuid = resVideo.body.video.uuid
111
112 await waitJobs(servers)
113
114 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
115
116 await waitJobs(servers)
117
118 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
119 expect(resComment.body.data).to.have.lengthOf(1)
120 const commentId = resComment.body.data[0].id
121
122 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
123 })
124
125 it('Should send a new comment notification after a local reply on my video', async function () {
126 this.timeout(10000)
127
128 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
129 const uuid = resVideo.body.video.uuid
130
131 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
132 const threadId = resThread.body.comment.id
133
134 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
135 const commentId = resComment.body.comment.id
136
137 await waitJobs(servers)
138 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
139 })
140
141 it('Should send a new comment notification after a remote reply on my video', async function () {
142 this.timeout(10000)
143
144 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
145 const uuid = resVideo.body.video.uuid
146 await waitJobs(servers)
147
148 {
149 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
150 const threadId = resThread.body.comment.id
151 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
152 }
153
154 await waitJobs(servers)
155
156 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
157 expect(resThread.body.data).to.have.lengthOf(1)
158 const threadId = resThread.body.data[0].id
159
160 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
161 const tree = resComments.body as VideoCommentThreadTree
162
163 expect(tree.children).to.have.lengthOf(1)
164 const commentId = tree.children[0].comment.id
165
166 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
167 })
168
169 it('Should convert markdown in comment to html', async function () {
170 this.timeout(10000)
171
172 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' })
173 const uuid = resVideo.body.video.uuid
174
175 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
176 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText)
177 const commentId = resComment.body.comment.id
178
179 await waitJobs(servers)
180 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
181
182 const latestEmail = emails[emails.length - 1]
183
184 const expected = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
185 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
186 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
187
188 expect(latestEmail['html']).to.contain(expected)
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 addAccountToAccountBlocklist(servers[0].url, userAccessToken, '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 removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, '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
326 after(async function () {
327 MockSmtpServer.Instance.kill()
328
329 await cleanupTests(servers)
330 })
331 })