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