1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 checkNewCommentOnMyVideo,
10 prepareNotificationsTest
11 } from '@server/tests/shared'
12 import { UserNotification } from '@shared/models'
13 import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
15 const expect = chai.expect
17 describe('Test comments notifications', function () {
18 let servers: PeerTubeServer[] = []
20 let userNotifications: UserNotification[] = []
21 let emails: object[] = []
23 const commentText = '**hello** <a href="https://joinpeertube.org">world</a>, <h1>what do you think about peertube?</h1>'
24 const expectedHtml = '<strong style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
25 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
26 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
28 before(async function () {
31 const res = await prepareNotificationsTest(2)
33 userToken = res.userAccessToken
35 userNotifications = res.userNotifications
38 describe('Comment on my video notifications', function () {
39 let baseParams: CheckerBaseParams
45 socketNotifications: userNotifications,
50 it('Should not send a new comment notification after a comment on another video', async function () {
53 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
55 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
56 const commentId = created.id
58 await waitJobs(servers)
59 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
62 it('Should not send a new comment notification if I comment my own video', async function () {
65 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
67 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
68 const commentId = created.id
70 await waitJobs(servers)
71 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
74 it('Should not send a new comment notification if the account is muted', async function () {
77 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
79 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
81 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
82 const commentId = created.id
84 await waitJobs(servers)
85 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
87 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
90 it('Should send a new comment notification after a local comment on my video', async function () {
93 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
95 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
96 const commentId = created.id
98 await waitJobs(servers)
99 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
102 it('Should send a new comment notification after a remote comment on my video', async function () {
105 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
107 await waitJobs(servers)
109 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
111 await waitJobs(servers)
113 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
114 expect(data).to.have.lengthOf(1)
116 const commentId = data[0].id
117 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
120 it('Should send a new comment notification after a local reply on my video', async function () {
123 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
125 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
127 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
129 await waitJobs(servers)
130 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
133 it('Should send a new comment notification after a remote reply on my video', async function () {
136 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
137 await waitJobs(servers)
140 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
141 const threadId = created.id
142 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
145 await waitJobs(servers)
147 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
148 expect(data).to.have.lengthOf(1)
150 const threadId = data[0].id
151 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
153 expect(tree.children).to.have.lengthOf(1)
154 const commentId = tree.children[0].comment.id
156 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
159 it('Should convert markdown in comment to html', async function () {
162 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
164 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
166 await waitJobs(servers)
168 const latestEmail = emails[emails.length - 1]
169 expect(latestEmail['html']).to.contain(expectedHtml)
173 describe('Mention notifications', function () {
174 let baseParams: CheckerBaseParams
175 const byAccountDisplayName = 'super root name'
181 socketNotifications: userNotifications,
185 await servers[0].users.updateMe({ displayName: 'super root name' })
186 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
189 it('Should not send a new mention comment notification if I mention the video owner', async function () {
192 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
194 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
196 await waitJobs(servers)
197 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
200 it('Should not send a new mention comment notification if I mention myself', async function () {
203 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
205 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
207 await waitJobs(servers)
208 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
211 it('Should not send a new mention notification if the account is muted', async function () {
214 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
216 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
218 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
220 await waitJobs(servers)
221 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
223 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
226 it('Should not send a new mention notification if the remote account mention a local account', async function () {
229 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
231 await waitJobs(servers)
232 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
234 await waitJobs(servers)
236 const byAccountDisplayName = 'super root 2 name'
237 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
240 it('Should send a new mention notification after local comments', async function () {
243 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
245 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
247 await waitJobs(servers)
248 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
250 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
252 await waitJobs(servers)
253 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
256 it('Should send a new mention notification after remote comments', async function () {
259 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
261 await waitJobs(servers)
263 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
264 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
266 await waitJobs(servers)
268 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
269 expect(data).to.have.lengthOf(1)
271 const byAccountDisplayName = 'super root 2 name'
272 const threadId = data[0].id
273 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
275 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
276 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
278 await waitJobs(servers)
280 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
282 expect(tree.children).to.have.lengthOf(1)
283 const commentId = tree.children[0].comment.id
285 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
288 it('Should convert markdown in comment to html', async function () {
291 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
293 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
295 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
297 await waitJobs(servers)
299 const latestEmail = emails[emails.length - 1]
300 expect(latestEmail['html']).to.contain(expectedHtml)
304 after(async function () {
305 MockSmtpServer.Instance.kill()
307 await cleanupTests(servers)