1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import * as chai from 'chai'
5 import { cleanupTests, getVideoCommentThreads, getVideoThreadComments, updateMyUser, wait } from '../../../../shared/extra-utils'
6 import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
7 import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
8 import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
9 import { addAccountToAccountBlocklist, removeAccountFromAccountBlocklist } from '../../../../shared/extra-utils/users/blocklist'
13 checkNewCommentOnMyVideo,
14 prepareNotificationsTest
15 } from '../../../../shared/extra-utils/users/user-notifications'
16 import { addVideoCommentReply, addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
17 import { UserNotification } from '../../../../shared/models/users'
18 import { VideoCommentThreadTree } from '../../../../shared/models/videos/video-comment.model'
20 const expect = chai.expect
22 describe('Test comments notifications', function () {
23 let servers: ServerInfo[] = []
24 let userAccessToken: string
25 let userNotifications: UserNotification[] = []
26 let emails: object[] = []
28 before(async function () {
31 const res = await prepareNotificationsTest(2)
33 userAccessToken = res.userAccessToken
35 userNotifications = res.userNotifications
38 describe('Comment on my video notifications', function () {
39 let baseParams: CheckerBaseParams
45 socketNotifications: userNotifications,
46 token: userAccessToken
50 it('Should not send a new comment notification after a comment on another video', async function () {
53 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
54 const uuid = resVideo.body.video.uuid
56 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
57 const commentId = resComment.body.comment.id
60 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
63 it('Should not send a new comment notification if I comment my own video', async function () {
66 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
67 const uuid = resVideo.body.video.uuid
69 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, 'comment')
70 const commentId = resComment.body.comment.id
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 addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
81 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
82 const uuid = resVideo.body.video.uuid
84 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
85 const commentId = resComment.body.comment.id
88 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'absence')
90 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
93 it('Should send a new comment notification after a local comment on my video', async function () {
96 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
97 const uuid = resVideo.body.video.uuid
99 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
100 const commentId = resComment.body.comment.id
103 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
106 it('Should send a new comment notification after a remote comment on my video', async function () {
109 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
110 const uuid = resVideo.body.video.uuid
112 await waitJobs(servers)
114 await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
116 await waitJobs(servers)
118 const resComment = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
119 expect(resComment.body.data).to.have.lengthOf(1)
120 const commentId = resComment.body.data[0].id
122 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, commentId, 'presence')
125 it('Should send a new comment notification after a local reply on my video', async function () {
128 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
129 const uuid = resVideo.body.video.uuid
131 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, 'comment')
132 const threadId = resThread.body.comment.id
134 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'reply')
135 const commentId = resComment.body.comment.id
138 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
141 it('Should send a new comment notification after a remote reply on my video', async function () {
144 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
145 const uuid = resVideo.body.video.uuid
146 await waitJobs(servers)
149 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, 'comment')
150 const threadId = resThread.body.comment.id
151 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, threadId, 'reply')
154 await waitJobs(servers)
156 const resThread = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
157 expect(resThread.body.data).to.have.lengthOf(1)
158 const threadId = resThread.body.data[0].id
160 const resComments = await getVideoThreadComments(servers[0].url, uuid, threadId)
161 const tree = resComments.body as VideoCommentThreadTree
163 expect(tree.children).to.have.lengthOf(1)
164 const commentId = tree.children[0].comment.id
166 await checkNewCommentOnMyVideo(baseParams, uuid, commentId, threadId, 'presence')
170 describe('Mention notifications', function () {
171 let baseParams: CheckerBaseParams
177 socketNotifications: userNotifications,
178 token: userAccessToken
183 accessToken: servers[0].accessToken,
184 displayName: 'super root name'
189 accessToken: servers[1].accessToken,
190 displayName: 'super root 2 name'
194 it('Should not send a new mention comment notification if I mention the video owner', async function () {
197 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: 'super video' })
198 const uuid = resVideo.body.video.uuid
200 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
201 const commentId = resComment.body.comment.id
204 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
207 it('Should not send a new mention comment notification if I mention myself', async function () {
210 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
211 const uuid = resVideo.body.video.uuid
213 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, uuid, '@user_1 hello')
214 const commentId = resComment.body.comment.id
217 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
220 it('Should not send a new mention notification if the account is muted', async function () {
223 await addAccountToAccountBlocklist(servers[0].url, userAccessToken, 'root')
225 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
226 const uuid = resVideo.body.video.uuid
228 const resComment = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello')
229 const commentId = resComment.body.comment.id
232 await checkCommentMention(baseParams, uuid, commentId, commentId, 'super root name', 'absence')
234 await removeAccountFromAccountBlocklist(servers[0].url, userAccessToken, 'root')
237 it('Should not send a new mention notification if the remote account mention a local account', async function () {
240 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
241 const uuid = resVideo.body.video.uuid
243 await waitJobs(servers)
244 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, '@user_1 hello')
245 const threadId = resThread.body.comment.id
247 await waitJobs(servers)
248 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root 2 name', 'absence')
251 it('Should send a new mention notification after local comments', async function () {
254 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
255 const uuid = resVideo.body.video.uuid
257 const resThread = await addVideoCommentThread(servers[0].url, servers[0].accessToken, uuid, '@user_1 hello 1')
258 const threadId = resThread.body.comment.id
261 await checkCommentMention(baseParams, uuid, threadId, threadId, 'super root name', 'presence')
263 const resComment = await addVideoCommentReply(servers[0].url, servers[0].accessToken, uuid, threadId, 'hello 2 @user_1')
264 const commentId = resComment.body.comment.id
267 await checkCommentMention(baseParams, uuid, commentId, threadId, 'super root name', 'presence')
270 it('Should send a new mention notification after remote comments', async function () {
273 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'super video' })
274 const uuid = resVideo.body.video.uuid
276 await waitJobs(servers)
278 const text1 = `hello @user_1@localhost:${servers[0].port} 1`
279 const resThread = await addVideoCommentThread(servers[1].url, servers[1].accessToken, uuid, text1)
280 const server2ThreadId = resThread.body.comment.id
282 await waitJobs(servers)
284 const resThread2 = await getVideoCommentThreads(servers[0].url, uuid, 0, 5)
285 expect(resThread2.body.data).to.have.lengthOf(1)
286 const server1ThreadId = resThread2.body.data[0].id
287 await checkCommentMention(baseParams, uuid, server1ThreadId, server1ThreadId, 'super root 2 name', 'presence')
289 const text2 = `@user_1@localhost:${servers[0].port} hello 2 @root@localhost:${servers[0].port}`
290 await addVideoCommentReply(servers[1].url, servers[1].accessToken, uuid, server2ThreadId, text2)
292 await waitJobs(servers)
294 const resComments = await getVideoThreadComments(servers[0].url, uuid, server1ThreadId)
295 const tree = resComments.body as VideoCommentThreadTree
297 expect(tree.children).to.have.lengthOf(1)
298 const commentId = tree.children[0].comment.id
300 await checkCommentMention(baseParams, uuid, commentId, server1ThreadId, 'super root 2 name', 'presence')
304 after(async function () {
305 MockSmtpServer.Instance.kill()
307 await cleanupTests(servers)