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