]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/notifications/moderation-notifications.ts
Bumped to version v5.2.1
[github/Chocobozzz/PeerTube.git] / server / tests / api / notifications / moderation-notifications.ts
CommitLineData
8eb07b01
C
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2
8eb07b01 3import {
0c1a77e9
C
4 checkAbuseStateChange,
5 checkAutoInstanceFollowing,
6 CheckerBaseParams,
7 checkNewAbuseMessage,
8 checkNewAccountAbuseForModerators,
9 checkNewBlacklistOnMyVideo,
10 checkNewCommentAbuseForModerators,
11 checkNewInstanceFollower,
12 checkNewVideoAbuseForModerators,
13 checkNewVideoFromSubscription,
0c1a77e9
C
14 checkVideoAutoBlacklistForModerators,
15 checkVideoIsPublished,
8eb07b01 16 MockInstancesIndex,
0c1a77e9 17 MockSmtpServer,
c55e3d72
C
18 prepareNotificationsTest
19} from '@server/tests/shared'
0628157f
C
20import { wait } from '@shared/core-utils'
21import { buildUUID } from '@shared/extra-utils'
9e847c17 22import { AbuseState, CustomConfig, UserNotification, UserRole, VideoPrivacy } from '@shared/models'
c55e3d72 23import { cleanupTests, PeerTubeServer, waitJobs } from '@shared/server-commands'
8eb07b01
C
24
25describe('Test moderation notifications', function () {
254d3579 26 let servers: PeerTubeServer[] = []
9e847c17
C
27 let userToken1: string
28 let userToken2: string
29
8eb07b01
C
30 let userNotifications: UserNotification[] = []
31 let adminNotifications: UserNotification[] = []
32 let adminNotificationsServer2: UserNotification[] = []
33 let emails: object[] = []
34
35 before(async function () {
e901579b 36 this.timeout(120000)
8eb07b01
C
37
38 const res = await prepareNotificationsTest(3)
39 emails = res.emails
9e847c17 40 userToken1 = res.userAccessToken
8eb07b01
C
41 servers = res.servers
42 userNotifications = res.userNotifications
43 adminNotifications = res.adminNotifications
44 adminNotificationsServer2 = res.adminNotificationsServer2
9e847c17
C
45
46 userToken2 = await servers[1].users.generateUserAndToken('user2', UserRole.USER)
8eb07b01
C
47 })
48
594d3e48 49 describe('Abuse for moderators notification', function () {
8eb07b01
C
50 let baseParams: CheckerBaseParams
51
52 before(() => {
53 baseParams = {
54 server: servers[0],
55 emails,
56 socketNotifications: adminNotifications,
57 token: servers[0].accessToken
58 }
59 })
60
9e847c17 61 it('Should not send a notification to moderators on local abuse reported by an admin', async function () {
7a07da01 62 this.timeout(50000)
8eb07b01 63
d4a8e7a6 64 const name = 'video for abuse ' + buildUUID()
9e847c17 65 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
8eb07b01 66
89d241a7 67 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' })
8eb07b01 68
9e847c17
C
69 await waitJobs(servers)
70 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'absence' })
71 })
72
73 it('Should send a notification to moderators on local video abuse', async function () {
7a07da01 74 this.timeout(50000)
9e847c17
C
75
76 const name = 'video for abuse ' + buildUUID()
77 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
78
79 await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
80
8eb07b01 81 await waitJobs(servers)
29837f88 82 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
8eb07b01
C
83 })
84
85 it('Should send a notification to moderators on remote video abuse', async function () {
7a07da01 86 this.timeout(50000)
8eb07b01 87
d4a8e7a6 88 const name = 'video for abuse ' + buildUUID()
9e847c17 89 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
8eb07b01
C
90
91 await waitJobs(servers)
92
89d241a7 93 const videoId = await servers[1].videos.getId({ uuid: video.uuid })
9e847c17 94 await servers[1].abuses.report({ token: userToken2, videoId, reason: 'super reason' })
8eb07b01
C
95
96 await waitJobs(servers)
29837f88 97 await checkNewVideoAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
8eb07b01 98 })
310b5219
C
99
100 it('Should send a notification to moderators on local comment abuse', async function () {
7a07da01 101 this.timeout(50000)
310b5219 102
d4a8e7a6 103 const name = 'video for abuse ' + buildUUID()
9e847c17 104 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
89d241a7 105 const comment = await servers[0].comments.createThread({
9e847c17 106 token: userToken1,
12edc149
C
107 videoId: video.id,
108 text: 'comment abuse ' + buildUUID()
109 })
310b5219 110
15bedeeb
C
111 await waitJobs(servers)
112
9e847c17 113 await servers[0].abuses.report({ token: userToken1, commentId: comment.id, reason: 'super reason' })
310b5219
C
114
115 await waitJobs(servers)
29837f88 116 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
310b5219
C
117 })
118
119 it('Should send a notification to moderators on remote comment abuse', async function () {
7a07da01 120 this.timeout(50000)
310b5219 121
d4a8e7a6 122 const name = 'video for abuse ' + buildUUID()
9e847c17 123 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
12edc149 124
89d241a7 125 await servers[0].comments.createThread({
9e847c17 126 token: userToken1,
12edc149
C
127 videoId: video.id,
128 text: 'comment abuse ' + buildUUID()
129 })
310b5219
C
130
131 await waitJobs(servers)
132
89d241a7 133 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid })
12edc149 134 const commentId = data[0].id
9e847c17 135 await servers[1].abuses.report({ token: userToken2, commentId, reason: 'super reason' })
310b5219
C
136
137 await waitJobs(servers)
29837f88 138 await checkNewCommentAbuseForModerators({ ...baseParams, shortUUID: video.shortUUID, videoName: name, checkType: 'presence' })
310b5219
C
139 })
140
141 it('Should send a notification to moderators on local account abuse', async function () {
7a07da01 142 this.timeout(50000)
310b5219
C
143
144 const username = 'user' + new Date().getTime()
89d241a7 145 const { account } = await servers[0].users.create({ username, password: 'donald' })
7926c5f9 146 const accountId = account.id
310b5219 147
9e847c17 148 await servers[0].abuses.report({ token: userToken1, accountId, reason: 'super reason' })
310b5219
C
149
150 await waitJobs(servers)
29837f88 151 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
310b5219
C
152 })
153
154 it('Should send a notification to moderators on remote account abuse', async function () {
7a07da01 155 this.timeout(50000)
310b5219
C
156
157 const username = 'user' + new Date().getTime()
89d241a7
C
158 const tmpToken = await servers[0].users.generateUserAndToken(username)
159 await servers[0].videos.upload({ token: tmpToken, attributes: { name: 'super video' } })
310b5219
C
160
161 await waitJobs(servers)
162
89d241a7 163 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host })
9e847c17 164 await servers[1].abuses.report({ token: userToken2, accountId: account.id, reason: 'super reason' })
310b5219
C
165
166 await waitJobs(servers)
29837f88 167 await checkNewAccountAbuseForModerators({ ...baseParams, displayName: username, checkType: 'presence' })
310b5219 168 })
8eb07b01
C
169 })
170
594d3e48
C
171 describe('Abuse state change notification', function () {
172 let baseParams: CheckerBaseParams
173 let abuseId: number
174
175 before(async function () {
176 baseParams = {
177 server: servers[0],
178 emails,
179 socketNotifications: userNotifications,
9e847c17 180 token: userToken1
594d3e48
C
181 }
182
d4a8e7a6 183 const name = 'abuse ' + buildUUID()
9e847c17 184 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
594d3e48 185
9e847c17 186 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
0c1a77e9 187 abuseId = body.abuse.id
594d3e48
C
188 })
189
190 it('Should send a notification to reporter if the abuse has been accepted', async function () {
9d1e41e8 191 this.timeout(30000)
594d3e48 192
89d241a7 193 await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
594d3e48
C
194 await waitJobs(servers)
195
29837f88 196 await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.ACCEPTED, checkType: 'presence' })
594d3e48
C
197 })
198
199 it('Should send a notification to reporter if the abuse has been rejected', async function () {
9d1e41e8 200 this.timeout(30000)
594d3e48 201
89d241a7 202 await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } })
594d3e48
C
203 await waitJobs(servers)
204
29837f88 205 await checkAbuseStateChange({ ...baseParams, abuseId, state: AbuseState.REJECTED, checkType: 'presence' })
594d3e48
C
206 })
207 })
208
209 describe('New abuse message notification', function () {
210 let baseParamsUser: CheckerBaseParams
211 let baseParamsAdmin: CheckerBaseParams
212 let abuseId: number
213 let abuseId2: number
214
215 before(async function () {
216 baseParamsUser = {
217 server: servers[0],
218 emails,
219 socketNotifications: userNotifications,
9e847c17 220 token: userToken1
594d3e48
C
221 }
222
223 baseParamsAdmin = {
224 server: servers[0],
225 emails,
226 socketNotifications: adminNotifications,
227 token: servers[0].accessToken
228 }
229
d4a8e7a6 230 const name = 'abuse ' + buildUUID()
9e847c17 231 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
594d3e48
C
232
233 {
9e847c17 234 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason' })
0c1a77e9 235 abuseId = body.abuse.id
594d3e48
C
236 }
237
238 {
9e847c17 239 const body = await servers[0].abuses.report({ token: userToken1, videoId: video.id, reason: 'super reason 2' })
0c1a77e9 240 abuseId2 = body.abuse.id
594d3e48
C
241 }
242 })
243
244 it('Should send a notification to reporter on new message', async function () {
9d1e41e8 245 this.timeout(30000)
594d3e48
C
246
247 const message = 'my super message to users'
89d241a7 248 await servers[0].abuses.addMessage({ abuseId, message })
594d3e48
C
249 await waitJobs(servers)
250
29837f88 251 await checkNewAbuseMessage({ ...baseParamsUser, abuseId, message, toEmail: 'user_1@example.com', checkType: 'presence' })
594d3e48
C
252 })
253
254 it('Should not send a notification to the admin if sent by the admin', async function () {
9d1e41e8 255 this.timeout(30000)
594d3e48
C
256
257 const message = 'my super message that should not be sent to the admin'
89d241a7 258 await servers[0].abuses.addMessage({ abuseId, message })
594d3e48
C
259 await waitJobs(servers)
260
29837f88
C
261 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
262 await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId, message, toEmail, checkType: 'absence' })
594d3e48
C
263 })
264
265 it('Should send a notification to moderators', async function () {
9d1e41e8 266 this.timeout(30000)
594d3e48
C
267
268 const message = 'my super message to moderators'
9e847c17 269 await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message })
594d3e48
C
270 await waitJobs(servers)
271
29837f88
C
272 const toEmail = 'admin' + servers[0].internalServerNumber + '@example.com'
273 await checkNewAbuseMessage({ ...baseParamsAdmin, abuseId: abuseId2, message, toEmail, checkType: 'presence' })
594d3e48
C
274 })
275
276 it('Should not send a notification to reporter if sent by the reporter', async function () {
9d1e41e8 277 this.timeout(30000)
594d3e48
C
278
279 const message = 'my super message that should not be sent to reporter'
9e847c17 280 await servers[0].abuses.addMessage({ token: userToken1, abuseId: abuseId2, message })
594d3e48
C
281 await waitJobs(servers)
282
29837f88
C
283 const toEmail = 'user_1@example.com'
284 await checkNewAbuseMessage({ ...baseParamsUser, abuseId: abuseId2, message, toEmail, checkType: 'absence' })
594d3e48
C
285 })
286 })
287
8eb07b01
C
288 describe('Video blacklist on my video', function () {
289 let baseParams: CheckerBaseParams
290
291 before(() => {
292 baseParams = {
293 server: servers[0],
294 emails,
295 socketNotifications: userNotifications,
9e847c17 296 token: userToken1
8eb07b01
C
297 }
298 })
299
300 it('Should send a notification to video owner on blacklist', async function () {
9d1e41e8 301 this.timeout(30000)
8eb07b01 302
d4a8e7a6 303 const name = 'video for abuse ' + buildUUID()
9e847c17 304 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
8eb07b01 305
89d241a7 306 await servers[0].blacklist.add({ videoId: uuid })
8eb07b01
C
307
308 await waitJobs(servers)
29837f88 309 await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'blacklist' })
8eb07b01
C
310 })
311
312 it('Should send a notification to video owner on unblacklist', async function () {
9d1e41e8 313 this.timeout(30000)
8eb07b01 314
d4a8e7a6 315 const name = 'video for abuse ' + buildUUID()
9e847c17 316 const { uuid, shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes: { name } })
8eb07b01 317
89d241a7 318 await servers[0].blacklist.add({ videoId: uuid })
8eb07b01
C
319
320 await waitJobs(servers)
89d241a7 321 await servers[0].blacklist.remove({ videoId: uuid })
8eb07b01
C
322 await waitJobs(servers)
323
324 await wait(500)
29837f88 325 await checkNewBlacklistOnMyVideo({ ...baseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
8eb07b01
C
326 })
327 })
328
8eb07b01
C
329 describe('New instance follows', function () {
330 const instanceIndexServer = new MockInstancesIndex()
f6500729 331 let config: any
8eb07b01
C
332 let baseParams: CheckerBaseParams
333
d1c64fd9 334 before(async function () {
8eb07b01
C
335 baseParams = {
336 server: servers[0],
337 emails,
338 socketNotifications: adminNotifications,
339 token: servers[0].accessToken
340 }
341
f6500729 342 const port = await instanceIndexServer.initialize()
8eb07b01 343 instanceIndexServer.addInstance(servers[1].host)
f6500729
C
344
345 config = {
346 followings: {
347 instance: {
348 autoFollowIndex: {
2732eeff 349 indexUrl: `http://127.0.0.1:${port}/api/v1/instances/hosts`,
f6500729
C
350 enabled: true
351 }
352 }
353 }
354 }
8eb07b01
C
355 })
356
357 it('Should send a notification only to admin when there is a new instance follower', async function () {
3097acc7 358 this.timeout(60000)
8eb07b01 359
4d029ef8 360 await servers[2].follows.follow({ hosts: [ servers[0].url ] })
8eb07b01
C
361
362 await waitJobs(servers)
363
2732eeff 364 await checkNewInstanceFollower({ ...baseParams, followerHost: servers[2].host, checkType: 'presence' })
8eb07b01 365
9e847c17 366 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
2732eeff 367 await checkNewInstanceFollower({ ...baseParams, ...userOverride, followerHost: servers[2].host, checkType: 'absence' })
8eb07b01
C
368 })
369
370 it('Should send a notification on auto follow back', async function () {
371 this.timeout(40000)
372
89d241a7 373 await servers[2].follows.unfollow({ target: servers[0] })
8eb07b01
C
374 await waitJobs(servers)
375
376 const config = {
377 followings: {
378 instance: {
379 autoFollowBack: { enabled: true }
380 }
381 }
382 }
89d241a7 383 await servers[0].config.updateCustomSubConfig({ newConfig: config })
8eb07b01 384
4d029ef8 385 await servers[2].follows.follow({ hosts: [ servers[0].url ] })
8eb07b01
C
386
387 await waitJobs(servers)
388
389 const followerHost = servers[0].host
390 const followingHost = servers[2].host
29837f88 391 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
8eb07b01 392
9e847c17 393 const userOverride = { socketNotifications: userNotifications, token: userToken1, check: { web: true, mail: false } }
29837f88 394 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride, followerHost, followingHost, checkType: 'absence' })
8eb07b01
C
395
396 config.followings.instance.autoFollowBack.enabled = false
89d241a7
C
397 await servers[0].config.updateCustomSubConfig({ newConfig: config })
398 await servers[0].follows.unfollow({ target: servers[2] })
399 await servers[2].follows.unfollow({ target: servers[0] })
8eb07b01
C
400 })
401
402 it('Should send a notification on auto instances index follow', async function () {
403 this.timeout(30000)
89d241a7 404 await servers[0].follows.unfollow({ target: servers[1] })
8eb07b01 405
89d241a7 406 await servers[0].config.updateCustomSubConfig({ newConfig: config })
8eb07b01
C
407
408 await wait(5000)
409 await waitJobs(servers)
410
411 const followerHost = servers[0].host
412 const followingHost = servers[1].host
29837f88 413 await checkAutoInstanceFollowing({ ...baseParams, followerHost, followingHost, checkType: 'presence' })
8eb07b01
C
414
415 config.followings.instance.autoFollowIndex.enabled = false
89d241a7
C
416 await servers[0].config.updateCustomSubConfig({ newConfig: config })
417 await servers[0].follows.unfollow({ target: servers[1] })
8eb07b01
C
418 })
419 })
420
421 describe('Video-related notifications when video auto-blacklist is enabled', function () {
422 let userBaseParams: CheckerBaseParams
423 let adminBaseParamsServer1: CheckerBaseParams
424 let adminBaseParamsServer2: CheckerBaseParams
29837f88
C
425 let uuid: string
426 let shortUUID: string
8eb07b01
C
427 let videoName: string
428 let currentCustomConfig: CustomConfig
429
d1c64fd9 430 before(async function () {
8eb07b01
C
431
432 adminBaseParamsServer1 = {
433 server: servers[0],
434 emails,
435 socketNotifications: adminNotifications,
436 token: servers[0].accessToken
437 }
438
439 adminBaseParamsServer2 = {
440 server: servers[1],
441 emails,
442 socketNotifications: adminNotificationsServer2,
443 token: servers[1].accessToken
444 }
445
446 userBaseParams = {
447 server: servers[0],
448 emails,
449 socketNotifications: userNotifications,
9e847c17 450 token: userToken1
8eb07b01
C
451 }
452
89d241a7 453 currentCustomConfig = await servers[0].config.getCustomConfig()
65e6e260 454
6c5065a0
C
455 const autoBlacklistTestsCustomConfig = {
456 ...currentCustomConfig,
457
8eb07b01
C
458 autoBlacklist: {
459 videos: {
460 ofUsers: {
461 enabled: true
462 }
463 }
464 }
6c5065a0 465 }
65e6e260 466
8eb07b01
C
467 // enable transcoding otherwise own publish notification after transcoding not expected
468 autoBlacklistTestsCustomConfig.transcoding.enabled = true
89d241a7 469 await servers[0].config.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig })
8eb07b01 470
2732eeff
C
471 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@' + servers[0].host })
472 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@' + servers[0].host })
8eb07b01
C
473 })
474
475 it('Should send notification to moderators on new video with auto-blacklist', async function () {
4fe7cde2 476 this.timeout(120000)
8eb07b01 477
d4a8e7a6 478 videoName = 'video with auto-blacklist ' + buildUUID()
9e847c17 479 const video = await servers[0].videos.upload({ token: userToken1, attributes: { name: videoName } })
29837f88
C
480 shortUUID = video.shortUUID
481 uuid = video.uuid
8eb07b01
C
482
483 await waitJobs(servers)
29837f88 484 await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName, checkType: 'presence' })
8eb07b01
C
485 })
486
487 it('Should not send video publish notification if auto-blacklisted', async function () {
4fe7cde2
C
488 this.timeout(120000)
489
29837f88 490 await checkVideoIsPublished({ ...userBaseParams, videoName, shortUUID, checkType: 'absence' })
8eb07b01
C
491 })
492
493 it('Should not send a local user subscription notification if auto-blacklisted', async function () {
4fe7cde2
C
494 this.timeout(120000)
495
29837f88 496 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'absence' })
8eb07b01
C
497 })
498
499 it('Should not send a remote user subscription notification if auto-blacklisted', async function () {
29837f88 500 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'absence' })
8eb07b01
C
501 })
502
503 it('Should send video published and unblacklist after video unblacklisted', async function () {
4fe7cde2 504 this.timeout(120000)
8eb07b01 505
29837f88 506 await servers[0].blacklist.remove({ videoId: uuid })
8eb07b01
C
507
508 await waitJobs(servers)
509
510 // FIXME: Can't test as two notifications sent to same user and util only checks last one
511 // One notification might be better anyways
512 // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist')
513 // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence')
514 })
515
516 it('Should send a local user subscription notification after removed from blacklist', async function () {
4fe7cde2
C
517 this.timeout(120000)
518
29837f88 519 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName, shortUUID, checkType: 'presence' })
8eb07b01
C
520 })
521
522 it('Should send a remote user subscription notification after removed from blacklist', async function () {
4fe7cde2
C
523 this.timeout(120000)
524
29837f88 525 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName, shortUUID, checkType: 'presence' })
8eb07b01
C
526 })
527
528 it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () {
4fe7cde2 529 this.timeout(120000)
8eb07b01
C
530
531 const updateAt = new Date(new Date().getTime() + 1000000)
532
d4a8e7a6 533 const name = 'video with auto-blacklist and future schedule ' + buildUUID()
8eb07b01 534
d23dd9fb 535 const attributes = {
8eb07b01
C
536 name,
537 privacy: VideoPrivacy.PRIVATE,
538 scheduleUpdate: {
539 updateAt: updateAt.toISOString(),
d23dd9fb 540 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
8eb07b01
C
541 }
542 }
543
9e847c17 544 const { shortUUID, uuid } = await servers[0].videos.upload({ token: userToken1, attributes })
8eb07b01 545
89d241a7 546 await servers[0].blacklist.remove({ videoId: uuid })
8eb07b01
C
547
548 await waitJobs(servers)
29837f88 549 await checkNewBlacklistOnMyVideo({ ...userBaseParams, shortUUID, videoName: name, blacklistType: 'unblacklist' })
8eb07b01
C
550
551 // FIXME: Can't test absence as two notifications sent to same user and util only checks last one
552 // One notification might be better anyways
553 // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
554
29837f88
C
555 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' })
556 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' })
8eb07b01
C
557 })
558
559 it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () {
4fe7cde2 560 this.timeout(120000)
8eb07b01
C
561
562 // In 2 seconds
563 const updateAt = new Date(new Date().getTime() + 2000)
564
d4a8e7a6 565 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID()
8eb07b01 566
d23dd9fb 567 const attributes = {
8eb07b01
C
568 name,
569 privacy: VideoPrivacy.PRIVATE,
570 scheduleUpdate: {
571 updateAt: updateAt.toISOString(),
d23dd9fb 572 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
8eb07b01
C
573 }
574 }
575
9e847c17 576 const { shortUUID } = await servers[0].videos.upload({ token: userToken1, attributes })
8eb07b01
C
577
578 await wait(6000)
29837f88
C
579 await checkVideoIsPublished({ ...userBaseParams, videoName: name, shortUUID, checkType: 'absence' })
580 await checkNewVideoFromSubscription({ ...adminBaseParamsServer1, videoName: name, shortUUID, checkType: 'absence' })
581 await checkNewVideoFromSubscription({ ...adminBaseParamsServer2, videoName: name, shortUUID, checkType: 'absence' })
8eb07b01
C
582 })
583
584 it('Should not send a notification to moderators on new video without auto-blacklist', async function () {
4fe7cde2 585 this.timeout(120000)
8eb07b01 586
d4a8e7a6 587 const name = 'video without auto-blacklist ' + buildUUID()
8eb07b01
C
588
589 // admin with blacklist right will not be auto-blacklisted
29837f88 590 const { shortUUID } = await servers[0].videos.upload({ attributes: { name } })
8eb07b01
C
591
592 await waitJobs(servers)
29837f88 593 await checkVideoAutoBlacklistForModerators({ ...adminBaseParamsServer1, shortUUID, videoName: name, checkType: 'absence' })
8eb07b01
C
594 })
595
596 after(async () => {
89d241a7 597 await servers[0].config.updateCustomConfig({ newCustomConfig: currentCustomConfig })
8eb07b01 598
2732eeff
C
599 await servers[0].subscriptions.remove({ uri: 'user_1_channel@' + servers[0].host })
600 await servers[1].subscriptions.remove({ uri: 'user_1_channel@' + servers[0].host })
8eb07b01
C
601 })
602 })
603
604 after(async function () {
605 MockSmtpServer.Instance.kill()
606
607 await cleanupTests(servers)
608 })
609})