]>
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 | getVideoIdFromUUID, |
8eb07b01 | 21 | MockInstancesIndex, |
0c1a77e9 C |
22 | MockSmtpServer, |
23 | prepareNotificationsTest, | |
0c1a77e9 | 24 | ServerInfo, |
0c1a77e9 C |
25 | uploadVideo, |
26 | wait, | |
27 | waitJobs | |
28 | } from '@shared/extra-utils' | |
29 | import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models' | |
8eb07b01 C |
30 | |
31 | describe('Test moderation notifications', function () { | |
32 | let servers: ServerInfo[] = [] | |
33 | let userAccessToken: string | |
34 | let userNotifications: UserNotification[] = [] | |
35 | let adminNotifications: UserNotification[] = [] | |
36 | let adminNotificationsServer2: UserNotification[] = [] | |
37 | let emails: object[] = [] | |
38 | ||
39 | before(async function () { | |
40 | this.timeout(120000) | |
41 | ||
42 | const res = await prepareNotificationsTest(3) | |
43 | emails = res.emails | |
44 | userAccessToken = res.userAccessToken | |
45 | servers = res.servers | |
46 | userNotifications = res.userNotifications | |
47 | adminNotifications = res.adminNotifications | |
48 | adminNotificationsServer2 = res.adminNotificationsServer2 | |
49 | }) | |
50 | ||
594d3e48 | 51 | describe('Abuse for moderators notification', function () { |
8eb07b01 C |
52 | let baseParams: CheckerBaseParams |
53 | ||
54 | before(() => { | |
55 | baseParams = { | |
56 | server: servers[0], | |
57 | emails, | |
58 | socketNotifications: adminNotifications, | |
59 | token: servers[0].accessToken | |
60 | } | |
61 | }) | |
62 | ||
63 | it('Should send a notification to moderators on local video abuse', async function () { | |
20516920 | 64 | this.timeout(20000) |
8eb07b01 | 65 | |
d4a8e7a6 | 66 | const name = 'video for abuse ' + buildUUID() |
8eb07b01 | 67 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) |
4f32032f | 68 | const video = resVideo.body.video |
8eb07b01 | 69 | |
0c1a77e9 | 70 | await servers[0].abusesCommand.report({ videoId: video.id, reason: 'super reason' }) |
8eb07b01 C |
71 | |
72 | await waitJobs(servers) | |
4f32032f | 73 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
8eb07b01 C |
74 | }) |
75 | ||
76 | it('Should send a notification to moderators on remote video abuse', async function () { | |
20516920 | 77 | this.timeout(20000) |
8eb07b01 | 78 | |
d4a8e7a6 | 79 | const name = 'video for abuse ' + buildUUID() |
8eb07b01 | 80 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) |
4f32032f | 81 | const video = resVideo.body.video |
8eb07b01 C |
82 | |
83 | await waitJobs(servers) | |
84 | ||
310b5219 | 85 | const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) |
0c1a77e9 | 86 | await servers[1].abusesCommand.report({ videoId, reason: 'super reason' }) |
8eb07b01 C |
87 | |
88 | await waitJobs(servers) | |
4f32032f | 89 | await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') |
8eb07b01 | 90 | }) |
310b5219 C |
91 | |
92 | it('Should send a notification to moderators on local comment abuse', async function () { | |
20516920 | 93 | this.timeout(20000) |
310b5219 | 94 | |
d4a8e7a6 | 95 | const name = 'video for abuse ' + buildUUID() |
310b5219 C |
96 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) |
97 | const video = resVideo.body.video | |
12edc149 C |
98 | const comment = await servers[0].commentsCommand.createThread({ |
99 | token: userAccessToken, | |
100 | videoId: video.id, | |
101 | text: 'comment abuse ' + buildUUID() | |
102 | }) | |
310b5219 | 103 | |
15bedeeb C |
104 | await waitJobs(servers) |
105 | ||
0c1a77e9 | 106 | await servers[0].abusesCommand.report({ commentId: comment.id, reason: 'super reason' }) |
310b5219 C |
107 | |
108 | await waitJobs(servers) | |
109 | await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') | |
110 | }) | |
111 | ||
112 | it('Should send a notification to moderators on remote comment abuse', async function () { | |
20516920 | 113 | this.timeout(20000) |
310b5219 | 114 | |
d4a8e7a6 | 115 | const name = 'video for abuse ' + buildUUID() |
310b5219 C |
116 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) |
117 | const video = resVideo.body.video | |
12edc149 C |
118 | |
119 | await servers[0].commentsCommand.createThread({ | |
120 | token: userAccessToken, | |
121 | videoId: video.id, | |
122 | text: 'comment abuse ' + buildUUID() | |
123 | }) | |
310b5219 C |
124 | |
125 | await waitJobs(servers) | |
126 | ||
12edc149 C |
127 | const { data } = await servers[1].commentsCommand.listThreads({ videoId: video.uuid }) |
128 | const commentId = 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() | |
7926c5f9 C |
139 | const { account } = await servers[0].usersCommand.create({ username, password: 'donald' }) |
140 | const accountId = account.id | |
310b5219 | 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() | |
7926c5f9 | 152 | const tmpToken = await servers[0].usersCommand.generateUserAndToken(username) |
310b5219 C |
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 | ||
e3d15a6a | 300 | await servers[0].blacklistCommand.add({ videoId: uuid }) |
8eb07b01 C |
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 | ||
e3d15a6a | 313 | await servers[0].blacklistCommand.add({ videoId: uuid }) |
8eb07b01 C |
314 | |
315 | await waitJobs(servers) | |
e3d15a6a | 316 | await servers[0].blacklistCommand.remove({ videoId: uuid }) |
8eb07b01 C |
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 | ||
7926c5f9 | 339 | await servers[0].usersCommand.register({ username: 'user_45' }) |
8eb07b01 C |
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 } } | |
6c5065a0 | 346 | await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence') |
8eb07b01 C |
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 } } | |
6c5065a0 | 388 | await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence') |
8eb07b01 C |
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 } } | |
6c5065a0 | 415 | await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence') |
8eb07b01 C |
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 | ||
6c5065a0 C |
475 | const autoBlacklistTestsCustomConfig = { |
476 | ...currentCustomConfig, | |
477 | ||
8eb07b01 C |
478 | autoBlacklist: { |
479 | videos: { | |
480 | ofUsers: { | |
481 | enabled: true | |
482 | } | |
483 | } | |
484 | } | |
6c5065a0 | 485 | } |
65e6e260 | 486 | |
8eb07b01 C |
487 | // enable transcoding otherwise own publish notification after transcoding not expected |
488 | autoBlacklistTestsCustomConfig.transcoding.enabled = true | |
65e6e260 | 489 | await servers[0].configCommand.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig }) |
8eb07b01 | 490 | |
2c27e704 C |
491 | await servers[0].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) |
492 | await servers[1].subscriptionsCommand.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port }) | |
8eb07b01 C |
493 | |
494 | }) | |
495 | ||
496 | it('Should send notification to moderators on new video with auto-blacklist', async function () { | |
34caef7f | 497 | this.timeout(40000) |
8eb07b01 | 498 | |
d4a8e7a6 | 499 | videoName = 'video with auto-blacklist ' + buildUUID() |
8eb07b01 C |
500 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) |
501 | videoUUID = resVideo.body.video.uuid | |
502 | ||
503 | await waitJobs(servers) | |
504 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') | |
505 | }) | |
506 | ||
507 | it('Should not send video publish notification if auto-blacklisted', async function () { | |
508 | await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'absence') | |
509 | }) | |
510 | ||
511 | it('Should not send a local user subscription notification if auto-blacklisted', async function () { | |
512 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'absence') | |
513 | }) | |
514 | ||
515 | it('Should not send a remote user subscription notification if auto-blacklisted', async function () { | |
516 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'absence') | |
517 | }) | |
518 | ||
519 | it('Should send video published and unblacklist after video unblacklisted', async function () { | |
34caef7f | 520 | this.timeout(40000) |
8eb07b01 | 521 | |
e3d15a6a | 522 | await servers[0].blacklistCommand.remove({ videoId: videoUUID }) |
8eb07b01 C |
523 | |
524 | await waitJobs(servers) | |
525 | ||
526 | // FIXME: Can't test as two notifications sent to same user and util only checks last one | |
527 | // One notification might be better anyways | |
528 | // await checkNewBlacklistOnMyVideo(userBaseParams, videoUUID, videoName, 'unblacklist') | |
529 | // await checkVideoIsPublished(userBaseParams, videoName, videoUUID, 'presence') | |
530 | }) | |
531 | ||
532 | it('Should send a local user subscription notification after removed from blacklist', async function () { | |
533 | await checkNewVideoFromSubscription(adminBaseParamsServer1, videoName, videoUUID, 'presence') | |
534 | }) | |
535 | ||
536 | it('Should send a remote user subscription notification after removed from blacklist', async function () { | |
537 | await checkNewVideoFromSubscription(adminBaseParamsServer2, videoName, videoUUID, 'presence') | |
538 | }) | |
539 | ||
540 | it('Should send unblacklist but not published/subscription notes after unblacklisted if scheduled update pending', async function () { | |
59fd824c | 541 | this.timeout(40000) |
8eb07b01 C |
542 | |
543 | const updateAt = new Date(new Date().getTime() + 1000000) | |
544 | ||
d4a8e7a6 | 545 | const name = 'video with auto-blacklist and future schedule ' + buildUUID() |
8eb07b01 C |
546 | |
547 | const data = { | |
548 | name, | |
549 | privacy: VideoPrivacy.PRIVATE, | |
550 | scheduleUpdate: { | |
551 | updateAt: updateAt.toISOString(), | |
552 | privacy: VideoPrivacy.PUBLIC | |
553 | } | |
554 | } | |
555 | ||
556 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | |
557 | const uuid = resVideo.body.video.uuid | |
558 | ||
e3d15a6a | 559 | await servers[0].blacklistCommand.remove({ videoId: uuid }) |
8eb07b01 C |
560 | |
561 | await waitJobs(servers) | |
562 | await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') | |
563 | ||
564 | // FIXME: Can't test absence as two notifications sent to same user and util only checks last one | |
565 | // One notification might be better anyways | |
566 | // await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
567 | ||
568 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | |
569 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | |
570 | }) | |
571 | ||
572 | it('Should not send publish/subscription notifications after scheduled update if video still auto-blacklisted', async function () { | |
59fd824c | 573 | this.timeout(40000) |
8eb07b01 C |
574 | |
575 | // In 2 seconds | |
576 | const updateAt = new Date(new Date().getTime() + 2000) | |
577 | ||
d4a8e7a6 | 578 | const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() |
8eb07b01 C |
579 | |
580 | const data = { | |
581 | name, | |
582 | privacy: VideoPrivacy.PRIVATE, | |
583 | scheduleUpdate: { | |
584 | updateAt: updateAt.toISOString(), | |
585 | privacy: VideoPrivacy.PUBLIC | |
586 | } | |
587 | } | |
588 | ||
589 | const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) | |
590 | const uuid = resVideo.body.video.uuid | |
591 | ||
592 | await wait(6000) | |
593 | await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') | |
594 | await checkNewVideoFromSubscription(adminBaseParamsServer1, name, uuid, 'absence') | |
595 | await checkNewVideoFromSubscription(adminBaseParamsServer2, name, uuid, 'absence') | |
596 | }) | |
597 | ||
598 | it('Should not send a notification to moderators on new video without auto-blacklist', async function () { | |
26171379 | 599 | this.timeout(60000) |
8eb07b01 | 600 | |
d4a8e7a6 | 601 | const name = 'video without auto-blacklist ' + buildUUID() |
8eb07b01 C |
602 | |
603 | // admin with blacklist right will not be auto-blacklisted | |
604 | const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) | |
605 | const uuid = resVideo.body.video.uuid | |
606 | ||
607 | await waitJobs(servers) | |
608 | await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') | |
609 | }) | |
610 | ||
611 | after(async () => { | |
65e6e260 | 612 | await servers[0].configCommand.updateCustomConfig({ newCustomConfig: currentCustomConfig }) |
8eb07b01 | 613 | |
2c27e704 C |
614 | await servers[0].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) |
615 | await servers[1].subscriptionsCommand.remove({ uri: 'user_1_channel@localhost:' + servers[0].port }) | |
8eb07b01 C |
616 | }) |
617 | }) | |
618 | ||
619 | after(async function () { | |
620 | MockSmtpServer.Instance.kill() | |
621 | ||
622 | await cleanupTests(servers) | |
623 | }) | |
624 | }) |