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