]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/videos/video-blacklist.ts
Improve tests when waiting pending jobs
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-blacklist.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import 'mocha'
5 import {
6 addVideoToBlacklist,
7 flushAndRunMultipleServers,
8 getVideosList,
9 killallServers,
10 searchVideo,
11 ServerInfo,
12 setAccessTokensToServers,
13 uploadVideo
14 } from '../../utils/index'
15 import { doubleFollow } from '../../utils/server/follows'
16 import { waitJobs } from '../../utils/server/jobs'
17
18 const expect = chai.expect
19
20 describe('Test video blacklists', function () {
21 let servers: ServerInfo[] = []
22
23 before(async function () {
24 this.timeout(50000)
25
26 // Run servers
27 servers = await flushAndRunMultipleServers(2)
28
29 // Get the access tokens
30 await setAccessTokensToServers(servers)
31
32 // Server 1 and server 2 follow each other
33 await doubleFollow(servers[0], servers[1])
34
35 // Upload a video on server 2
36 const videoAttributes = {
37 name: 'my super name for server 2',
38 description: 'my super description for server 2'
39 }
40 await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
41
42 // Wait videos propagation, server 2 has transcoding enabled
43 await waitJobs(servers)
44
45 const res = await getVideosList(servers[0].url)
46 const videos = res.body.data
47
48 expect(videos.length).to.equal(1)
49
50 servers[0].remoteVideo = videos.find(video => video.name === 'my super name for server 2')
51 })
52
53 it('Should blacklist a remote video on server 1', async function () {
54 await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id)
55 })
56
57 it('Should not have the video blacklisted in videos list on server 1', async function () {
58 const res = await getVideosList(servers[0].url)
59
60 expect(res.body.total).to.equal(0)
61 expect(res.body.data).to.be.an('array')
62 expect(res.body.data.length).to.equal(0)
63 })
64
65 it('Should not have the video blacklisted in videos search on server 1', async function () {
66 const res = await searchVideo(servers[0].url, 'name')
67
68 expect(res.body.total).to.equal(0)
69 expect(res.body.data).to.be.an('array')
70 expect(res.body.data.length).to.equal(0)
71 })
72
73 it('Should have the blacklisted video in videos list on server 2', async function () {
74 const res = await getVideosList(servers[1].url)
75
76 expect(res.body.total).to.equal(1)
77 expect(res.body.data).to.be.an('array')
78 expect(res.body.data.length).to.equal(1)
79 })
80
81 it('Should have the video blacklisted in videos search on server 2', async function () {
82 const res = await searchVideo(servers[1].url, 'name')
83
84 expect(res.body.total).to.equal(1)
85 expect(res.body.data).to.be.an('array')
86 expect(res.body.data.length).to.equal(1)
87 })
88
89 after(async function () {
90 killallServers(servers)
91 })
92 })