1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import * as chai from 'chai'
7 checkNewCommentOnMyVideo,
9 prepareNotificationsTest
10 } from '@server/tests/shared'
11 import { UserNotification } from '@shared/models'
12 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
14 const expect = chai.expect
16 describe('Test comments notifications', function () {
17 let servers: PeerTubeServer[] = []
19 let userNotifications: UserNotification[] = []
20 let emails: object[] = []
22 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
23 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
24 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
25 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
27 before(async function () {
30 const res = await prepareNotificationsTest(2)
32 userToken = res.userAccessToken
34 userNotifications = res.userNotifications
37 describe('Comment on my video notifications', function () {
38 let baseParams: CheckerBaseParams
44 socketNotifications: userNotifications,
49 it('Should not send a new comment notification after a comment on another video', async function () {
52 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
54 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
55 const commentId = created.id
57 await waitJobs(servers)
58 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
61 it('Should not send a new comment notification if I comment my own video', async function () {
64 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
66 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
67 const commentId = created.id
69 await waitJobs(servers)
70 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
73 it('Should not send a new comment notification if the account is muted', async function () {
76 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
78 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
80 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
81 const commentId = created.id
83 await waitJobs(servers)
84 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
86 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
89 it('Should send a new comment notification after a local comment on my video', async function () {
92 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
94 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
95 const commentId = created.id
97 await waitJobs(servers)
98 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
101 it('Should send a new comment notification after a remote comment on my video', async function () {
104 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
106 await waitJobs(servers)
108 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
110 await waitJobs(servers)
112 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
113 expect(data).to.have.lengthOf(1)
115 const commentId = data[0].id
116 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
119 it('Should send a new comment notification after a local reply on my video', async function () {
122 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
124 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
126 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
128 await waitJobs(servers)
129 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
132 it('Should send a new comment notification after a remote reply on my video', async function () {
135 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
136 await waitJobs(servers)
139 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
140 const threadId = created.id
141 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
144 await waitJobs(servers)
146 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
147 expect(data).to.have.lengthOf(1)
149 const threadId = data[0].id
150 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
152 expect(tree.children).to.have.lengthOf(1)
153 const commentId = tree.children[0].comment.id
155 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
158 it('Should convert markdown in comment to html', async function () {
161 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
163 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
165 await waitJobs(servers)
167 const latestEmail = emails[emails.length - 1]
168 expect(latestEmail['html']).to.contain(expectedHtml)
172 describe('Mention notifications', function () {
173 let baseParams: CheckerBaseParams
174 const byAccountDisplayName = 'super root name'
180 socketNotifications: userNotifications,
184 await servers[0].users.updateMe({ displayName: 'super root name' })
185 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
188 it('Should not send a new mention comment notification if I mention the video owner', async function () {
191 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
193 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
195 await waitJobs(servers)
196 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
199 it('Should not send a new mention comment notification if I mention myself', async function () {
202 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
204 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
206 await waitJobs(servers)
207 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
210 it('Should not send a new mention notification if the account is muted', async function () {
213 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
215 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
217 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
219 await waitJobs(servers)
220 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
222 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
225 it('Should not send a new mention notification if the remote account mention a local account', async function () {
228 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
230 await waitJobs(servers)
231 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
233 await waitJobs(servers)
235 const byAccountDisplayName = 'super root 2 name'
236 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
239 it('Should send a new mention notification after local comments', async function () {
242 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
244 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
246 await waitJobs(servers)
247 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
249 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
251 await waitJobs(servers)
252 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
255 it('Should send a new mention notification after remote comments', async function () {
258 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
260 await waitJobs(servers)
262 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
263 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
265 await waitJobs(servers)
267 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
268 expect(data).to.have.lengthOf(1)
270 const byAccountDisplayName = 'super root 2 name'
271 const threadId = data[0].id
272 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
274 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
275 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
277 await waitJobs(servers)
279 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
281 expect(tree.children).to.have.lengthOf(1)
282 const commentId = tree.children[0].comment.id
284 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
287 it('Should convert markdown in comment to html', async function () {
290 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
292 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
294 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
296 await waitJobs(servers)
298 const latestEmail = emails[emails.length - 1]
299 expect(latestEmail['html']).to.contain(expectedHtml)
303 after(async function () {
304 MockSmtpServer.Instance.kill()
306 await cleanupTests(servers)