1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
10 checkNewCommentOnMyVideo,
12 getVideoCommentThreads,
13 getVideoThreadComments,
15 prepareNotificationsTest,
20 } from '@shared/extra-utils'
21 import { UserNotification, VideoCommentThreadTree } from '@shared/models'
23 const expect = chai.expect
25 describe('Test comments notifications', function () {
26 let servers: ServerInfo[] = []
27 let userAccessToken: string
28 let userNotifications: UserNotification[] = []
29 let emails: object[] = []
31 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
32 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
33 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
34 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
36 before(async function () {
39 const res = await prepareNotificationsTest(2)
41 userAccessToken = res.userAccessToken
43 userNotifications = res.userNotifications
46 describe('Comment on my video notifications', function () {
47 let baseParams: CheckerBaseParams
53 socketNotifications: userNotifications,
54 token: userAccessToken
58 it('Should not send a new comment notification after a comment on another video', async function () {
61 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
62 const uuid = resVideo.body.video.uuid
64 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
65 const commentId = resComment.body.comment.id
67 await waitJobs(servers)
68 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
71 it('Should not send a new comment notification if I comment my own video', async function () {
74 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
75 const uuid = resVideo.body.video.uuid
77 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
78 const commentId = resComment.body.comment.id
80 await waitJobs(servers)
81 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
84 it('Should not send a new comment notification if the account is muted', async function () {
87 await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
89 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
90 const uuid = resVideo.body.video.uuid
92 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
93 const commentId = resComment.body.comment.id
95 await waitJobs(servers)
96 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
98 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
101 it('Should send a new comment notification after a local comment on my video', async function () {
104 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
105 const uuid = resVideo.body.video.uuid
107 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
108 const commentId = resComment.body.comment.id
110 await waitJobs(servers)
111 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
114 it('Should send a new comment notification after a remote comment on my video', async function () {
117 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
118 const uuid = resVideo.body.video.uuid
120 await waitJobs(servers)
122 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
124 await waitJobs(servers)
126 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
127 expect(resComment.body.data).to.have.lengthOf(1)
128 const commentId = resComment.body.data[0].id
130 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
133 it('Should send a new comment notification after a local reply on my video', async function () {
136 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
137 const uuid = resVideo.body.video.uuid
139 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
140 const threadId = resThread.body.comment.id
142 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
143 const commentId = resComment.body.comment.id
145 await waitJobs(servers)
146 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
149 it('Should send a new comment notification after a remote reply on my video', async function () {
152 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
153 const uuid = resVideo.body.video.uuid
154 await waitJobs(servers)
157 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
158 const threadId = resThread.body.comment.id
159 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
162 await waitJobs(servers)
164 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
165 expect(resThread.body.data).to.have.lengthOf(1)
166 const threadId = resThread.body.data[0].id
168 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
169 const tree = resComments.body as VideoCommentThreadTree
171 expect(tree.children).to.have.lengthOf(1)
172 const commentId = tree.children[0].comment.id
174 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
177 it('Should convert markdown in comment to html', async function () {
180 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'cool video' })
181 const uuid = resVideo.body.video.uuid
183 await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, commentText)
185 await waitJobs(servers)
187 const latestEmail = emails[emails.length - 1]
188 expect(latestEmail['html']).to.contain(expectedHtml)
192 describe('Mention notifications', function () {
193 let baseParams: CheckerBaseParams
199 socketNotifications: userNotifications,
200 token: userAccessToken
205 accessToken: servers[0].accessToken,
206 displayName: 'super root name'
211 accessToken: servers[1].accessToken,
212 displayName: 'super root 2 name'
216 it('Should not send a new mention comment notification if I mention the video owner', async function () {
219 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
220 const uuid = resVideo.body.video.uuid
222 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
223 const commentId = resComment.body.comment.id
225 await waitJobs(servers)
226 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
229 it('Should not send a new mention comment notification if I mention myself', async function () {
232 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
233 const uuid = resVideo.body.video.uuid
235 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
236 const commentId = resComment.body.comment.id
238 await waitJobs(servers)
239 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
242 it('Should not send a new mention notification if the account is muted', async function () {
245 await servers[0].blocklistCommand.addToMyBlocklist({ token: userAccessToken, account: 'root' })
247 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
248 const uuid = resVideo.body.video.uuid
250 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
251 const commentId = resComment.body.comment.id
253 await waitJobs(servers)
254 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
256 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userAccessToken, account: 'root' })
259 it('Should not send a new mention notification if the remote account mention a local account', async function () {
262 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
263 const uuid = resVideo.body.video.uuid
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
269 await waitJobs(servers)
270 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
273 it('Should send a new mention notification after local comments', async function () {
276 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
277 const uuid = resVideo.body.video.uuid
279 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
280 const threadId = resThread.body.comment.id
282 await waitJobs(servers)
283 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
285 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
286 const commentId = resComment.body.comment.id
288 await waitJobs(servers)
289 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
292 it('Should send a new mention notification after remote comments', async function () {
295 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
296 const uuid = resVideo.body.video.uuid
298 await waitJobs(servers)
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
304 await waitJobs(servers)
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')
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)
314 await waitJobs(servers)
316 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
317 const tree = resComments.body as VideoCommentThreadTree
319 expect(tree.children).to.have.lengthOf(1)
320 const commentId = tree.children[0].comment.id
322 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
325 it('Should convert markdown in comment to html', async function () {
328 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
329 const uuid = resVideo.body.video.uuid
331 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
332 const threadId = resThread.body.comment.id
334 await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, '@user_1 ' + commentText)
336 await waitJobs(servers)
338 const latestEmail = emails[emails.length - 1]
339 expect(latestEmail['html']).to.contain(expectedHtml)
343 after(async function () {
344 MockSmtpServer.Instance.kill()
346 await cleanupTests(servers)