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