]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/videos/video-blacklist-management.ts
Add advanced search in client
[github/Chocobozzz/PeerTube.git] / server / tests / api / videos / video-blacklist-management.ts
CommitLineData
792dbaf0
GS
1/* tslint:disable:no-unused-expressions */
2
792dbaf0 3import * as chai from 'chai'
792dbaf0 4import * as lodash from 'lodash'
975e6e0e 5import 'mocha'
792dbaf0 6import {
975e6e0e 7 addVideoToBlacklist,
792dbaf0 8 flushAndRunMultipleServers,
975e6e0e
C
9 getBlacklistedVideosList,
10 getSortedBlacklistedVideosList,
792dbaf0 11 getVideosList,
975e6e0e 12 killallServers,
792dbaf0 13 removeVideoFromBlacklist,
975e6e0e
C
14 ServerInfo,
15 setAccessTokensToServers,
3cd0734f 16 uploadVideo
c5d31dba
C
17} from '../../utils/index'
18import { doubleFollow } from '../../utils/server/follows'
3cd0734f 19import { waitJobs } from '../../utils/server/jobs'
975e6e0e
C
20
21const expect = chai.expect
22const orderBy = lodash.orderBy
792dbaf0
GS
23
24describe('Test video blacklist management', function () {
25 let servers: ServerInfo[] = []
26
975e6e0e 27 async function blacklistVideosOnServer (server: ServerInfo) {
792dbaf0
GS
28 const res = await getVideosList(server.url)
29
30 const videos = res.body.data
31 for (let video of videos) {
32 await addVideoToBlacklist(server.url, server.accessToken, video.id)
33 }
34 }
35
36 before(async function () {
572f8d3d 37 this.timeout(50000)
792dbaf0
GS
38
39 // Run servers
40 servers = await flushAndRunMultipleServers(2)
41
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
44
975e6e0e
C
45 // Server 1 and server 2 follow each other
46 await doubleFollow(servers[0], servers[1])
792dbaf0 47
975e6e0e
C
48 // Upload 2 videos on server 2
49 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
50 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
792dbaf0 51
572f8d3d 52 // Wait videos propagation, server 2 has transcoding enabled
3cd0734f 53 await waitJobs(servers)
792dbaf0 54
975e6e0e
C
55 // Blacklist the two videos on server 1
56 await blacklistVideosOnServer(servers[0])
792dbaf0
GS
57 })
58
59 describe('When listing blacklisted videos', function () {
60 it('Should display all the blacklisted videos', async function () {
61 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
62
63 expect(res.body.total).to.equal(2)
64
65 const videos = res.body.data
66 expect(videos).to.be.an('array')
67 expect(videos.length).to.equal(2)
68 })
69
70 it('Should get the correct sort when sorting by descending id', async function () {
71 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
72 expect(res.body.total).to.equal(2)
73
74 const videos = res.body.data
75 expect(videos).to.be.an('array')
76 expect(videos.length).to.equal(2)
77
78 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
79
80 expect(videos).to.deep.equal(result)
81 })
82
83 it('Should get the correct sort when sorting by descending video name', async function () {
84 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
85 expect(res.body.total).to.equal(2)
86
87 const videos = res.body.data
88 expect(videos).to.be.an('array')
89 expect(videos.length).to.equal(2)
90
91 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
92
93 expect(videos).to.deep.equal(result)
94 })
95
96 it('Should get the correct sort when sorting by ascending creation date', async function () {
97 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
98 expect(res.body.total).to.equal(2)
99
100 const videos = res.body.data
101 expect(videos).to.be.an('array')
102 expect(videos.length).to.equal(2)
103
104 const result = orderBy(res.body.data, [ 'createdAt' ])
105
106 expect(videos).to.deep.equal(result)
107 })
108 })
109
110 describe('When removing a blacklisted video', function () {
111 let videoToRemove
112 let blacklist = []
113
975e6e0e 114 it('Should not have any video in videos list on server 1', async function () {
792dbaf0
GS
115 const res = await getVideosList(servers[0].url)
116 expect(res.body.total).to.equal(0)
117 expect(res.body.data).to.be.an('array')
118 expect(res.body.data.length).to.equal(0)
119 })
120
975e6e0e 121 it('Should remove a video from the blacklist on server 1', async function () {
792dbaf0
GS
122 // Get one video in the blacklist
123 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
124 videoToRemove = res.body.data[0]
125 blacklist = res.body.data.slice(1)
126
127 // Remove it
128 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId)
129 })
130
975e6e0e 131 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
792dbaf0
GS
132 const res = await getVideosList(servers[0].url)
133 expect(res.body.total).to.equal(1)
134
135 const videos = res.body.data
136 expect(videos).to.be.an('array')
137 expect(videos.length).to.equal(1)
138
139 expect(videos[0].name).to.equal(videoToRemove.name)
140 expect(videos[0].id).to.equal(videoToRemove.videoId)
141 })
142
975e6e0e 143 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
792dbaf0
GS
144 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
145 expect(res.body.total).to.equal(1)
146
147 const videos = res.body.data
148 expect(videos).to.be.an('array')
149 expect(videos.length).to.equal(1)
150 expect(videos).to.deep.equal(blacklist)
151 })
152 })
153
154 after(async function () {
155 killallServers(servers)
792dbaf0
GS
156 })
157})