1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } 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 describe('Test comments notifications', function () {
15 let servers: PeerTubeServer[] = []
17 let userNotifications: UserNotification[] = []
18 let emails: object[] = []
20 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
21 const expectedHtml = '<strong>hello</strong> <a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer">world</a>' +
22 ', </p>what do you think about peertube?'
24 before(async function () {
27 const res = await prepareNotificationsTest(2)
29 userToken = res.userAccessToken
31 userNotifications = res.userNotifications
34 describe('Comment on my video notifications', function () {
35 let baseParams: CheckerBaseParams
41 socketNotifications: userNotifications,
46 it('Should not send a new comment notification after a comment on another video', async function () {
49 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
51 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
52 const commentId = created.id
54 await waitJobs(servers)
55 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
58 it('Should not send a new comment notification if I comment my own video', async function () {
61 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
63 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
64 const commentId = created.id
66 await waitJobs(servers)
67 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
70 it('Should not send a new comment notification if the account is muted', async function () {
73 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
75 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
77 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
78 const commentId = created.id
80 await waitJobs(servers)
81 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
83 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
86 it('Should send a new comment notification after a local comment on my video', async function () {
89 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
91 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
92 const commentId = created.id
94 await waitJobs(servers)
95 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
98 it('Should send a new comment notification after a remote comment on my video', async function () {
101 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
103 await waitJobs(servers)
105 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
107 await waitJobs(servers)
109 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
110 expect(data).to.have.lengthOf(1)
112 const commentId = data[0].id
113 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
116 it('Should send a new comment notification after a local reply on my video', async function () {
119 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
121 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
123 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
125 await waitJobs(servers)
126 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
129 it('Should send a new comment notification after a remote reply on my video', async function () {
132 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
133 await waitJobs(servers)
136 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
137 const threadId = created.id
138 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
141 await waitJobs(servers)
143 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
144 expect(data).to.have.lengthOf(1)
146 const threadId = data[0].id
147 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
149 expect(tree.children).to.have.lengthOf(1)
150 const commentId = tree.children[0].comment.id
152 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
155 it('Should convert markdown in comment to html', async function () {
158 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
160 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
162 await waitJobs(servers)
164 const latestEmail = emails[emails.length - 1]
165 expect(latestEmail['html']).to.contain(expectedHtml)
169 describe('Mention notifications', function () {
170 let baseParams: CheckerBaseParams
171 const byAccountDisplayName = 'super root name'
177 socketNotifications: userNotifications,
181 await servers[0].users.updateMe({ displayName: 'super root name' })
182 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
185 it('Should not send a new mention comment notification if I mention the video owner', async function () {
188 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
190 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
192 await waitJobs(servers)
193 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
196 it('Should not send a new mention comment notification if I mention myself', async function () {
199 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
201 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
203 await waitJobs(servers)
204 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
207 it('Should not send a new mention notification if the account is muted', async function () {
210 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
212 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
214 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
216 await waitJobs(servers)
217 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
219 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
222 it('Should not send a new mention notification if the remote account mention a local account', async function () {
225 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
227 await waitJobs(servers)
228 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
230 await waitJobs(servers)
232 const byAccountDisplayName = 'super root 2 name'
233 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
236 it('Should send a new mention notification after local comments', async function () {
239 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
241 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
243 await waitJobs(servers)
244 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
246 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
248 await waitJobs(servers)
249 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
252 it('Should send a new mention notification after remote comments', async function () {
255 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
257 await waitJobs(servers)
259 const text1 = `hello @user_1@${servers[0].host} 1`
260 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
262 await waitJobs(servers)
264 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
265 expect(data).to.have.lengthOf(1)
267 const byAccountDisplayName = 'super root 2 name'
268 const threadId = data[0].id
269 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
271 const text2 = `@user_1@${servers[0].host} hello 2 @root@${servers[0].host}`
272 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
274 await waitJobs(servers)
276 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
278 expect(tree.children).to.have.lengthOf(1)
279 const commentId = tree.children[0].comment.id
281 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
284 it('Should convert markdown in comment to html', async function () {
287 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
289 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
291 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
293 await waitJobs(servers)
295 const latestEmail = emails[emails.length - 1]
296 expect(latestEmail['html']).to.contain(expectedHtml)
300 after(async function () {
301 MockSmtpServer.Instance.kill()
303 await cleanupTests(servers)