aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/video-blacklist.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/moderation/video-blacklist.ts')
-rw-r--r--server/tests/api/moderation/video-blacklist.ts304
1 files changed, 125 insertions, 179 deletions
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index 52cac20d9..d5838191a 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -4,44 +4,30 @@ import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { orderBy } from 'lodash' 5import { orderBy } from 'lodash'
6import { 6import {
7 addVideoToBlacklist, 7 BlacklistCommand,
8 cleanupTests, 8 cleanupTests,
9 createUser, 9 createMultipleServers,
10 flushAndRunMultipleServers, 10 doubleFollow,
11 getBlacklistedVideosList, 11 FIXTURE_URLS,
12 getMyUserInformation,
13 getMyVideos,
14 getVideosList,
15 killallServers, 12 killallServers,
16 removeVideoFromBlacklist, 13 PeerTubeServer,
17 reRunServer,
18 searchVideo,
19 ServerInfo,
20 setAccessTokensToServers, 14 setAccessTokensToServers,
21 updateVideo, 15 waitJobs
22 updateVideoBlacklist, 16} from '@shared/extra-utils'
23 uploadVideo, 17import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
24 userLogin
25} from '../../../../shared/extra-utils/index'
26import { doubleFollow } from '../../../../shared/extra-utils/server/follows'
27import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
28import { getGoodVideoUrl, getMagnetURI, importVideo } from '../../../../shared/extra-utils/videos/video-imports'
29import { User, UserRole } from '../../../../shared/models/users'
30import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
31import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
32 18
33const expect = chai.expect 19const expect = chai.expect
34 20
35describe('Test video blacklist', function () { 21describe('Test video blacklist', function () {
36 let servers: ServerInfo[] = [] 22 let servers: PeerTubeServer[] = []
37 let videoId: number 23 let videoId: number
24 let command: BlacklistCommand
38 25
39 async function blacklistVideosOnServer (server: ServerInfo) { 26 async function blacklistVideosOnServer (server: PeerTubeServer) {
40 const res = await getVideosList(server.url) 27 const { data } = await server.videos.list()
41 28
42 const videos = res.body.data 29 for (const video of data) {
43 for (const video of videos) { 30 await server.blacklist.add({ videoId: video.id, reason: 'super reason' })
44 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
45 } 31 }
46 } 32 }
47 33
@@ -49,7 +35,7 @@ describe('Test video blacklist', function () {
49 this.timeout(50000) 35 this.timeout(50000)
50 36
51 // Run servers 37 // Run servers
52 servers = await flushAndRunMultipleServers(2) 38 servers = await createMultipleServers(2)
53 39
54 // Get the access tokens 40 // Get the access tokens
55 await setAccessTokensToServers(servers) 41 await setAccessTokensToServers(servers)
@@ -58,12 +44,14 @@ describe('Test video blacklist', function () {
58 await doubleFollow(servers[0], servers[1]) 44 await doubleFollow(servers[0], servers[1])
59 45
60 // Upload 2 videos on server 2 46 // Upload 2 videos on server 2
61 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) 47 await servers[1].videos.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
62 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) 48 await servers[1].videos.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
63 49
64 // Wait videos propagation, server 2 has transcoding enabled 50 // Wait videos propagation, server 2 has transcoding enabled
65 await waitJobs(servers) 51 await waitJobs(servers)
66 52
53 command = servers[0].blacklist
54
67 // Blacklist the two videos on server 1 55 // Blacklist the two videos on server 1
68 await blacklistVideosOnServer(servers[0]) 56 await blacklistVideosOnServer(servers[0])
69 }) 57 })
@@ -72,48 +60,47 @@ describe('Test video blacklist', function () {
72 60
73 it('Should not have the video blacklisted in videos list/search on server 1', async function () { 61 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
74 { 62 {
75 const res = await getVideosList(servers[0].url) 63 const { total, data } = await servers[0].videos.list()
76 64
77 expect(res.body.total).to.equal(0) 65 expect(total).to.equal(0)
78 expect(res.body.data).to.be.an('array') 66 expect(data).to.be.an('array')
79 expect(res.body.data.length).to.equal(0) 67 expect(data.length).to.equal(0)
80 } 68 }
81 69
82 { 70 {
83 const res = await searchVideo(servers[0].url, 'name') 71 const body = await servers[0].search.searchVideos({ search: 'video' })
84 72
85 expect(res.body.total).to.equal(0) 73 expect(body.total).to.equal(0)
86 expect(res.body.data).to.be.an('array') 74 expect(body.data).to.be.an('array')
87 expect(res.body.data.length).to.equal(0) 75 expect(body.data.length).to.equal(0)
88 } 76 }
89 }) 77 })
90 78
91 it('Should have the blacklisted video in videos list/search on server 2', async function () { 79 it('Should have the blacklisted video in videos list/search on server 2', async function () {
92 { 80 {
93 const res = await getVideosList(servers[1].url) 81 const { total, data } = await servers[1].videos.list()
94 82
95 expect(res.body.total).to.equal(2) 83 expect(total).to.equal(2)
96 expect(res.body.data).to.be.an('array') 84 expect(data).to.be.an('array')
97 expect(res.body.data.length).to.equal(2) 85 expect(data.length).to.equal(2)
98 } 86 }
99 87
100 { 88 {
101 const res = await searchVideo(servers[1].url, 'video') 89 const body = await servers[1].search.searchVideos({ search: 'video' })
102 90
103 expect(res.body.total).to.equal(2) 91 expect(body.total).to.equal(2)
104 expect(res.body.data).to.be.an('array') 92 expect(body.data).to.be.an('array')
105 expect(res.body.data.length).to.equal(2) 93 expect(body.data.length).to.equal(2)
106 } 94 }
107 }) 95 })
108 }) 96 })
109 97
110 describe('When listing manually blacklisted videos', function () { 98 describe('When listing manually blacklisted videos', function () {
111 it('Should display all the blacklisted videos', async function () { 99 it('Should display all the blacklisted videos', async function () {
112 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken }) 100 const body = await command.list()
113 101 expect(body.total).to.equal(2)
114 expect(res.body.total).to.equal(2)
115 102
116 const blacklistedVideos = res.body.data 103 const blacklistedVideos = body.data
117 expect(blacklistedVideos).to.be.an('array') 104 expect(blacklistedVideos).to.be.an('array')
118 expect(blacklistedVideos.length).to.equal(2) 105 expect(blacklistedVideos.length).to.equal(2)
119 106
@@ -124,79 +111,66 @@ describe('Test video blacklist', function () {
124 }) 111 })
125 112
126 it('Should display all the blacklisted videos when applying manual type filter', async function () { 113 it('Should display all the blacklisted videos when applying manual type filter', async function () {
127 const res = await getBlacklistedVideosList({ 114 const body = await command.list({ type: VideoBlacklistType.MANUAL })
128 url: servers[0].url, 115 expect(body.total).to.equal(2)
129 token: servers[0].accessToken,
130 type: VideoBlacklistType.MANUAL
131 })
132 116
133 expect(res.body.total).to.equal(2) 117 const blacklistedVideos = body.data
134
135 const blacklistedVideos = res.body.data
136 expect(blacklistedVideos).to.be.an('array') 118 expect(blacklistedVideos).to.be.an('array')
137 expect(blacklistedVideos.length).to.equal(2) 119 expect(blacklistedVideos.length).to.equal(2)
138 }) 120 })
139 121
140 it('Should display nothing when applying automatic type filter', async function () { 122 it('Should display nothing when applying automatic type filter', async function () {
141 const res = await getBlacklistedVideosList({ 123 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
142 url: servers[0].url, 124 expect(body.total).to.equal(0)
143 token: servers[0].accessToken,
144 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
145 })
146
147 expect(res.body.total).to.equal(0)
148 125
149 const blacklistedVideos = res.body.data 126 const blacklistedVideos = body.data
150 expect(blacklistedVideos).to.be.an('array') 127 expect(blacklistedVideos).to.be.an('array')
151 expect(blacklistedVideos.length).to.equal(0) 128 expect(blacklistedVideos.length).to.equal(0)
152 }) 129 })
153 130
154 it('Should get the correct sort when sorting by descending id', async function () { 131 it('Should get the correct sort when sorting by descending id', async function () {
155 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-id' }) 132 const body = await command.list({ sort: '-id' })
156 expect(res.body.total).to.equal(2) 133 expect(body.total).to.equal(2)
157 134
158 const blacklistedVideos = res.body.data 135 const blacklistedVideos = body.data
159 expect(blacklistedVideos).to.be.an('array') 136 expect(blacklistedVideos).to.be.an('array')
160 expect(blacklistedVideos.length).to.equal(2) 137 expect(blacklistedVideos.length).to.equal(2)
161 138
162 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ]) 139 const result = orderBy(body.data, [ 'id' ], [ 'desc' ])
163
164 expect(blacklistedVideos).to.deep.equal(result) 140 expect(blacklistedVideos).to.deep.equal(result)
165 }) 141 })
166 142
167 it('Should get the correct sort when sorting by descending video name', async function () { 143 it('Should get the correct sort when sorting by descending video name', async function () {
168 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 144 const body = await command.list({ sort: '-name' })
169 expect(res.body.total).to.equal(2) 145 expect(body.total).to.equal(2)
170 146
171 const blacklistedVideos = res.body.data 147 const blacklistedVideos = body.data
172 expect(blacklistedVideos).to.be.an('array') 148 expect(blacklistedVideos).to.be.an('array')
173 expect(blacklistedVideos.length).to.equal(2) 149 expect(blacklistedVideos.length).to.equal(2)
174 150
175 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ]) 151 const result = orderBy(body.data, [ 'name' ], [ 'desc' ])
176
177 expect(blacklistedVideos).to.deep.equal(result) 152 expect(blacklistedVideos).to.deep.equal(result)
178 }) 153 })
179 154
180 it('Should get the correct sort when sorting by ascending creation date', async function () { 155 it('Should get the correct sort when sorting by ascending creation date', async function () {
181 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) 156 const body = await command.list({ sort: 'createdAt' })
182 expect(res.body.total).to.equal(2) 157 expect(body.total).to.equal(2)
183 158
184 const blacklistedVideos = res.body.data 159 const blacklistedVideos = body.data
185 expect(blacklistedVideos).to.be.an('array') 160 expect(blacklistedVideos).to.be.an('array')
186 expect(blacklistedVideos.length).to.equal(2) 161 expect(blacklistedVideos.length).to.equal(2)
187 162
188 const result = orderBy(res.body.data, [ 'createdAt' ]) 163 const result = orderBy(body.data, [ 'createdAt' ])
189
190 expect(blacklistedVideos).to.deep.equal(result) 164 expect(blacklistedVideos).to.deep.equal(result)
191 }) 165 })
192 }) 166 })
193 167
194 describe('When updating blacklisted videos', function () { 168 describe('When updating blacklisted videos', function () {
195 it('Should change the reason', async function () { 169 it('Should change the reason', async function () {
196 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated') 170 await command.update({ videoId, reason: 'my super reason updated' })
197 171
198 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 172 const body = await command.list({ sort: '-name' })
199 const video = res.body.data.find(b => b.video.id === videoId) 173 const video = body.data.find(b => b.video.id === videoId)
200 174
201 expect(video.reason).to.equal('my super reason updated') 175 expect(video.reason).to.equal('my super reason updated')
202 }) 176 })
@@ -206,12 +180,12 @@ describe('Test video blacklist', function () {
206 it('Should display blacklisted videos', async function () { 180 it('Should display blacklisted videos', async function () {
207 await blacklistVideosOnServer(servers[1]) 181 await blacklistVideosOnServer(servers[1])
208 182
209 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) 183 const { total, data } = await servers[1].videos.listMyVideos()
210 184
211 expect(res.body.total).to.equal(2) 185 expect(total).to.equal(2)
212 expect(res.body.data).to.have.lengthOf(2) 186 expect(data).to.have.lengthOf(2)
213 187
214 for (const video of res.body.data) { 188 for (const video of data) {
215 expect(video.blacklisted).to.be.true 189 expect(video.blacklisted).to.be.true
216 expect(video.blacklistedReason).to.equal('super reason') 190 expect(video.blacklistedReason).to.equal('super reason')
217 } 191 }
@@ -223,39 +197,38 @@ describe('Test video blacklist', function () {
223 let blacklist = [] 197 let blacklist = []
224 198
225 it('Should not have any video in videos list on server 1', async function () { 199 it('Should not have any video in videos list on server 1', async function () {
226 const res = await getVideosList(servers[0].url) 200 const { total, data } = await servers[0].videos.list()
227 expect(res.body.total).to.equal(0) 201 expect(total).to.equal(0)
228 expect(res.body.data).to.be.an('array') 202 expect(data).to.be.an('array')
229 expect(res.body.data.length).to.equal(0) 203 expect(data.length).to.equal(0)
230 }) 204 })
231 205
232 it('Should remove a video from the blacklist on server 1', async function () { 206 it('Should remove a video from the blacklist on server 1', async function () {
233 // Get one video in the blacklist 207 // Get one video in the blacklist
234 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 208 const body = await command.list({ sort: '-name' })
235 videoToRemove = res.body.data[0] 209 videoToRemove = body.data[0]
236 blacklist = res.body.data.slice(1) 210 blacklist = body.data.slice(1)
237 211
238 // Remove it 212 // Remove it
239 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id) 213 await command.remove({ videoId: videoToRemove.video.id })
240 }) 214 })
241 215
242 it('Should have the ex-blacklisted video in videos list on server 1', async function () { 216 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
243 const res = await getVideosList(servers[0].url) 217 const { total, data } = await servers[0].videos.list()
244 expect(res.body.total).to.equal(1) 218 expect(total).to.equal(1)
245 219
246 const videos = res.body.data 220 expect(data).to.be.an('array')
247 expect(videos).to.be.an('array') 221 expect(data.length).to.equal(1)
248 expect(videos.length).to.equal(1)
249 222
250 expect(videos[0].name).to.equal(videoToRemove.video.name) 223 expect(data[0].name).to.equal(videoToRemove.video.name)
251 expect(videos[0].id).to.equal(videoToRemove.video.id) 224 expect(data[0].id).to.equal(videoToRemove.video.id)
252 }) 225 })
253 226
254 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 227 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
255 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: '-name' }) 228 const body = await command.list({ sort: '-name' })
256 expect(res.body.total).to.equal(1) 229 expect(body.total).to.equal(1)
257 230
258 const videos = res.body.data 231 const videos = body.data
259 expect(videos).to.be.an('array') 232 expect(videos).to.be.an('array')
260 expect(videos.length).to.equal(1) 233 expect(videos.length).to.equal(1)
261 expect(videos).to.deep.equal(blacklist) 234 expect(videos).to.deep.equal(blacklist)
@@ -270,12 +243,12 @@ describe('Test video blacklist', function () {
270 this.timeout(10000) 243 this.timeout(10000)
271 244
272 { 245 {
273 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) 246 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 3' } })
274 video3UUID = res.body.video.uuid 247 video3UUID = uuid
275 } 248 }
276 { 249 {
277 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) 250 const { uuid } = await servers[0].videos.upload({ attributes: { name: 'Video 4' } })
278 video4UUID = res.body.video.uuid 251 video4UUID = uuid
279 } 252 }
280 253
281 await waitJobs(servers) 254 await waitJobs(servers)
@@ -284,51 +257,51 @@ describe('Test video blacklist', function () {
284 it('Should blacklist video 3 and keep it federated', async function () { 257 it('Should blacklist video 3 and keep it federated', async function () {
285 this.timeout(10000) 258 this.timeout(10000)
286 259
287 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video3UUID, 'super reason', false) 260 await command.add({ videoId: video3UUID, reason: 'super reason', unfederate: false })
288 261
289 await waitJobs(servers) 262 await waitJobs(servers)
290 263
291 { 264 {
292 const res = await getVideosList(servers[0].url) 265 const { data } = await servers[0].videos.list()
293 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined 266 expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
294 } 267 }
295 268
296 { 269 {
297 const res = await getVideosList(servers[1].url) 270 const { data } = await servers[1].videos.list()
298 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined 271 expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
299 } 272 }
300 }) 273 })
301 274
302 it('Should unfederate the video', async function () { 275 it('Should unfederate the video', async function () {
303 this.timeout(10000) 276 this.timeout(10000)
304 277
305 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, video4UUID, 'super reason', true) 278 await command.add({ videoId: video4UUID, reason: 'super reason', unfederate: true })
306 279
307 await waitJobs(servers) 280 await waitJobs(servers)
308 281
309 for (const server of servers) { 282 for (const server of servers) {
310 const res = await getVideosList(server.url) 283 const { data } = await server.videos.list()
311 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 284 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
312 } 285 }
313 }) 286 })
314 287
315 it('Should have the video unfederated even after an Update AP message', async function () { 288 it('Should have the video unfederated even after an Update AP message', async function () {
316 this.timeout(10000) 289 this.timeout(10000)
317 290
318 await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) 291 await servers[0].videos.update({ id: video4UUID, attributes: { description: 'super description' } })
319 292
320 await waitJobs(servers) 293 await waitJobs(servers)
321 294
322 for (const server of servers) { 295 for (const server of servers) {
323 const res = await getVideosList(server.url) 296 const { data } = await server.videos.list()
324 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 297 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
325 } 298 }
326 }) 299 })
327 300
328 it('Should have the correct video blacklist unfederate attribute', async function () { 301 it('Should have the correct video blacklist unfederate attribute', async function () {
329 const res = await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, sort: 'createdAt' }) 302 const body = await command.list({ sort: 'createdAt' })
330 303
331 const blacklistedVideos: VideoBlacklist[] = res.body.data 304 const blacklistedVideos = body.data
332 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID) 305 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
333 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID) 306 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
334 307
@@ -339,13 +312,13 @@ describe('Test video blacklist', function () {
339 it('Should remove the video from blacklist and refederate the video', async function () { 312 it('Should remove the video from blacklist and refederate the video', async function () {
340 this.timeout(10000) 313 this.timeout(10000)
341 314
342 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, video4UUID) 315 await command.remove({ videoId: video4UUID })
343 316
344 await waitJobs(servers) 317 await waitJobs(servers)
345 318
346 for (const server of servers) { 319 for (const server of servers) {
347 const res = await getVideosList(server.url) 320 const { data } = await server.videos.list()
348 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined 321 expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
349 } 322 }
350 }) 323 })
351 324
@@ -359,7 +332,7 @@ describe('Test video blacklist', function () {
359 before(async function () { 332 before(async function () {
360 this.timeout(20000) 333 this.timeout(20000)
361 334
362 killallServers([ servers[0] ]) 335 await killallServers([ servers[0] ])
363 336
364 const config = { 337 const config = {
365 auto_blacklist: { 338 auto_blacklist: {
@@ -370,106 +343,79 @@ describe('Test video blacklist', function () {
370 } 343 }
371 } 344 }
372 } 345 }
373 await reRunServer(servers[0], config) 346 await servers[0].run(config)
374 347
375 { 348 {
376 const user = { username: 'user_without_flag', password: 'password' } 349 const user = { username: 'user_without_flag', password: 'password' }
377 await createUser({ 350 await servers[0].users.create({
378 url: servers[0].url,
379 accessToken: servers[0].accessToken,
380 username: user.username, 351 username: user.username,
381 adminFlags: UserAdminFlag.NONE, 352 adminFlags: UserAdminFlag.NONE,
382 password: user.password, 353 password: user.password,
383 role: UserRole.USER 354 role: UserRole.USER
384 }) 355 })
385 356
386 userWithoutFlag = await userLogin(servers[0], user) 357 userWithoutFlag = await servers[0].login.getAccessToken(user)
387 358
388 const res = await getMyUserInformation(servers[0].url, userWithoutFlag) 359 const { videoChannels } = await servers[0].users.getMyInfo({ token: userWithoutFlag })
389 const body: User = res.body 360 channelOfUserWithoutFlag = videoChannels[0].id
390 channelOfUserWithoutFlag = body.videoChannels[0].id
391 } 361 }
392 362
393 { 363 {
394 const user = { username: 'user_with_flag', password: 'password' } 364 const user = { username: 'user_with_flag', password: 'password' }
395 await createUser({ 365 await servers[0].users.create({
396 url: servers[0].url,
397 accessToken: servers[0].accessToken,
398 username: user.username, 366 username: user.username,
399 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST, 367 adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST,
400 password: user.password, 368 password: user.password,
401 role: UserRole.USER 369 role: UserRole.USER
402 }) 370 })
403 371
404 userWithFlag = await userLogin(servers[0], user) 372 userWithFlag = await servers[0].login.getAccessToken(user)
405 } 373 }
406 374
407 await waitJobs(servers) 375 await waitJobs(servers)
408 }) 376 })
409 377
410 it('Should auto blacklist a video on upload', async function () { 378 it('Should auto blacklist a video on upload', async function () {
411 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) 379 await servers[0].videos.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } })
412
413 const res = await getBlacklistedVideosList({
414 url: servers[0].url,
415 token: servers[0].accessToken,
416 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
417 })
418 380
419 expect(res.body.total).to.equal(1) 381 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
420 expect(res.body.data[0].video.name).to.equal('blacklisted') 382 expect(body.total).to.equal(1)
383 expect(body.data[0].video.name).to.equal('blacklisted')
421 }) 384 })
422 385
423 it('Should auto blacklist a video on URL import', async function () { 386 it('Should auto blacklist a video on URL import', async function () {
424 this.timeout(15000) 387 this.timeout(15000)
425 388
426 const attributes = { 389 const attributes = {
427 targetUrl: getGoodVideoUrl(), 390 targetUrl: FIXTURE_URLS.goodVideo,
428 name: 'URL import', 391 name: 'URL import',
429 channelId: channelOfUserWithoutFlag 392 channelId: channelOfUserWithoutFlag
430 } 393 }
431 await importVideo(servers[0].url, userWithoutFlag, attributes) 394 await servers[0].imports.importVideo({ token: userWithoutFlag, attributes })
432 395
433 const res = await getBlacklistedVideosList({ 396 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
434 url: servers[0].url, 397 expect(body.total).to.equal(2)
435 token: servers[0].accessToken, 398 expect(body.data[1].video.name).to.equal('URL import')
436 sort: 'createdAt',
437 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
438 })
439
440 expect(res.body.total).to.equal(2)
441 expect(res.body.data[1].video.name).to.equal('URL import')
442 }) 399 })
443 400
444 it('Should auto blacklist a video on torrent import', async function () { 401 it('Should auto blacklist a video on torrent import', async function () {
445 const attributes = { 402 const attributes = {
446 magnetUri: getMagnetURI(), 403 magnetUri: FIXTURE_URLS.magnet,
447 name: 'Torrent import', 404 name: 'Torrent import',
448 channelId: channelOfUserWithoutFlag 405 channelId: channelOfUserWithoutFlag
449 } 406 }
450 await importVideo(servers[0].url, userWithoutFlag, attributes) 407 await servers[0].imports.importVideo({ token: userWithoutFlag, attributes })
451
452 const res = await getBlacklistedVideosList({
453 url: servers[0].url,
454 token: servers[0].accessToken,
455 sort: 'createdAt',
456 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
457 })
458 408
459 expect(res.body.total).to.equal(3) 409 const body = await command.list({ sort: 'createdAt', type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
460 expect(res.body.data[2].video.name).to.equal('Torrent import') 410 expect(body.total).to.equal(3)
411 expect(body.data[2].video.name).to.equal('Torrent import')
461 }) 412 })
462 413
463 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { 414 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
464 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) 415 await servers[0].videos.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
465
466 const res = await getBlacklistedVideosList({
467 url: servers[0].url,
468 token: servers[0].accessToken,
469 type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED
470 })
471 416
472 expect(res.body.total).to.equal(3) 417 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
418 expect(body.total).to.equal(3)
473 }) 419 })
474 }) 420 })
475 421