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