1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
8 checkNewCommentOnMyVideo,
11 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: ServerInfo[] = []
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 } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
57 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
58 const commentId = created.id
60 await waitJobs(servers)
61 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
64 it('Should not send a new comment notification if I comment my own video', async function () {
67 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
69 const created = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: 'comment' })
70 const commentId = created.id
72 await waitJobs(servers)
73 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
76 it('Should not send a new comment notification if the account is muted', async function () {
79 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
81 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
83 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
84 const commentId = created.id
86 await waitJobs(servers)
87 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
89 await servers[0].blocklistCommand.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 } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
97 const created = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
98 const commentId = created.id
100 await waitJobs(servers)
101 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
104 it('Should send a new comment notification after a remote comment on my video', async function () {
107 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
109 await waitJobs(servers)
111 await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
113 await waitJobs(servers)
115 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
116 expect(data).to.have.lengthOf(1)
118 const commentId = data[0].id
119 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
122 it('Should send a new comment notification after a local reply on my video', async function () {
125 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
127 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
129 const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
131 await waitJobs(servers)
132 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
135 it('Should send a new comment notification after a remote reply on my video', async function () {
138 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
139 await waitJobs(servers)
142 const created = await servers[1].commentsCommand.createThread({ videoId: uuid, text: 'comment' })
143 const threadId = created.id
144 await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
147 await waitJobs(servers)
149 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
150 expect(data).to.have.lengthOf(1)
152 const threadId = data[0].id
153 const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId })
155 expect(tree.children).to.have.lengthOf(1)
156 const commentId = tree.children[0].comment.id
158 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
161 it('Should convert markdown in comment to html', async function () {
164 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'cool video' } })
166 await servers[0].commentsCommand.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
182 socketNotifications: userNotifications,
186 await servers[0].usersCommand.updateMe({ displayName: 'super root name' })
187 await servers[1].usersCommand.updateMe({ displayName: 'super root 2 name' })
190 it('Should not send a new mention comment notification if I mention the video owner', async function () {
193 const { uuid } = await servers[0].videosCommand.upload({ token: userToken, attributes: { name: 'super video' } })
195 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
197 await waitJobs(servers)
198 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
201 it('Should not send a new mention comment notification if I mention myself', async function () {
204 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
206 const { id: commentId } = await servers[0].commentsCommand.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
208 await waitJobs(servers)
209 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
212 it('Should not send a new mention notification if the account is muted', async function () {
215 await servers[0].blocklistCommand.addToMyBlocklist({ token: userToken, account: 'root' })
217 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
219 const { id: commentId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
221 await waitJobs(servers)
222 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
224 await servers[0].blocklistCommand.removeFromMyBlocklist({ token: userToken, account: 'root' })
227 it('Should not send a new mention notification if the remote account mention a local account', async function () {
230 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
232 await waitJobs(servers)
233 const { id: threadId } = await servers[1].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello' })
235 await waitJobs(servers)
236 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
239 it('Should send a new mention notification after local comments', async function () {
242 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
244 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
246 await waitJobs(servers)
247 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
249 const { id: commentId } = await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
251 await waitJobs(servers)
252 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
255 it('Should send a new mention notification after remote comments', async function () {
258 const { uuid } = await servers[0].videosCommand.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].commentsCommand.createThread({ videoId: uuid, text: text1 })
265 await waitJobs(servers)
267 const { data } = await servers[0].commentsCommand.listThreads({ videoId: uuid })
268 expect(data).to.have.lengthOf(1)
270 const server1ThreadId = data[0].id
271 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
273 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
274 await servers[1].commentsCommand.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
276 await waitJobs(servers)
278 const tree = await servers[0].commentsCommand.getThread({ videoId: uuid, threadId: server1ThreadId })
280 expect(tree.children).to.have.lengthOf(1)
281 const commentId = tree.children[0].comment.id
283 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
286 it('Should convert markdown in comment to html', async function () {
289 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'super video' } })
291 const { id: threadId } = await servers[0].commentsCommand.createThread({ videoId: uuid, text: '@user_1 hello 1' })
293 await servers[0].commentsCommand.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
295 await waitJobs(servers)
297 const latestEmail = emails[emails.length - 1]
298 expect(latestEmail['html']).to.contain(expectedHtml)
302 after(async function () {
303 MockSmtpServer.Instance.kill()
305 await cleanupTests(servers)