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