aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/notifications/moderation-notifications.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/notifications/moderation-notifications.ts')
-rw-r--r--server/tests/api/notifications/moderation-notifications.ts218
1 files changed, 97 insertions, 121 deletions
diff --git a/server/tests/api/notifications/moderation-notifications.ts b/server/tests/api/notifications/moderation-notifications.ts
index 3425480ae..6f74709b3 100644
--- a/server/tests/api/notifications/moderation-notifications.ts
+++ b/server/tests/api/notifications/moderation-notifications.ts
@@ -2,33 +2,6 @@
2 2
3import 'mocha' 3import 'mocha'
4import { buildUUID } from '@server/helpers/uuid' 4import { buildUUID } from '@server/helpers/uuid'
5import { AbuseState } from '@shared/models'
6import {
7 addAbuseMessage,
8 addVideoCommentThread,
9 addVideoToBlacklist,
10 cleanupTests,
11 createUser,
12 follow,
13 generateUserAccessToken,
14 getAccount,
15 getCustomConfig,
16 getVideoCommentThreads,
17 getVideoIdFromUUID,
18 immutableAssign,
19 MockInstancesIndex,
20 registerUser,
21 removeVideoFromBlacklist,
22 reportAbuse,
23 unfollow,
24 updateAbuse,
25 updateCustomConfig,
26 updateCustomSubConfig,
27 wait
28} from '../../../../shared/extra-utils'
29import { ServerInfo, uploadVideo } from '../../../../shared/extra-utils/index'
30import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
31import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
32import { 5import {
33 checkAbuseStateChange, 6 checkAbuseStateChange,
34 checkAutoInstanceFollowing, 7 checkAutoInstanceFollowing,
@@ -43,15 +16,18 @@ import {
43 checkUserRegistered, 16 checkUserRegistered,
44 checkVideoAutoBlacklistForModerators, 17 checkVideoAutoBlacklistForModerators,
45 checkVideoIsPublished, 18 checkVideoIsPublished,
46 prepareNotificationsTest 19 cleanupTests,
47} from '../../../../shared/extra-utils/users/user-notifications' 20 MockInstancesIndex,
48import { addUserSubscription, removeUserSubscription } from '../../../../shared/extra-utils/users/user-subscriptions' 21 MockSmtpServer,
49import { CustomConfig } from '../../../../shared/models/server' 22 PeerTubeServer,
50import { UserNotification } from '../../../../shared/models/users' 23 prepareNotificationsTest,
51import { VideoPrivacy } from '../../../../shared/models/videos' 24 wait,
25 waitJobs
26} from '@shared/extra-utils'
27import { AbuseState, CustomConfig, UserNotification, VideoPrivacy } from '@shared/models'
52 28
53describe('Test moderation notifications', function () { 29describe('Test moderation notifications', function () {
54 let servers: ServerInfo[] = [] 30 let servers: PeerTubeServer[] = []
55 let userAccessToken: string 31 let userAccessToken: string
56 let userNotifications: UserNotification[] = [] 32 let userNotifications: UserNotification[] = []
57 let adminNotifications: UserNotification[] = [] 33 let adminNotifications: UserNotification[] = []
@@ -86,10 +62,9 @@ describe('Test moderation notifications', function () {
86 this.timeout(20000) 62 this.timeout(20000)
87 63
88 const name = 'video for abuse ' + buildUUID() 64 const name = 'video for abuse ' + buildUUID()
89 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 65 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
90 const video = resVideo.body.video
91 66
92 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, videoId: video.id, reason: 'super reason' }) 67 await servers[0].abuses.report({ videoId: video.id, reason: 'super reason' })
93 68
94 await waitJobs(servers) 69 await waitJobs(servers)
95 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') 70 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence')
@@ -99,13 +74,12 @@ describe('Test moderation notifications', function () {
99 this.timeout(20000) 74 this.timeout(20000)
100 75
101 const name = 'video for abuse ' + buildUUID() 76 const name = 'video for abuse ' + buildUUID()
102 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 77 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
103 const video = resVideo.body.video
104 78
105 await waitJobs(servers) 79 await waitJobs(servers)
106 80
107 const videoId = await getVideoIdFromUUID(servers[1].url, video.uuid) 81 const videoId = await servers[1].videos.getId({ uuid: video.uuid })
108 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, videoId, reason: 'super reason' }) 82 await servers[1].abuses.report({ videoId, reason: 'super reason' })
109 83
110 await waitJobs(servers) 84 await waitJobs(servers)
111 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence') 85 await checkNewVideoAbuseForModerators(baseParams, video.uuid, name, 'presence')
@@ -115,14 +89,16 @@ describe('Test moderation notifications', function () {
115 this.timeout(20000) 89 this.timeout(20000)
116 90
117 const name = 'video for abuse ' + buildUUID() 91 const name = 'video for abuse ' + buildUUID()
118 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 92 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
119 const video = resVideo.body.video 93 const comment = await servers[0].comments.createThread({
120 const resComment = await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) 94 token: userAccessToken,
121 const comment = resComment.body.comment 95 videoId: video.id,
96 text: 'comment abuse ' + buildUUID()
97 })
122 98
123 await waitJobs(servers) 99 await waitJobs(servers)
124 100
125 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, commentId: comment.id, reason: 'super reason' }) 101 await servers[0].abuses.report({ commentId: comment.id, reason: 'super reason' })
126 102
127 await waitJobs(servers) 103 await waitJobs(servers)
128 await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') 104 await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence')
@@ -132,15 +108,19 @@ describe('Test moderation notifications', function () {
132 this.timeout(20000) 108 this.timeout(20000)
133 109
134 const name = 'video for abuse ' + buildUUID() 110 const name = 'video for abuse ' + buildUUID()
135 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 111 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
136 const video = resVideo.body.video 112
137 await addVideoCommentThread(servers[0].url, userAccessToken, video.id, 'comment abuse ' + buildUUID()) 113 await servers[0].comments.createThread({
114 token: userAccessToken,
115 videoId: video.id,
116 text: 'comment abuse ' + buildUUID()
117 })
138 118
139 await waitJobs(servers) 119 await waitJobs(servers)
140 120
141 const resComments = await getVideoCommentThreads(servers[1].url, video.uuid, 0, 5) 121 const { data } = await servers[1].comments.listThreads({ videoId: video.uuid })
142 const commentId = resComments.body.data[0].id 122 const commentId = data[0].id
143 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, commentId, reason: 'super reason' }) 123 await servers[1].abuses.report({ commentId, reason: 'super reason' })
144 124
145 await waitJobs(servers) 125 await waitJobs(servers)
146 await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence') 126 await checkNewCommentAbuseForModerators(baseParams, video.uuid, name, 'presence')
@@ -150,10 +130,10 @@ describe('Test moderation notifications', function () {
150 this.timeout(20000) 130 this.timeout(20000)
151 131
152 const username = 'user' + new Date().getTime() 132 const username = 'user' + new Date().getTime()
153 const resUser = await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username, password: 'donald' }) 133 const { account } = await servers[0].users.create({ username, password: 'donald' })
154 const accountId = resUser.body.user.account.id 134 const accountId = account.id
155 135
156 await reportAbuse({ url: servers[0].url, token: servers[0].accessToken, accountId, reason: 'super reason' }) 136 await servers[0].abuses.report({ accountId, reason: 'super reason' })
157 137
158 await waitJobs(servers) 138 await waitJobs(servers)
159 await checkNewAccountAbuseForModerators(baseParams, username, 'presence') 139 await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
@@ -163,13 +143,13 @@ describe('Test moderation notifications', function () {
163 this.timeout(20000) 143 this.timeout(20000)
164 144
165 const username = 'user' + new Date().getTime() 145 const username = 'user' + new Date().getTime()
166 const tmpToken = await generateUserAccessToken(servers[0], username) 146 const tmpToken = await servers[0].users.generateUserAndToken(username)
167 await uploadVideo(servers[0].url, tmpToken, { name: 'super video' }) 147 await servers[0].videos.upload({ token: tmpToken, attributes: { name: 'super video' } })
168 148
169 await waitJobs(servers) 149 await waitJobs(servers)
170 150
171 const resAccount = await getAccount(servers[1].url, username + '@' + servers[0].host) 151 const account = await servers[1].accounts.get({ accountName: username + '@' + servers[0].host })
172 await reportAbuse({ url: servers[1].url, token: servers[1].accessToken, accountId: resAccount.body.id, reason: 'super reason' }) 152 await servers[1].abuses.report({ accountId: account.id, reason: 'super reason' })
173 153
174 await waitJobs(servers) 154 await waitJobs(servers)
175 await checkNewAccountAbuseForModerators(baseParams, username, 'presence') 155 await checkNewAccountAbuseForModerators(baseParams, username, 'presence')
@@ -189,17 +169,16 @@ describe('Test moderation notifications', function () {
189 } 169 }
190 170
191 const name = 'abuse ' + buildUUID() 171 const name = 'abuse ' + buildUUID()
192 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 172 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
193 const video = resVideo.body.video
194 173
195 const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) 174 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
196 abuseId = res.body.abuse.id 175 abuseId = body.abuse.id
197 }) 176 })
198 177
199 it('Should send a notification to reporter if the abuse has been accepted', async function () { 178 it('Should send a notification to reporter if the abuse has been accepted', async function () {
200 this.timeout(10000) 179 this.timeout(10000)
201 180
202 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.ACCEPTED }) 181 await servers[0].abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
203 await waitJobs(servers) 182 await waitJobs(servers)
204 183
205 await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence') 184 await checkAbuseStateChange(baseParams, abuseId, AbuseState.ACCEPTED, 'presence')
@@ -208,7 +187,7 @@ describe('Test moderation notifications', function () {
208 it('Should send a notification to reporter if the abuse has been rejected', async function () { 187 it('Should send a notification to reporter if the abuse has been rejected', async function () {
209 this.timeout(10000) 188 this.timeout(10000)
210 189
211 await updateAbuse(servers[0].url, servers[0].accessToken, abuseId, { state: AbuseState.REJECTED }) 190 await servers[0].abuses.update({ abuseId, body: { state: AbuseState.REJECTED } })
212 await waitJobs(servers) 191 await waitJobs(servers)
213 192
214 await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence') 193 await checkAbuseStateChange(baseParams, abuseId, AbuseState.REJECTED, 'presence')
@@ -237,17 +216,16 @@ describe('Test moderation notifications', function () {
237 } 216 }
238 217
239 const name = 'abuse ' + buildUUID() 218 const name = 'abuse ' + buildUUID()
240 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 219 const video = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
241 const video = resVideo.body.video
242 220
243 { 221 {
244 const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason' }) 222 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason' })
245 abuseId = res.body.abuse.id 223 abuseId = body.abuse.id
246 } 224 }
247 225
248 { 226 {
249 const res = await reportAbuse({ url: servers[0].url, token: userAccessToken, videoId: video.id, reason: 'super reason 2' }) 227 const body = await servers[0].abuses.report({ token: userAccessToken, videoId: video.id, reason: 'super reason 2' })
250 abuseId2 = res.body.abuse.id 228 abuseId2 = body.abuse.id
251 } 229 }
252 }) 230 })
253 231
@@ -255,7 +233,7 @@ describe('Test moderation notifications', function () {
255 this.timeout(10000) 233 this.timeout(10000)
256 234
257 const message = 'my super message to users' 235 const message = 'my super message to users'
258 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) 236 await servers[0].abuses.addMessage({ abuseId, message })
259 await waitJobs(servers) 237 await waitJobs(servers)
260 238
261 await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence') 239 await checkNewAbuseMessage(baseParamsUser, abuseId, message, 'user_1@example.com', 'presence')
@@ -265,7 +243,7 @@ describe('Test moderation notifications', function () {
265 this.timeout(10000) 243 this.timeout(10000)
266 244
267 const message = 'my super message that should not be sent to the admin' 245 const message = 'my super message that should not be sent to the admin'
268 await addAbuseMessage(servers[0].url, servers[0].accessToken, abuseId, message) 246 await servers[0].abuses.addMessage({ abuseId, message })
269 await waitJobs(servers) 247 await waitJobs(servers)
270 248
271 await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence') 249 await checkNewAbuseMessage(baseParamsAdmin, abuseId, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'absence')
@@ -275,7 +253,7 @@ describe('Test moderation notifications', function () {
275 this.timeout(10000) 253 this.timeout(10000)
276 254
277 const message = 'my super message to moderators' 255 const message = 'my super message to moderators'
278 await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) 256 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message })
279 await waitJobs(servers) 257 await waitJobs(servers)
280 258
281 await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence') 259 await checkNewAbuseMessage(baseParamsAdmin, abuseId2, message, 'admin' + servers[0].internalServerNumber + '@example.com', 'presence')
@@ -285,7 +263,7 @@ describe('Test moderation notifications', function () {
285 this.timeout(10000) 263 this.timeout(10000)
286 264
287 const message = 'my super message that should not be sent to reporter' 265 const message = 'my super message that should not be sent to reporter'
288 await addAbuseMessage(servers[0].url, userAccessToken, abuseId2, message) 266 await servers[0].abuses.addMessage({ token: userAccessToken, abuseId: abuseId2, message })
289 await waitJobs(servers) 267 await waitJobs(servers)
290 268
291 await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence') 269 await checkNewAbuseMessage(baseParamsUser, abuseId2, message, 'user_1@example.com', 'absence')
@@ -308,10 +286,9 @@ describe('Test moderation notifications', function () {
308 this.timeout(10000) 286 this.timeout(10000)
309 287
310 const name = 'video for abuse ' + buildUUID() 288 const name = 'video for abuse ' + buildUUID()
311 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 289 const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
312 const uuid = resVideo.body.video.uuid
313 290
314 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) 291 await servers[0].blacklist.add({ videoId: uuid })
315 292
316 await waitJobs(servers) 293 await waitJobs(servers)
317 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist') 294 await checkNewBlacklistOnMyVideo(baseParams, uuid, name, 'blacklist')
@@ -321,13 +298,12 @@ describe('Test moderation notifications', function () {
321 this.timeout(10000) 298 this.timeout(10000)
322 299
323 const name = 'video for abuse ' + buildUUID() 300 const name = 'video for abuse ' + buildUUID()
324 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name }) 301 const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name } })
325 const uuid = resVideo.body.video.uuid
326 302
327 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, uuid) 303 await servers[0].blacklist.add({ videoId: uuid })
328 304
329 await waitJobs(servers) 305 await waitJobs(servers)
330 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) 306 await servers[0].blacklist.remove({ videoId: uuid })
331 await waitJobs(servers) 307 await waitJobs(servers)
332 308
333 await wait(500) 309 await wait(500)
@@ -350,14 +326,14 @@ describe('Test moderation notifications', function () {
350 it('Should send a notification only to moderators when a user registers on the instance', async function () { 326 it('Should send a notification only to moderators when a user registers on the instance', async function () {
351 this.timeout(10000) 327 this.timeout(10000)
352 328
353 await registerUser(servers[0].url, 'user_45', 'password') 329 await servers[0].users.register({ username: 'user_45' })
354 330
355 await waitJobs(servers) 331 await waitJobs(servers)
356 332
357 await checkUserRegistered(baseParams, 'user_45', 'presence') 333 await checkUserRegistered(baseParams, 'user_45', 'presence')
358 334
359 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 335 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
360 await checkUserRegistered(immutableAssign(baseParams, userOverride), 'user_45', 'absence') 336 await checkUserRegistered({ ...baseParams, ...userOverride }, 'user_45', 'absence')
361 }) 337 })
362 }) 338 })
363 339
@@ -392,20 +368,20 @@ describe('Test moderation notifications', function () {
392 it('Should send a notification only to admin when there is a new instance follower', async function () { 368 it('Should send a notification only to admin when there is a new instance follower', async function () {
393 this.timeout(20000) 369 this.timeout(20000)
394 370
395 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) 371 await servers[2].follows.follow({ hosts: [ servers[0].url ] })
396 372
397 await waitJobs(servers) 373 await waitJobs(servers)
398 374
399 await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence') 375 await checkNewInstanceFollower(baseParams, 'localhost:' + servers[2].port, 'presence')
400 376
401 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 377 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
402 await checkNewInstanceFollower(immutableAssign(baseParams, userOverride), 'localhost:' + servers[2].port, 'absence') 378 await checkNewInstanceFollower({ ...baseParams, ...userOverride }, 'localhost:' + servers[2].port, 'absence')
403 }) 379 })
404 380
405 it('Should send a notification on auto follow back', async function () { 381 it('Should send a notification on auto follow back', async function () {
406 this.timeout(40000) 382 this.timeout(40000)
407 383
408 await unfollow(servers[2].url, servers[2].accessToken, servers[0]) 384 await servers[2].follows.unfollow({ target: servers[0] })
409 await waitJobs(servers) 385 await waitJobs(servers)
410 386
411 const config = { 387 const config = {
@@ -415,9 +391,9 @@ describe('Test moderation notifications', function () {
415 } 391 }
416 } 392 }
417 } 393 }
418 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 394 await servers[0].config.updateCustomSubConfig({ newConfig: config })
419 395
420 await follow(servers[2].url, [ servers[0].url ], servers[2].accessToken) 396 await servers[2].follows.follow({ hosts: [ servers[0].url ] })
421 397
422 await waitJobs(servers) 398 await waitJobs(servers)
423 399
@@ -426,19 +402,19 @@ describe('Test moderation notifications', function () {
426 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') 402 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
427 403
428 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } } 404 const userOverride = { socketNotifications: userNotifications, token: userAccessToken, check: { web: true, mail: false } }
429 await checkAutoInstanceFollowing(immutableAssign(baseParams, userOverride), followerHost, followingHost, 'absence') 405 await checkAutoInstanceFollowing({ ...baseParams, ...userOverride }, followerHost, followingHost, 'absence')
430 406
431 config.followings.instance.autoFollowBack.enabled = false 407 config.followings.instance.autoFollowBack.enabled = false
432 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 408 await servers[0].config.updateCustomSubConfig({ newConfig: config })
433 await unfollow(servers[0].url, servers[0].accessToken, servers[2]) 409 await servers[0].follows.unfollow({ target: servers[2] })
434 await unfollow(servers[2].url, servers[2].accessToken, servers[0]) 410 await servers[2].follows.unfollow({ target: servers[0] })
435 }) 411 })
436 412
437 it('Should send a notification on auto instances index follow', async function () { 413 it('Should send a notification on auto instances index follow', async function () {
438 this.timeout(30000) 414 this.timeout(30000)
439 await unfollow(servers[0].url, servers[0].accessToken, servers[1]) 415 await servers[0].follows.unfollow({ target: servers[1] })
440 416
441 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 417 await servers[0].config.updateCustomSubConfig({ newConfig: config })
442 418
443 await wait(5000) 419 await wait(5000)
444 await waitJobs(servers) 420 await waitJobs(servers)
@@ -448,8 +424,8 @@ describe('Test moderation notifications', function () {
448 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence') 424 await checkAutoInstanceFollowing(baseParams, followerHost, followingHost, 'presence')
449 425
450 config.followings.instance.autoFollowIndex.enabled = false 426 config.followings.instance.autoFollowIndex.enabled = false
451 await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) 427 await servers[0].config.updateCustomSubConfig({ newConfig: config })
452 await unfollow(servers[0].url, servers[0].accessToken, servers[1]) 428 await servers[0].follows.unfollow({ target: servers[1] })
453 }) 429 })
454 }) 430 })
455 431
@@ -484,9 +460,11 @@ describe('Test moderation notifications', function () {
484 token: userAccessToken 460 token: userAccessToken
485 } 461 }
486 462
487 const resCustomConfig = await getCustomConfig(servers[0].url, servers[0].accessToken) 463 currentCustomConfig = await servers[0].config.getCustomConfig()
488 currentCustomConfig = resCustomConfig.body 464
489 const autoBlacklistTestsCustomConfig = immutableAssign(currentCustomConfig, { 465 const autoBlacklistTestsCustomConfig = {
466 ...currentCustomConfig,
467
490 autoBlacklist: { 468 autoBlacklist: {
491 videos: { 469 videos: {
492 ofUsers: { 470 ofUsers: {
@@ -494,13 +472,14 @@ describe('Test moderation notifications', function () {
494 } 472 }
495 } 473 }
496 } 474 }
497 }) 475 }
476
498 // enable transcoding otherwise own publish notification after transcoding not expected 477 // enable transcoding otherwise own publish notification after transcoding not expected
499 autoBlacklistTestsCustomConfig.transcoding.enabled = true 478 autoBlacklistTestsCustomConfig.transcoding.enabled = true
500 await updateCustomConfig(servers[0].url, servers[0].accessToken, autoBlacklistTestsCustomConfig) 479 await servers[0].config.updateCustomConfig({ newCustomConfig: autoBlacklistTestsCustomConfig })
501 480
502 await addUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 481 await servers[0].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
503 await addUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 482 await servers[1].subscriptions.add({ targetUri: 'user_1_channel@localhost:' + servers[0].port })
504 483
505 }) 484 })
506 485
@@ -508,8 +487,8 @@ describe('Test moderation notifications', function () {
508 this.timeout(40000) 487 this.timeout(40000)
509 488
510 videoName = 'video with auto-blacklist ' + buildUUID() 489 videoName = 'video with auto-blacklist ' + buildUUID()
511 const resVideo = await uploadVideo(servers[0].url, userAccessToken, { name: videoName }) 490 const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes: { name: videoName } })
512 videoUUID = resVideo.body.video.uuid 491 videoUUID = uuid
513 492
514 await waitJobs(servers) 493 await waitJobs(servers)
515 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence') 494 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, videoUUID, videoName, 'presence')
@@ -530,7 +509,7 @@ describe('Test moderation notifications', function () {
530 it('Should send video published and unblacklist after video unblacklisted', async function () { 509 it('Should send video published and unblacklist after video unblacklisted', async function () {
531 this.timeout(40000) 510 this.timeout(40000)
532 511
533 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoUUID) 512 await servers[0].blacklist.remove({ videoId: videoUUID })
534 513
535 await waitJobs(servers) 514 await waitJobs(servers)
536 515
@@ -555,19 +534,18 @@ describe('Test moderation notifications', function () {
555 534
556 const name = 'video with auto-blacklist and future schedule ' + buildUUID() 535 const name = 'video with auto-blacklist and future schedule ' + buildUUID()
557 536
558 const data = { 537 const attributes = {
559 name, 538 name,
560 privacy: VideoPrivacy.PRIVATE, 539 privacy: VideoPrivacy.PRIVATE,
561 scheduleUpdate: { 540 scheduleUpdate: {
562 updateAt: updateAt.toISOString(), 541 updateAt: updateAt.toISOString(),
563 privacy: VideoPrivacy.PUBLIC 542 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
564 } 543 }
565 } 544 }
566 545
567 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) 546 const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes })
568 const uuid = resVideo.body.video.uuid
569 547
570 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, uuid) 548 await servers[0].blacklist.remove({ videoId: uuid })
571 549
572 await waitJobs(servers) 550 await waitJobs(servers)
573 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist') 551 await checkNewBlacklistOnMyVideo(userBaseParams, uuid, name, 'unblacklist')
@@ -588,17 +566,16 @@ describe('Test moderation notifications', function () {
588 566
589 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID() 567 const name = 'video with schedule done and still auto-blacklisted ' + buildUUID()
590 568
591 const data = { 569 const attributes = {
592 name, 570 name,
593 privacy: VideoPrivacy.PRIVATE, 571 privacy: VideoPrivacy.PRIVATE,
594 scheduleUpdate: { 572 scheduleUpdate: {
595 updateAt: updateAt.toISOString(), 573 updateAt: updateAt.toISOString(),
596 privacy: VideoPrivacy.PUBLIC 574 privacy: VideoPrivacy.PUBLIC as VideoPrivacy.PUBLIC
597 } 575 }
598 } 576 }
599 577
600 const resVideo = await uploadVideo(servers[0].url, userAccessToken, data) 578 const { uuid } = await servers[0].videos.upload({ token: userAccessToken, attributes })
601 const uuid = resVideo.body.video.uuid
602 579
603 await wait(6000) 580 await wait(6000)
604 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence') 581 await checkVideoIsPublished(userBaseParams, name, uuid, 'absence')
@@ -612,18 +589,17 @@ describe('Test moderation notifications', function () {
612 const name = 'video without auto-blacklist ' + buildUUID() 589 const name = 'video without auto-blacklist ' + buildUUID()
613 590
614 // admin with blacklist right will not be auto-blacklisted 591 // admin with blacklist right will not be auto-blacklisted
615 const resVideo = await uploadVideo(servers[0].url, servers[0].accessToken, { name }) 592 const { uuid } = await servers[0].videos.upload({ attributes: { name } })
616 const uuid = resVideo.body.video.uuid
617 593
618 await waitJobs(servers) 594 await waitJobs(servers)
619 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence') 595 await checkVideoAutoBlacklistForModerators(adminBaseParamsServer1, uuid, name, 'absence')
620 }) 596 })
621 597
622 after(async () => { 598 after(async () => {
623 await updateCustomConfig(servers[0].url, servers[0].accessToken, currentCustomConfig) 599 await servers[0].config.updateCustomConfig({ newCustomConfig: currentCustomConfig })
624 600
625 await removeUserSubscription(servers[0].url, servers[0].accessToken, 'user_1_channel@localhost:' + servers[0].port) 601 await servers[0].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
626 await removeUserSubscription(servers[1].url, servers[1].accessToken, 'user_1_channel@localhost:' + servers[0].port) 602 await servers[1].subscriptions.remove({ uri: 'user_1_channel@localhost:' + servers[0].port })
627 }) 603 })
628 }) 604 })
629 605