1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 checkNewCommentOnMyVideo,
11 prepareNotificationsTest,
16 } from '@shared/extra-utils'
17 import { UserNotification } from '@shared/models'
19 const expect = chai.expect
21 describe('Test comments notifications', function () {
22 let servers: ServerInfo[] = []
24 let userNotifications: UserNotification[] = []
25 let emails: object[] = []
27 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
28 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
29 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
30 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
32 before(async function () {
35 const res = await prepareNotificationsTest(2)
37 userToken = res.userAccessToken
39 userNotifications = res.userNotifications
42 describe('Comment on my video notifications', function () {
43 let baseParams: CheckerBaseParams
49 socketNotifications: userNotifications,
54 it('Should not send a new comment notification after a comment on another video', async function () {
57 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
58 const uuid = resVideo.body.video.uuid
60 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
61 const commentId = created.id
63 await waitJobs(servers)
64 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
67 it('Should not send a new comment notification if I comment my own video', async function () {
70 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
71 const uuid = resVideo.body.video.uuid
73 const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
74 const commentId = created.id
76 await waitJobs(servers)
77 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
80 it('Should not send a new comment notification if the account is muted', async function () {
83 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
85 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
86 const uuid = resVideo.body.video.uuid
88 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
89 const commentId = created.id
91 await waitJobs(servers)
92 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
94 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
97 it('Should send a new comment notification after a local comment on my video', async function () {
100 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
101 const uuid = resVideo.body.video.uuid
103 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
104 const commentId = created.id
106 await waitJobs(servers)
107 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
110 it('Should send a new comment notification after a remote comment on my video', async function () {
113 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
114 const uuid = resVideo.body.video.uuid
116 await waitJobs(servers)
118 await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
120 await waitJobs(servers)
122 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
123 expect(data).to.have.lengthOf(1)
125 const commentId = data[0].id
126 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
129 it('Should send a new comment notification after a local reply on my video', async function () {
132 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
133 const uuid = resVideo.body.video.uuid
135 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
137 const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
139 await waitJobs(servers)
140 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
143 it('Should send a new comment notification after a remote reply on my video', async function () {
146 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
147 const uuid = resVideo.body.video.uuid
148 await waitJobs(servers)
151 const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
152 const threadId = created.id
153 await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
156 await waitJobs(servers)
158 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
159 expect(data).to.have.lengthOf(1)
161 const threadId = data[0].id
162 const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId })
164 expect(tree.children).to.have.lengthOf(1)
165 const commentId = tree.children[0].comment.id
167 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
170 it('Should convert markdown in comment to html', async function () {
173 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'cool video' })
174 const uuid = resVideo.body.video.uuid
176 await servers[0].commentsCommand.createThread({ videoId: uuid, text: commentText })
178 await waitJobs(servers)
180 const latestEmail = emails[emails.length - 1]
181 expect(latestEmail['html']).to.contain(expectedHtml)
185 describe('Mention notifications', function () {
186 let baseParams: CheckerBaseParams
192 socketNotifications: userNotifications,
198 accessToken: servers[0].accessToken,
199 displayName: 'super root name'
204 accessToken: servers[1].accessToken,
205 displayName: 'super root 2 name'
209 it('Should not send a new mention comment notification if I mention the video owner', async function () {
212 const resVideo = await uploadVideo(servers[0].url, userToken, { name: 'super video' })
213 const uuid = resVideo.body.video.uuid
215 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
217 await waitJobs(servers)
218 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
221 it('Should not send a new mention comment notification if I mention myself', async function () {
224 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
225 const uuid = resVideo.body.video.uuid
227 const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
229 await waitJobs(servers)
230 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
233 it('Should not send a new mention notification if the account is muted', async function () {
236 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
238 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
239 const uuid = resVideo.body.video.uuid
241 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
243 await waitJobs(servers)
244 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
246 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
249 it('Should not send a new mention notification if the remote account mention a local account', async function () {
252 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
253 const uuid = resVideo.body.video.uuid
255 await waitJobs(servers)
256 const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
258 await waitJobs(servers)
259 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
262 it('Should send a new mention notification after local comments', async function () {
265 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
266 const uuid = resVideo.body.video.uuid
268 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
270 await waitJobs(servers)
271 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
273 const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
275 await waitJobs(servers)
276 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
279 it('Should send a new mention notification after remote comments', async function () {
282 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
283 const uuid = resVideo.body.video.uuid
285 await waitJobs(servers)
287 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
288 const { id: server2ThreadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: text1 })
290 await waitJobs(servers)
292 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
293 expect(data).to.have.lengthOf(1)
295 const server1ThreadId = data[0].id
296 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
298 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
299 await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
301 await waitJobs(servers)
303 const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId })
305 expect(tree.children).to.have.lengthOf(1)
306 const commentId = tree.children[0].comment.id
308 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
311 it('Should convert markdown in comment to html', async function () {
314 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
315 const uuid = resVideo.body.video.uuid
317 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
319 await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
321 await waitJobs(servers)
323 const latestEmail = emails[emails.length - 1]
324 expect(latestEmail['html']).to.contain(expectedHtml)
328 after(async function () {
329 MockSmtpServer.Instance.kill()
331 await cleanupTests(servers)