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 style="-ms-text-size-adjust: 100%; -webkit-text-size-adjust: 100%;">hello</strong> ' +
22 '<a href="https://joinpeertube.org" target="_blank" rel="noopener noreferrer" style="-ms-text-size-adjust: 100%; ' +
23 '-webkit-text-size-adjust: 100%; text-decoration: none; color: #f2690d;">world</a>, </p>what do you think about peertube?'
25 before(async function () {
28 const res = await prepareNotificationsTest(2)
30 userToken = res.userAccessToken
32 userNotifications = res.userNotifications
35 describe('Comment on my video notifications', function () {
36 let baseParams: CheckerBaseParams
42 socketNotifications: userNotifications,
47 it('Should not send a new comment notification after a comment on another video', async function () {
50 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
52 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
53 const commentId = created.id
55 await waitJobs(servers)
56 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
59 it('Should not send a new comment notification if I comment my own video', async function () {
62 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
64 const created = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: 'comment' })
65 const commentId = created.id
67 await waitJobs(servers)
68 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
71 it('Should not send a new comment notification if the account is muted', async function () {
74 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
76 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
78 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
79 const commentId = created.id
81 await waitJobs(servers)
82 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'absence' })
84 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
87 it('Should send a new comment notification after a local comment on my video', async function () {
90 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
92 const created = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
93 const commentId = created.id
95 await waitJobs(servers)
96 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
99 it('Should send a new comment notification after a remote comment on my video', async function () {
102 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
104 await waitJobs(servers)
106 await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
108 await waitJobs(servers)
110 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
111 expect(data).to.have.lengthOf(1)
113 const commentId = data[0].id
114 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId: commentId, commentId, checkType: 'presence' })
117 it('Should send a new comment notification after a local reply on my video', async function () {
120 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
122 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: 'comment' })
124 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
126 await waitJobs(servers)
127 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
130 it('Should send a new comment notification after a remote reply on my video', async function () {
133 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
134 await waitJobs(servers)
137 const created = await servers[1].comments.createThread({ videoId: uuid, text: 'comment' })
138 const threadId = created.id
139 await servers[1].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'reply' })
142 await waitJobs(servers)
144 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
145 expect(data).to.have.lengthOf(1)
147 const threadId = data[0].id
148 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
150 expect(tree.children).to.have.lengthOf(1)
151 const commentId = tree.children[0].comment.id
153 await checkNewCommentOnMyVideo({ ...baseParams, shortUUID, threadId, commentId, checkType: 'presence' })
156 it('Should convert markdown in comment to html', async function () {
159 const { uuid } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'cool video' } })
161 await servers[0].comments.createThread({ videoId: uuid, text: commentText })
163 await waitJobs(servers)
165 const latestEmail = emails[emails.length - 1]
166 expect(latestEmail['html']).to.contain(expectedHtml)
170 describe('Mention notifications', function () {
171 let baseParams: CheckerBaseParams
172 const byAccountDisplayName = 'super root name'
178 socketNotifications: userNotifications,
182 await servers[0].users.updateMe({ displayName: 'super root name' })
183 await servers[1].users.updateMe({ displayName: 'super root 2 name' })
186 it('Should not send a new mention comment notification if I mention the video owner', async function () {
189 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken, attributes: { name: 'super video' } })
191 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
193 await waitJobs(servers)
194 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
197 it('Should not send a new mention comment notification if I mention myself', async function () {
200 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
202 const { id: commentId } = await servers[0].comments.createThread({ token: userToken, videoId: uuid, text: '@user_1 hello' })
204 await waitJobs(servers)
205 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
208 it('Should not send a new mention notification if the account is muted', async function () {
211 await servers[0].blocklist.addToMyBlocklist({ token: userToken, account: 'root' })
213 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
215 const { id: commentId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
217 await waitJobs(servers)
218 await checkCommentMention({ ...baseParams, shortUUID, threadId: commentId, commentId, byAccountDisplayName, checkType: 'absence' })
220 await servers[0].blocklist.removeFromMyBlocklist({ token: userToken, account: 'root' })
223 it('Should not send a new mention notification if the remote account mention a local account', async function () {
226 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
228 await waitJobs(servers)
229 const { id: threadId } = await servers[1].comments.createThread({ videoId: uuid, text: '@user_1 hello' })
231 await waitJobs(servers)
233 const byAccountDisplayName = 'super root 2 name'
234 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'absence' })
237 it('Should send a new mention notification after local comments', async function () {
240 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
242 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hellotext: 1' })
244 await waitJobs(servers)
245 await checkCommentMention({ ...baseParams, shortUUID, threadId, commentId: threadId, byAccountDisplayName, checkType: 'presence' })
247 const { id: commentId } = await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: 'hello 2 @user_1' })
249 await waitJobs(servers)
250 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
253 it('Should send a new mention notification after remote comments', async function () {
256 const { uuid, shortUUID } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
258 await waitJobs(servers)
260 const text1 = `hello @user_1@${servers[0].host} 1`
261 const { id: server2ThreadId } = await servers[1].comments.createThread({ videoId: uuid, text: text1 })
263 await waitJobs(servers)
265 const { data } = await servers[0].comments.listThreads({ videoId: uuid })
266 expect(data).to.have.lengthOf(1)
268 const byAccountDisplayName = 'super root 2 name'
269 const threadId = data[0].id
270 await checkCommentMention({ ...baseParams, shortUUID, commentId: threadId, threadId, byAccountDisplayName, checkType: 'presence' })
272 const text2 = `@user_1@${servers[0].host} hello 2 @root@${servers[0].host}`
273 await servers[1].comments.addReply({ videoId: uuid, toCommentId: server2ThreadId, text: text2 })
275 await waitJobs(servers)
277 const tree = await servers[0].comments.getThread({ videoId: uuid, threadId })
279 expect(tree.children).to.have.lengthOf(1)
280 const commentId = tree.children[0].comment.id
282 await checkCommentMention({ ...baseParams, shortUUID, commentId, threadId, byAccountDisplayName, checkType: 'presence' })
285 it('Should convert markdown in comment to html', async function () {
288 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'super video' } })
290 const { id: threadId } = await servers[0].comments.createThread({ videoId: uuid, text: '@user_1 hello 1' })
292 await servers[0].comments.addReply({ videoId: uuid, toCommentId: threadId, text: '@user_1 ' + commentText })
294 await waitJobs(servers)
296 const latestEmail = emails[emails.length - 1]
297 expect(latestEmail['html']).to.contain(expectedHtml)
301 after(async function () {
302 MockSmtpServer.Instance.kill()
304 await cleanupTests(servers)