1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 checkNewCommentOnMyVideo,
12 prepareNotificationsTest,
14 } from '@shared/extra-utils'
15 import { UserNotification } from '@shared/models'
17 const expect = chai.expect
19 describe('Test comments notifications', function () {
20 let servers: PeerTubeServer[] = []
22 let userNotifications: UserNotification[] = []
23 let emails: object[] = []
25 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
26 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
27 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
28 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
30 before(async function () {
33 const res = await prepareNotificationsTest(2)
35 userToken = res.userAccessToken
37 userNotifications = res.userNotifications
40 describe('Comment on my video notifications', function () {
41 let baseParams: CheckerBaseParams
47 socketNotifications: userNotifications,
52 it('Should not send a new comment notification after a comment on another video', async function () {
55 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
57 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
58 const commentId = created.id
60 await waitJobs(servers)
61 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
64 it('Should not send a new comment notification if I comment my own video', async function () {
67 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
69 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
70 const commentId = created.id
72 await waitJobs(servers)
73 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
76 it('Should not send a new comment notification if the account is muted', async function () {
79 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
81 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
83 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
84 const commentId = created.id
86 await waitJobs(servers)
87 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
89 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
92 it('Should send a new comment notification after a local comment on my video', async function () {
95 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
97 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
98 const commentId = created.id
100 await waitJobs(servers)
101 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
104 it('Should send a new comment notification after a remote comment on my video', async function () {
107 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
109 await waitJobs(servers)
111 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
113 await waitJobs(servers)
115 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
116 expect(data).to.have.lengthOf(1)
118 const commentId = data[0].id
119 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
122 it('Should send a new comment notification after a local reply on my video', async function () {
125 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
127 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
129 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
131 await waitJobs(servers)
132 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
135 it('Should send a new comment notification after a remote reply on my video', async function () {
138 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
139 await waitJobs(servers)
142 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
143 const threadId = created.id
144 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
147 await waitJobs(servers)
149 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
150 expect(data).to.have.lengthOf(1)
152 const threadId = data[0].id
153 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
155 expect(tree.children).to.have.lengthOf(1)
156 const commentId = tree.children[0].comment.id
158 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
161 it('Should convert markdown in comment to html', async function () {
164 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
166 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
168 await waitJobs(servers)
170 const latestEmail = emails[emails.length - 1]
171 expect(latestEmail['html']).to.contain(expectedHtml)
175 describe('Mention notifications', function () {
176 let baseParams: CheckerBaseParams
177 const byAccountDisplayName = 'super root name'
183 socketNotifications: userNotifications,
187 await servers[0].users.updateMe({ displayName: 'super root name' })
188 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
191 it('Should not send a new mention comment notification if I mention the video owner', async function () {
194 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
196 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
198 await waitJobs(servers)
199 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
202 it('Should not send a new mention comment notification if I mention myself', async function () {
205 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
207 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
209 await waitJobs(servers)
210 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
213 it('Should not send a new mention notification if the account is muted', async function () {
216 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
218 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
220 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
222 await waitJobs(servers)
223 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
225 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
228 it('Should not send a new mention notification if the remote account mention a local account', async function () {
231 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
233 await waitJobs(servers)
234 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
236 await waitJobs(servers)
238 const byAccountDisplayName = 'super root 2 name'
239 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
242 it('Should send a new mention notification after local comments', async function () {
245 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
247 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
249 await waitJobs(servers)
250 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
252 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
254 await waitJobs(servers)
255 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
258 it('Should send a new mention notification after remote comments', async function () {
261 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
263 await waitJobs(servers)
265 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
266 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
268 await waitJobs(servers)
270 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
271 expect(data).to.have.lengthOf(1)
273 const byAccountDisplayName = 'super root 2 name'
274 const threadId = data[0].id
275 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
277 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
278 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
280 await waitJobs(servers)
282 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
284 expect(tree.children).to.have.lengthOf(1)
285 const commentId = tree.children[0].comment.id
287 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
290 it('Should convert markdown in comment to html', async function () {
293 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
295 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
297 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
299 await waitJobs(servers)
301 const latestEmail = emails[emails.length - 1]
302 expect(latestEmail['html']).to.contain(expectedHtml)
306 after(async function () {
307 MockSmtpServer.Instance.kill()
309 await cleanupTests(servers)