aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications/moderation-notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/notifications/moderation-notifications.ts')
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts96
1 files changed, 55 insertions, 41 deletions
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index f806fed31..9e330bd61 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -1,7 +1,6 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { buildUUID } from '@server/helpers/uuid'
5import { 4import {
6 checkAbuseStateChange, 5 checkAbuseStateChange,
7 checkAutoInstanceFollowing, 6 checkAutoInstanceFollowing,
@@ -16,19 +15,20 @@ import {
16 checkUserRegistered, 15 checkUserRegistered,
17 checkVideoAutoBlacklistForModerators, 16 checkVideoAutoBlacklistForModerators,
18 checkVideoIsPublished, 17 checkVideoIsPublished,
19 cleanupTests,
20 MockInstancesIndex, 18 MockInstancesIndex,
21 MockSmtpServer, 19 MockSmtpServer,
22 PeerTubeServer, 20 prepareNotificationsTest
23 prepareNotificationsTest, 21} from '@server/tests/shared'
24 wait, 22import { wait } from '@shared/core-utils'
25 waitJobs 23import { buildUUID } from '@shared/extra-utils'
26} from '@shared/extra-utils' 24import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models'
27import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' 25import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
28 26
29describe('Test moderation notifications', function () { 27describe('Test moderation notifications', function () {
30 let servers: PeerTubeServer[] = [] 28 let servers: PeerTubeServer[] = []
31 let userAccessToken: string 29 let userToken1: string
30 let userToken2: string
31
32 let userNotifications: UserNotification[] = [] 32 let userNotifications: UserNotification[] = []
33 let adminNotifications: UserNotification[] = [] 33 let adminNotifications: UserNotification[] = []
34 let adminNotificationsServer2: UserNotification[] = [] 34 let adminNotificationsServer2: UserNotification[] = []
@@ -39,11 +39,13 @@ describe('Test moderation notifications', function () {
39 39
40 const res = await prepareNotificationsTest(3) 40 const res = await prepareNotificationsTest(3)
41 emails = res.emails 41 emails = res.emails
42 userAccessToken = res.userAccessToken 42 userToken1 = res.userAccessToken
43 servers = res.servers 43 servers = res.servers
44 userNotifications = res.userNotifications 44 userNotifications = res.userNotifications
45 adminNotifications = res.adminNotifications 45 adminNotifications = res.adminNotifications
46 adminNotificationsServer2 = res.adminNotificationsServer2 46 adminNotificationsServer2 = res.adminNotificationsServer2
47
48 userToken2 = await servers[1].users.generateUserAndToken('user2', UserRole.USER)
47 }) 49 })
48 50
49 describe('Abuse for moderators notification', function () { 51 describe('Abuse for moderators notification', function () {
@@ -58,15 +60,27 @@ describe('Test moderation notifications', function () {
58 } 60 }
59 }) 61 })
60 62
61 it('Should send a notification to moderators on local video abuse', async function () { 63 it('Should not send a notification to moderators on local abuse reported by an admin', async function () {
62 this.timeout(20000) 64 this.timeout(20000)
63 65
64 const name = 'video for abuse ' + buildUUID() 66 const name = 'video for abuse ' + buildUUID()
65 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 67 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
66 68
67 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' }) 69 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' })
68 70
69 await waitJobs(servers) 71 await waitJobs(servers)
72 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'absence' })
73 })
74
75 it('Should send a notification to moderators on local video abuse', async function () {
76 this.timeout(20000)
77
78 const name = 'video for abuse ' + buildUUID()
79 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
80
81 await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
82
83 await waitJobs(servers)
70 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 84 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
71 }) 85 })
72 86
@@ -74,12 +88,12 @@ describe('Test moderation notifications', function () {
74 this.timeout(20000) 88 this.timeout(20000)
75 89
76 const name = 'video for abuse ' + buildUUID() 90 const name = 'video for abuse ' + buildUUID()
77 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 91 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
78 92
79 await waitJobs(servers) 93 await waitJobs(servers)
80 94
81 const videoId = await servers[1].videos.getId({ uuid: video.uuid }) 95 const videoId = await servers[1].videos.getId({ uuid: video.uuid })
82 await servers[1].abuses.report({ videoId, reason: 'super reason' }) 96 await servers[1].abuses.report({ token: userToken2, videoId, reason: 'super reason' })
83 97
84 await waitJobs(servers) 98 await waitJobs(servers)
85 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 99 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
@@ -89,16 +103,16 @@ describe('Test moderation notifications', function () {
89 this.timeout(20000) 103 this.timeout(20000)
90 104
91 const name = 'video for abuse ' + buildUUID() 105 const name = 'video for abuse ' + buildUUID()
92 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 106 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
93 const comment = await servers[0].comments.createThread({ 107 const comment = await servers[0].comments.createThread({
94 token: userAccessToken, 108 token: userToken1,
95 videoId: video.id, 109 videoId: video.id,
96 text: 'comment abuse ' + buildUUID() 110 text: 'comment abuse ' + buildUUID()
97 }) 111 })
98 112
99 await waitJobs(servers) 113 await waitJobs(servers)
100 114
101 await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' }) 115 await servers[0].abuses.report({ token: userToken1, commentId: comment.id, reason: 'super reason' })
102 116
103 await waitJobs(servers) 117 await waitJobs(servers)
104 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 118 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
@@ -108,10 +122,10 @@ describe('Test moderation notifications', function () {
108 this.timeout(20000) 122 this.timeout(20000)
109 123
110 const name = 'video for abuse ' + buildUUID() 124 const name = 'video for abuse ' + buildUUID()
111 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 125 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
112 126
113 await servers[0].comments.createThread({ 127 await servers[0].comments.createThread({
114 token: userAccessToken, 128 token: userToken1,
115 videoId: video.id, 129 videoId: video.id,
116 text: 'comment abuse ' + buildUUID() 130 text: 'comment abuse ' + buildUUID()
117 }) 131 })
@@ -120,7 +134,7 @@ describe('Test moderation notifications', function () {
120 134
121 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid }) 135 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid })
122 const commentId = data[0].id 136 const commentId = data[0].id
123 await servers[1].abuses.report({ commentId, reason: 'super reason' }) 137 await servers[1].abuses.report({ token: userToken2, commentId, reason: 'super reason' })
124 138
125 await waitJobs(servers) 139 await waitJobs(servers)
126 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' }) 140 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
@@ -133,7 +147,7 @@ describe('Test moderation notifications', function () {
133 const { account } = await servers[0].users.create({ username, password: 'donald' }) 147 const { account } = await servers[0].users.create({ username, password: 'donald' })
134 const accountId = account.id 148 const accountId = account.id
135 149
136 await servers[0].abuses.report({ accountId, reason: 'super reason' }) 150 await servers[0].abuses.report({ token: userToken1, accountId, reason: 'super reason' })
137 151
138 await waitJobs(servers) 152 await waitJobs(servers)
139 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) 153 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
@@ -149,7 +163,7 @@ describe('Test moderation notifications', function () {
149 await waitJobs(servers) 163 await waitJobs(servers)
150 164
151 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host }) 165 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host })
152 await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' }) 166 await servers[1].abuses.report({ token: userToken2, accountId: account.id, reason: 'super reason' })
153 167
154 await waitJobs(servers) 168 await waitJobs(servers)
155 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' }) 169 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
@@ -165,13 +179,13 @@ describe('Test moderation notifications', function () {
165 server: servers[0], 179 server: servers[0],
166 emails, 180 emails,
167 socketNotifications: userNotifications, 181 socketNotifications: userNotifications,
168 token: userAccessToken 182 token: userToken1
169 } 183 }
170 184
171 const name = 'abuse ' + buildUUID() 185 const name = 'abuse ' + buildUUID()
172 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 186 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
173 187
174 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) 188 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
175 abuseId = body.abuse.id 189 abuseId = body.abuse.id
176 }) 190 })
177 191
@@ -205,7 +219,7 @@ describe('Test moderation notifications', function () {
205 server: servers[0], 219 server: servers[0],
206 emails, 220 emails,
207 socketNotifications: userNotifications, 221 socketNotifications: userNotifications,
208 token: userAccessToken 222 token: userToken1
209 } 223 }
210 224
211 baseParamsAdmin = { 225 baseParamsAdmin = {
@@ -216,15 +230,15 @@ describe('Test moderation notifications', function () {
216 } 230 }
217 231
218 const name = 'abuse ' + buildUUID() 232 const name = 'abuse ' + buildUUID()
219 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 233 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
220 234
221 { 235 {
222 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' }) 236 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
223 abuseId = body.abuse.id 237 abuseId = body.abuse.id
224 } 238 }
225 239
226 { 240 {
227 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) 241 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason 2' })
228 abuseId2 = body.abuse.id 242 abuseId2 = body.abuse.id
229 } 243 }
230 }) 244 })
@@ -254,7 +268,7 @@ describe('Test moderation notifications', function () {
254 this.timeout(10000) 268 this.timeout(10000)
255 269
256 const message = 'my super message to moderators' 270 const message = 'my super message to moderators'
257 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) 271 await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message })
258 await waitJobs(servers) 272 await waitJobs(servers)
259 273
260 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com' 274 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
@@ -265,7 +279,7 @@ describe('Test moderation notifications', function () {
265 this.timeout(10000) 279 this.timeout(10000)
266 280
267 const message = 'my super message that should not be sent to reporter' 281 const message = 'my super message that should not be sent to reporter'
268 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message }) 282 await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message })
269 await waitJobs(servers) 283 await waitJobs(servers)
270 284
271 const toEmail = 'user_1@example.com' 285 const toEmail = 'user_1@example.com'
@@ -281,7 +295,7 @@ describe('Test moderation notifications', function () {
281 server: servers[0], 295 server: servers[0],
282 emails, 296 emails,
283 socketNotifications: userNotifications, 297 socketNotifications: userNotifications,
284 token: userAccessToken 298 token: userToken1
285 } 299 }
286 }) 300 })
287 301
@@ -289,7 +303,7 @@ describe('Test moderation notifications', function () {
289 this.timeout(10000) 303 this.timeout(10000)
290 304
291 const name = 'video for abuse ' + buildUUID() 305 const name = 'video for abuse ' + buildUUID()
292 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 306 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
293 307
294 await servers[0].blacklist.add({ videoId: uuid }) 308 await servers[0].blacklist.add({ videoId: uuid })
295 309
@@ -301,7 +315,7 @@ describe('Test moderation notifications', function () {
301 this.timeout(10000) 315 this.timeout(10000)
302 316
303 const name = 'video for abuse ' + buildUUID() 317 const name = 'video for abuse ' + buildUUID()
304 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } }) 318 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
305 319
306 await servers[0].blacklist.add({ videoId: uuid }) 320 await servers[0].blacklist.add({ videoId: uuid })
307 321
@@ -335,7 +349,7 @@ describe('Test moderation notifications', function () {
335 349
336 await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' }) 350 await checkUserRegistered({ ...baseParams, username: 'user_45', checkType: 'presence' })
337 351
338 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 352 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
339 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' }) 353 await checkUserRegistered({ ...baseParams, ...userOverride, username: 'user_45', checkType: 'absence' })
340 }) 354 })
341 }) 355 })
@@ -377,7 +391,7 @@ describe('Test moderation notifications', function () {
377 391
378 await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' }) 392 await checkNewInstanceFollower({ ...baseParams, followerHost: 'localhost:' + servers[2].port, checkType: 'presence' })
379 393
380 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 394 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
381 await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' }) 395 await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: 'localhost:' + servers[2].port, checkType: 'absence' })
382 }) 396 })
383 397
@@ -404,7 +418,7 @@ describe('Test moderation notifications', function () {
404 const followingHost = servers[2].host 418 const followingHost = servers[2].host
405 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' }) 419 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
406 420
407 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 421 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
408 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' }) 422 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' })
409 423
410 config.followings.instance.autoFollowBack.enabled = false 424 config.followings.instance.autoFollowBack.enabled = false
@@ -461,7 +475,7 @@ describe('Test moderation notifications', function () {
461 server: servers[0], 475 server: servers[0],
462 emails, 476 emails,
463 socketNotifications: userNotifications, 477 socketNotifications: userNotifications,
464 token: userAccessToken 478 token: userToken1
465 } 479 }
466 480
467 currentCustomConfig = await servers[0].config.getCustomConfig() 481 currentCustomConfig = await servers[0].config.getCustomConfig()
@@ -490,7 +504,7 @@ describe('Test moderation notifications', function () {
490 this.timeout(120000) 504 this.timeout(120000)
491 505
492 videoName = 'video with auto-blacklist ' + buildUUID() 506 videoName = 'video with auto-blacklist ' + buildUUID()
493 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } }) 507 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name: videoName } })
494 shortUUID = video.shortUUID 508 shortUUID = video.shortUUID
495 uuid = video.uuid 509 uuid = video.uuid
496 510
@@ -547,7 +561,7 @@ describe('Test moderation notifications', function () {
547 } 561 }
548 } 562 }
549 563
550 const { shortUUID, uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes }) 564 const { shortUUID, uuid } = await servers[0].videos.upload({ token: userToken1, attributes })
551 565
552 await servers[0].blacklist.remove({ videoId: uuid }) 566 await servers[0].blacklist.remove({ videoId: uuid })
553 567
@@ -579,7 +593,7 @@ describe('Test moderation notifications', function () {
579 } 593 }
580 } 594 }
581 595
582 const { shortUUID } = await servers[0].videos.upload({ token: userAccessToken, attributes }) 596 const { shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes })
583 597
584 await wait(6000) 598 await wait(6000)
585 await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' }) 599 await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' })