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