1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { orderBy } from 'lodash'
8 flushAndRunMultipleServers,
9 getBlacklistedVideosList,
11 getSortedBlacklistedVideosList,
14 removeVideoFromBlacklist,
17 setAccessTokensToServers,
22 } from '../../../../shared/utils/index'
23 import { doubleFollow } from '../../../../shared/utils/server/follows'
24 import { waitJobs } from '../../../../shared/utils/server/jobs'
25 import { VideoBlacklist } from '../../../../shared/models/videos'
27 const expect = chai.expect
29 describe('Test video blacklist management', function () {
30 let servers: ServerInfo[] = []
33 async function blacklistVideosOnServer (server: ServerInfo) {
34 const res = await getVideosList(server.url)
36 const videos = res.body.data
37 for (let video of videos) {
38 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
42 before(async function () {
46 servers = await flushAndRunMultipleServers(2)
48 // Get the access tokens
49 await setAccessTokensToServers(servers)
51 // Server 1 and server 2 follow each other
52 await doubleFollow(servers[0], servers[1])
54 // Upload 2 videos on server 2
55 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
56 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
58 // Wait videos propagation, server 2 has transcoding enabled
59 await waitJobs(servers)
61 // Blacklist the two videos on server 1
62 await blacklistVideosOnServer(servers[0])
65 describe('When listing/searching videos', function () {
67 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
69 const res = await getVideosList(servers[ 0 ].url)
71 expect(res.body.total).to.equal(0)
72 expect(res.body.data).to.be.an('array')
73 expect(res.body.data.length).to.equal(0)
77 const res = await searchVideo(servers[ 0 ].url, 'name')
79 expect(res.body.total).to.equal(0)
80 expect(res.body.data).to.be.an('array')
81 expect(res.body.data.length).to.equal(0)
85 it('Should have the blacklisted video in videos list/search on server 2', async function () {
87 const res = await getVideosList(servers[ 1 ].url)
89 expect(res.body.total).to.equal(2)
90 expect(res.body.data).to.be.an('array')
91 expect(res.body.data.length).to.equal(2)
95 const res = await searchVideo(servers[ 1 ].url, 'video')
97 expect(res.body.total).to.equal(2)
98 expect(res.body.data).to.be.an('array')
99 expect(res.body.data.length).to.equal(2)
104 describe('When listing blacklisted videos', function () {
105 it('Should display all the blacklisted videos', async function () {
106 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
108 expect(res.body.total).to.equal(2)
110 const blacklistedVideos = res.body.data
111 expect(blacklistedVideos).to.be.an('array')
112 expect(blacklistedVideos.length).to.equal(2)
114 for (const blacklistedVideo of blacklistedVideos) {
115 expect(blacklistedVideo.reason).to.equal('super reason')
116 videoId = blacklistedVideo.video.id
120 it('Should get the correct sort when sorting by descending id', async function () {
121 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
122 expect(res.body.total).to.equal(2)
124 const blacklistedVideos = res.body.data
125 expect(blacklistedVideos).to.be.an('array')
126 expect(blacklistedVideos.length).to.equal(2)
128 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
130 expect(blacklistedVideos).to.deep.equal(result)
133 it('Should get the correct sort when sorting by descending video name', async function () {
134 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
135 expect(res.body.total).to.equal(2)
137 const blacklistedVideos = res.body.data
138 expect(blacklistedVideos).to.be.an('array')
139 expect(blacklistedVideos.length).to.equal(2)
141 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
143 expect(blacklistedVideos).to.deep.equal(result)
146 it('Should get the correct sort when sorting by ascending creation date', async function () {
147 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
148 expect(res.body.total).to.equal(2)
150 const blacklistedVideos = res.body.data
151 expect(blacklistedVideos).to.be.an('array')
152 expect(blacklistedVideos.length).to.equal(2)
154 const result = orderBy(res.body.data, [ 'createdAt' ])
156 expect(blacklistedVideos).to.deep.equal(result)
160 describe('When updating blacklisted videos', function () {
161 it('Should change the reason', async function () {
162 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
164 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
165 const video = res.body.data.find(b => b.video.id === videoId)
167 expect(video.reason).to.equal('my super reason updated')
171 describe('When listing my videos', function () {
172 it('Should display blacklisted videos', async function () {
173 await blacklistVideosOnServer(servers[1])
175 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
177 expect(res.body.total).to.equal(2)
178 expect(res.body.data).to.have.lengthOf(2)
180 for (const video of res.body.data) {
181 expect(video.blacklisted).to.be.true
182 expect(video.blacklistedReason).to.equal('super reason')
187 describe('When removing a blacklisted video', function () {
188 let videoToRemove: VideoBlacklist
191 it('Should not have any video in videos list on server 1', async function () {
192 const res = await getVideosList(servers[0].url)
193 expect(res.body.total).to.equal(0)
194 expect(res.body.data).to.be.an('array')
195 expect(res.body.data.length).to.equal(0)
198 it('Should remove a video from the blacklist on server 1', async function () {
199 // Get one video in the blacklist
200 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
201 videoToRemove = res.body.data[0]
202 blacklist = res.body.data.slice(1)
205 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
208 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
209 const res = await getVideosList(servers[0].url)
210 expect(res.body.total).to.equal(1)
212 const videos = res.body.data
213 expect(videos).to.be.an('array')
214 expect(videos.length).to.equal(1)
216 expect(videos[0].name).to.equal(videoToRemove.video.name)
217 expect(videos[0].id).to.equal(videoToRemove.video.id)
220 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
221 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
222 expect(res.body.total).to.equal(1)
224 const videos = res.body.data
225 expect(videos).to.be.an('array')
226 expect(videos.length).to.equal(1)
227 expect(videos).to.deep.equal(blacklist)
231 describe('When blacklisting local videos', function () {
232 let video3UUID: string
233 let video4UUID: string
235 before(async function () {
239 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' })
240 video3UUID = res.body.video.uuid
243 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'Video 4' })
244 video4UUID = res.body.video.uuid
247 await waitJobs(servers)
250 it('Should blacklist video 3 and keep it federated', async function () {
253 await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video3UUID, 'super reason', false)
255 await waitJobs(servers)
258 const res = await getVideosList(servers[ 0 ].url)
259 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined
263 const res = await getVideosList(servers[ 1 ].url)
264 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined
268 it('Should unfederate the video', async function () {
271 await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, 'super reason', true)
273 await waitJobs(servers)
275 for (const server of servers) {
276 const res = await getVideosList(server.url)
277 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
281 it('Should have the video unfederated even after an Update AP message', async function () {
284 await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, { description: 'super description' })
286 await waitJobs(servers)
288 for (const server of servers) {
289 const res = await getVideosList(server.url)
290 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
294 it('Should have the correct video blacklist unfederate attribute', async function () {
295 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
297 const blacklistedVideos: VideoBlacklist[] = res.body.data
298 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
299 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
301 expect(video3Blacklisted.unfederated).to.be.false
302 expect(video4Blacklisted.unfederated).to.be.true
305 it('Should remove the video from blacklist and refederate the video', async function () {
308 await removeVideoFromBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID)
310 await waitJobs(servers)
312 for (const server of servers) {
313 const res = await getVideosList(server.url)
314 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined
320 after(async function () {
321 killallServers(servers)