1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
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'
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'
20 const expect = chai.expect
22 describe('Test comments notifications', function () {
23 let servers: ServerInfo[] = []
24 let userAccessToken: string
25 let userNotifications: UserNotification[] = []
26 let emails: object[] = []
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?'
33 before(async function () {
36 const res = await prepareNotificationsTest(2)
38 userAccessToken = res.userAccessToken
40 userNotifications = res.userNotifications
43 describe('Comment on my video notifications', function () {
44 let baseParams: CheckerBaseParams
50 socketNotifications: userNotifications,
51 token: userAccessToken
55 it('Should not send a new comment notification after a comment on another video', async function () {
58 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
59 const uuid = resVideo.body.video.uuid
61 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
62 const commentId = resComment.body.comment.id
64 await waitJobs(servers)
65 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
68 it('Should not send a new comment notification if I comment my own video', async function () {
71 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
72 const uuid = resVideo.body.video.uuid
74 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
75 const commentId = resComment.body.comment.id
77 await waitJobs(servers)
78 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
81 it('Should not send a new comment notification if the account is muted', async function () {
84 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
86 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
87 const uuid = resVideo.body.video.uuid
89 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
90 const commentId = resComment.body.comment.id
92 await waitJobs(servers)
93 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
95 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
98 it('Should send a new comment notification after a local comment on my video', async function () {
101 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
102 const uuid = resVideo.body.video.uuid
104 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
105 const commentId = resComment.body.comment.id
107 await waitJobs(servers)
108 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
111 it('Should send a new comment notification after a remote comment on my video', async function () {
114 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
115 const uuid = resVideo.body.video.uuid
117 await waitJobs(servers)
119 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
121 await waitJobs(servers)
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
127 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
130 it('Should send a new comment notification after a local reply on my video', async function () {
133 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
134 const uuid = resVideo.body.video.uuid
136 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
137 const threadId = resThread.body.comment.id
139 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
140 const commentId = resComment.body.comment.id
142 await waitJobs(servers)
143 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
146 it('Should send a new comment notification after a remote reply on my video', async function () {
149 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
150 const uuid = resVideo.body.video.uuid
151 await waitJobs(servers)
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')
159 await waitJobs(servers)
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
165 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
166 const tree = resComments.body as VideoCommentThreadTree
168 expect(tree.children).to.have.lengthOf(1)
169 const commentId = tree.children[0].comment.id
171 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
174 it('Should convert markdown in comment to html', async function () {
177 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' })
178 const uuid = resVideo.body.video.uuid
180 await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText)
182 await waitJobs(servers)
184 const latestEmail = emails[emails.length - 1]
185 expect(latestEmail['html']).to.contain(expectedHtml)
189 describe('Mention notifications', function () {
190 let baseParams: CheckerBaseParams
196 socketNotifications: userNotifications,
197 token: userAccessToken
202 accessToken: servers[0].accessToken,
203 displayName: 'super root name'
208 accessToken: servers[1].accessToken,
209 displayName: 'super root 2 name'
213 it('Should not send a new mention comment notification if I mention the video owner', async function () {
216 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
217 const uuid = resVideo.body.video.uuid
219 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
220 const commentId = resComment.body.comment.id
222 await waitJobs(servers)
223 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
226 it('Should not send a new mention comment notification if I mention myself', async function () {
229 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
230 const uuid = resVideo.body.video.uuid
232 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
233 const commentId = resComment.body.comment.id
235 await waitJobs(servers)
236 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
239 it('Should not send a new mention notification if the account is muted', async function () {
242 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
244 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
245 const uuid = resVideo.body.video.uuid
247 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
248 const commentId = resComment.body.comment.id
250 await waitJobs(servers)
251 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
253 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
256 it('Should not send a new mention notification if the remote account mention a local account', async function () {
259 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
260 const uuid = resVideo.body.video.uuid
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
266 await waitJobs(servers)
267 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
270 it('Should send a new mention notification after local comments', async function () {
273 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
274 const uuid = resVideo.body.video.uuid
276 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
277 const threadId = resThread.body.comment.id
279 await waitJobs(servers)
280 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
282 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
283 const commentId = resComment.body.comment.id
285 await waitJobs(servers)
286 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
289 it('Should send a new mention notification after remote comments', async function () {
292 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
293 const uuid = resVideo.body.video.uuid
295 await waitJobs(servers)
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
301 await waitJobs(servers)
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')
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)
311 await waitJobs(servers)
313 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
314 const tree = resComments.body as VideoCommentThreadTree
316 expect(tree.children).to.have.lengthOf(1)
317 const commentId = tree.children[0].comment.id
319 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
322 it('Should convert markdown in comment to html', async function () {
325 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
326 const uuid = resVideo.body.video.uuid
328 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
329 const threadId = resThread.body.comment.id
331 await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText)
333 await waitJobs(servers)
335 const latestEmail = emails[emails.length - 1]
336 expect(latestEmail['html']).to.contain(expectedHtml)
340 after(async function () {
341 MockSmtpServer.Instance.kill()
343 await cleanupTests(servers)