aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/moderation/video-blacklist.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-15 10:02:54 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commitd23dd9fbfc4d26026352c10f81d2795ceaf2908a (patch)
treeda82286d423c5e834a1ee2dcd5970076b8263cf1 /server/tests/api/moderation/video-blacklist.ts
parent7926c5f9b3ffcabb1ffb0dcfa5e48b8e0b88fbc0 (diff)
downloadPeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.gz
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.tar.zst
PeerTube-d23dd9fbfc4d26026352c10f81d2795ceaf2908a.zip
Introduce videos command
Diffstat (limited to 'server/tests/api/moderation/video-blacklist.ts')
-rw-r--r--server/tests/api/moderation/video-blacklist.ts92
1 files changed, 43 insertions, 49 deletions
diff --git a/server/tests/api/moderation/video-blacklist.ts b/server/tests/api/moderation/video-blacklist.ts
index ef25cfb8e..2f2e678e7 100644
--- a/server/tests/api/moderation/video-blacklist.ts
+++ b/server/tests/api/moderation/video-blacklist.ts
@@ -8,15 +8,11 @@ import {
8 cleanupTests, 8 cleanupTests,
9 doubleFollow, 9 doubleFollow,
10 flushAndRunMultipleServers, 10 flushAndRunMultipleServers,
11 getMyVideos,
12 getVideosList,
13 ImportsCommand, 11 ImportsCommand,
14 killallServers, 12 killallServers,
15 reRunServer, 13 reRunServer,
16 ServerInfo, 14 ServerInfo,
17 setAccessTokensToServers, 15 setAccessTokensToServers,
18 updateVideo,
19 uploadVideo,
20 waitJobs 16 waitJobs
21} from '@shared/extra-utils' 17} from '@shared/extra-utils'
22import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models' 18import { UserAdminFlag, UserRole, VideoBlacklist, VideoBlacklistType } from '@shared/models'
@@ -29,10 +25,9 @@ describe('Test video blacklist', function () {
29 let command: BlacklistCommand 25 let command: BlacklistCommand
30 26
31 async function blacklistVideosOnServer (server: ServerInfo) { 27 async function blacklistVideosOnServer (server: ServerInfo) {
32 const res = await getVideosList(server.url) 28 const { data } = await server.videosCommand.list()
33 29
34 const videos = res.body.data 30 for (const video of data) {
35 for (const video of videos) {
36 await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' }) 31 await server.blacklistCommand.add({ videoId: video.id, reason: 'super reason' })
37 } 32 }
38 } 33 }
@@ -50,8 +45,8 @@ describe('Test video blacklist', function () {
50 await doubleFollow(servers[0], servers[1]) 45 await doubleFollow(servers[0], servers[1])
51 46
52 // Upload 2 videos on server 2 47 // Upload 2 videos on server 2
53 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' }) 48 await servers[1].videosCommand.upload({ attributes: { name: 'My 1st video', description: 'A video on server 2' } })
54 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' }) 49 await servers[1].videosCommand.upload({ attributes: { name: 'My 2nd video', description: 'A video on server 2' } })
55 50
56 // Wait videos propagation, server 2 has transcoding enabled 51 // Wait videos propagation, server 2 has transcoding enabled
57 await waitJobs(servers) 52 await waitJobs(servers)
@@ -66,11 +61,11 @@ describe('Test video blacklist', function () {
66 61
67 it('Should not have the video blacklisted in videos list/search on server 1', async function () { 62 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
68 { 63 {
69 const res = await getVideosList(servers[0].url) 64 const { total, data } = await servers[0].videosCommand.list()
70 65
71 expect(res.body.total).to.equal(0) 66 expect(total).to.equal(0)
72 expect(res.body.data).to.be.an('array') 67 expect(data).to.be.an('array')
73 expect(res.body.data.length).to.equal(0) 68 expect(data.length).to.equal(0)
74 } 69 }
75 70
76 { 71 {
@@ -84,11 +79,11 @@ describe('Test video blacklist', function () {
84 79
85 it('Should have the blacklisted video in videos list/search on server 2', async function () { 80 it('Should have the blacklisted video in videos list/search on server 2', async function () {
86 { 81 {
87 const res = await getVideosList(servers[1].url) 82 const { total, data } = await servers[1].videosCommand.list()
88 83
89 expect(res.body.total).to.equal(2) 84 expect(total).to.equal(2)
90 expect(res.body.data).to.be.an('array') 85 expect(data).to.be.an('array')
91 expect(res.body.data.length).to.equal(2) 86 expect(data.length).to.equal(2)
92 } 87 }
93 88
94 { 89 {
@@ -186,12 +181,12 @@ describe('Test video blacklist', function () {
186 it('Should display blacklisted videos', async function () { 181 it('Should display blacklisted videos', async function () {
187 await blacklistVideosOnServer(servers[1]) 182 await blacklistVideosOnServer(servers[1])
188 183
189 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5) 184 const { total, data } = await servers[1].videosCommand.listMyVideos()
190 185
191 expect(res.body.total).to.equal(2) 186 expect(total).to.equal(2)
192 expect(res.body.data).to.have.lengthOf(2) 187 expect(data).to.have.lengthOf(2)
193 188
194 for (const video of res.body.data) { 189 for (const video of data) {
195 expect(video.blacklisted).to.be.true 190 expect(video.blacklisted).to.be.true
196 expect(video.blacklistedReason).to.equal('super reason') 191 expect(video.blacklistedReason).to.equal('super reason')
197 } 192 }
@@ -203,10 +198,10 @@ describe('Test video blacklist', function () {
203 let blacklist = [] 198 let blacklist = []
204 199
205 it('Should not have any video in videos list on server 1', async function () { 200 it('Should not have any video in videos list on server 1', async function () {
206 const res = await getVideosList(servers[0].url) 201 const { total, data } = await servers[0].videosCommand.list()
207 expect(res.body.total).to.equal(0) 202 expect(total).to.equal(0)
208 expect(res.body.data).to.be.an('array') 203 expect(data).to.be.an('array')
209 expect(res.body.data.length).to.equal(0) 204 expect(data.length).to.equal(0)
210 }) 205 })
211 206
212 it('Should remove a video from the blacklist on server 1', async function () { 207 it('Should remove a video from the blacklist on server 1', async function () {
@@ -220,15 +215,14 @@ describe('Test video blacklist', function () {
220 }) 215 })
221 216
222 it('Should have the ex-blacklisted video in videos list on server 1', async function () { 217 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
223 const res = await getVideosList(servers[0].url) 218 const { total, data } = await servers[0].videosCommand.list()
224 expect(res.body.total).to.equal(1) 219 expect(total).to.equal(1)
225 220
226 const videos = res.body.data 221 expect(data).to.be.an('array')
227 expect(videos).to.be.an('array') 222 expect(data.length).to.equal(1)
228 expect(videos.length).to.equal(1)
229 223
230 expect(videos[0].name).to.equal(videoToRemove.video.name) 224 expect(data[0].name).to.equal(videoToRemove.video.name)
231 expect(videos[0].id).to.equal(videoToRemove.video.id) 225 expect(data[0].id).to.equal(videoToRemove.video.id)
232 }) 226 })
233 227
234 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () { 228 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
@@ -250,12 +244,12 @@ describe('Test video blacklist', function () {
250 this.timeout(10000) 244 this.timeout(10000)
251 245
252 { 246 {
253 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' }) 247 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 3' } })
254 video3UUID = res.body.video.uuid 248 video3UUID = uuid
255 } 249 }
256 { 250 {
257 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 4' }) 251 const { uuid } = await servers[0].videosCommand.upload({ attributes: { name: 'Video 4' } })
258 video4UUID = res.body.video.uuid 252 video4UUID = uuid
259 } 253 }
260 254
261 await waitJobs(servers) 255 await waitJobs(servers)
@@ -269,13 +263,13 @@ describe('Test video blacklist', function () {
269 await waitJobs(servers) 263 await waitJobs(servers)
270 264
271 { 265 {
272 const res = await getVideosList(servers[0].url) 266 const { data } = await servers[0].videosCommand.list()
273 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined 267 expect(data.find(v => v.uuid === video3UUID)).to.be.undefined
274 } 268 }
275 269
276 { 270 {
277 const res = await getVideosList(servers[1].url) 271 const { data } = await servers[1].videosCommand.list()
278 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined 272 expect(data.find(v => v.uuid === video3UUID)).to.not.be.undefined
279 } 273 }
280 }) 274 })
281 275
@@ -287,21 +281,21 @@ describe('Test video blacklist', function () {
287 await waitJobs(servers) 281 await waitJobs(servers)
288 282
289 for (const server of servers) { 283 for (const server of servers) {
290 const res = await getVideosList(server.url) 284 const { data } = await server.videosCommand.list()
291 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 285 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
292 } 286 }
293 }) 287 })
294 288
295 it('Should have the video unfederated even after an Update AP message', async function () { 289 it('Should have the video unfederated even after an Update AP message', async function () {
296 this.timeout(10000) 290 this.timeout(10000)
297 291
298 await updateVideo(servers[0].url, servers[0].accessToken, video4UUID, { description: 'super description' }) 292 await servers[0].videosCommand.update({ id: video4UUID, attributes: { description: 'super description' } })
299 293
300 await waitJobs(servers) 294 await waitJobs(servers)
301 295
302 for (const server of servers) { 296 for (const server of servers) {
303 const res = await getVideosList(server.url) 297 const { data } = await server.videosCommand.list()
304 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined 298 expect(data.find(v => v.uuid === video4UUID)).to.be.undefined
305 } 299 }
306 }) 300 })
307 301
@@ -324,8 +318,8 @@ describe('Test video blacklist', function () {
324 await waitJobs(servers) 318 await waitJobs(servers)
325 319
326 for (const server of servers) { 320 for (const server of servers) {
327 const res = await getVideosList(server.url) 321 const { data } = await server.videosCommand.list()
328 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined 322 expect(data.find(v => v.uuid === video4UUID)).to.not.be.undefined
329 } 323 }
330 }) 324 })
331 325
@@ -383,7 +377,7 @@ describe('Test video blacklist', function () {
383 }) 377 })
384 378
385 it('Should auto blacklist a video on upload', async function () { 379 it('Should auto blacklist a video on upload', async function () {
386 await uploadVideo(servers[0].url, userWithoutFlag, { name: 'blacklisted' }) 380 await servers[0].videosCommand.upload({ token: userWithoutFlag, attributes: { name: 'blacklisted' } })
387 381
388 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) 382 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
389 expect(body.total).to.equal(1) 383 expect(body.total).to.equal(1)
@@ -419,7 +413,7 @@ describe('Test video blacklist', function () {
419 }) 413 })
420 414
421 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () { 415 it('Should not auto blacklist a video on upload if the user has the bypass blacklist flag', async function () {
422 await uploadVideo(servers[0].url, userWithFlag, { name: 'not blacklisted' }) 416 await servers[0].videosCommand.upload({ token: userWithFlag, attributes: { name: 'not blacklisted' } })
423 417
424 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED }) 418 const body = await command.list({ type: VideoBlacklistType.AUTO_BEFORE_PUBLISHED })
425 expect(body.total).to.equal(3) 419 expect(body.total).to.equal(3)