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