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