1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
6 addAccountToAccountBlocklist,
11 checkNewCommentOnMyVideo,
13 getVideoCommentThreads,
14 getVideoThreadComments,
16 prepareNotificationsTest,
17 removeAccountFromAccountBlocklist,
22 } from '@shared/extra-utils'
23 import { UserNotification, VideoCommentThreadTree } from '@shared/models'
25 const expect = chai.expect
27 describe('Test comments notifications', function () {
28 let servers: ServerInfo[] = []
29 let userAccessToken: string
30 let userNotifications: UserNotification[] = []
31 let emails: object[] = []
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?'
38 before(async function () {
41 const res = await prepareNotificationsTest(2)
43 userAccessToken = res.userAccessToken
45 userNotifications = res.userNotifications
48 describe('Comment on my video notifications', function () {
49 let baseParams: CheckerBaseParams
55 socketNotifications: userNotifications,
56 token: userAccessToken
60 it('Should not send a new comment notification after a comment on another video', async function () {
63 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
64 const uuid = resVideo.body.video.uuid
66 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
67 const commentId = resComment.body.comment.id
69 await waitJobs(servers)
70 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
73 it('Should not send a new comment notification if I comment my own video', async function () {
76 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
77 const uuid = resVideo.body.video.uuid
79 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
80 const commentId = resComment.body.comment.id
82 await waitJobs(servers)
83 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
86 it('Should not send a new comment notification if the account is muted', async function () {
89 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
91 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
92 const uuid = resVideo.body.video.uuid
94 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
95 const commentId = resComment.body.comment.id
97 await waitJobs(servers)
98 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
100 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
103 it('Should send a new comment notification after a local comment on my video', async function () {
106 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
107 const uuid = resVideo.body.video.uuid
109 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
110 const commentId = resComment.body.comment.id
112 await waitJobs(servers)
113 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
116 it('Should send a new comment notification after a remote comment on my video', async function () {
119 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
120 const uuid = resVideo.body.video.uuid
122 await waitJobs(servers)
124 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
126 await waitJobs(servers)
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
132 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
135 it('Should send a new comment notification after a local reply on my video', async function () {
138 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
139 const uuid = resVideo.body.video.uuid
141 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
142 const threadId = resThread.body.comment.id
144 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
145 const commentId = resComment.body.comment.id
147 await waitJobs(servers)
148 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
151 it('Should send a new comment notification after a remote reply on my video', async function () {
154 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
155 const uuid = resVideo.body.video.uuid
156 await waitJobs(servers)
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')
164 await waitJobs(servers)
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
170 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
171 const tree = resComments.body as VideoCommentThreadTree
173 expect(tree.children).to.have.lengthOf(1)
174 const commentId = tree.children[0].comment.id
176 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
179 it('Should convert markdown in comment to html', async function () {
182 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' })
183 const uuid = resVideo.body.video.uuid
185 await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText)
187 await waitJobs(servers)
189 const latestEmail = emails[emails.length - 1]
190 expect(latestEmail['html']).to.contain(expectedHtml)
194 describe('Mention notifications', function () {
195 let baseParams: CheckerBaseParams
201 socketNotifications: userNotifications,
202 token: userAccessToken
207 accessToken: servers[0].accessToken,
208 displayName: 'super root name'
213 accessToken: servers[1].accessToken,
214 displayName: 'super root 2 name'
218 it('Should not send a new mention comment notification if I mention the video owner', async function () {
221 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
222 const uuid = resVideo.body.video.uuid
224 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
225 const commentId = resComment.body.comment.id
227 await waitJobs(servers)
228 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
231 it('Should not send a new mention comment notification if I mention myself', async function () {
234 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
235 const uuid = resVideo.body.video.uuid
237 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
238 const commentId = resComment.body.comment.id
240 await waitJobs(servers)
241 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
244 it('Should not send a new mention notification if the account is muted', async function () {
247 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
249 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
250 const uuid = resVideo.body.video.uuid
252 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
253 const commentId = resComment.body.comment.id
255 await waitJobs(servers)
256 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
258 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
261 it('Should not send a new mention notification if the remote account mention a local account', async function () {
264 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
265 const uuid = resVideo.body.video.uuid
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
271 await waitJobs(servers)
272 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
275 it('Should send a new mention notification after local comments', async function () {
278 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
279 const uuid = resVideo.body.video.uuid
281 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
282 const threadId = resThread.body.comment.id
284 await waitJobs(servers)
285 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
287 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
288 const commentId = resComment.body.comment.id
290 await waitJobs(servers)
291 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
294 it('Should send a new mention notification after remote comments', async function () {
297 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
298 const uuid = resVideo.body.video.uuid
300 await waitJobs(servers)
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
306 await waitJobs(servers)
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')
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)
316 await waitJobs(servers)
318 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
319 const tree = resComments.body as VideoCommentThreadTree
321 expect(tree.children).to.have.lengthOf(1)
322 const commentId = tree.children[0].comment.id
324 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
327 it('Should convert markdown in comment to html', async function () {
330 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
331 const uuid = resVideo.body.video.uuid
333 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
334 const threadId = resThread.body.comment.id
336 await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText)
338 await waitJobs(servers)
340 const latestEmail = emails[emails.length - 1]
341 expect(latestEmail['html']).to.contain(expectedHtml)
345 after(async function () {
346 MockSmtpServer.Instance.kill()
348 await cleanupTests(servers)