1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import { orderBy } from 'lodash'
8 flushAndRunMultipleServers,
9 getBlacklistedVideosList,
10 getBlacklistedVideosListWithTypeFilter,
12 getSortedBlacklistedVideosList,
15 removeVideoFromBlacklist,
18 setAccessTokensToServers,
23 } from '../../../../shared/utils/index'
24 import { doubleFollow } from '../../../../shared/utils/server/follows'
25 import { waitJobs } from '../../../../shared/utils/server/jobs'
26 import { VideoBlacklist, VideoBlacklistType } from '../../../../shared/models/videos'
28 const expect = chai.expect
30 describe('Test video blacklist management', function () {
31 let servers: ServerInfo[] = []
34 async function blacklistVideosOnServer (server: ServerInfo) {
35 const res = await getVideosList(server.url)
37 const videos = res.body.data
38 for (let video of videos) {
39 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
43 before(async function () {
47 servers = await flushAndRunMultipleServers(2)
49 // Get the access tokens
50 await setAccessTokensToServers(servers)
52 // Server 1 and server 2 follow each other
53 await doubleFollow(servers[0], servers[1])
55 // Upload 2 videos on server 2
56 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
57 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
59 // Wait videos propagation, server 2 has transcoding enabled
60 await waitJobs(servers)
62 // Blacklist the two videos on server 1
63 await blacklistVideosOnServer(servers[0])
66 describe('When listing/searching videos', function () {
68 it('Should not have the video blacklisted in videos list/search on server 1', async function () {
70 const res = await getVideosList(servers[ 0 ].url)
72 expect(res.body.total).to.equal(0)
73 expect(res.body.data).to.be.an('array')
74 expect(res.body.data.length).to.equal(0)
78 const res = await searchVideo(servers[ 0 ].url, 'name')
80 expect(res.body.total).to.equal(0)
81 expect(res.body.data).to.be.an('array')
82 expect(res.body.data.length).to.equal(0)
86 it('Should have the blacklisted video in videos list/search on server 2', async function () {
88 const res = await getVideosList(servers[ 1 ].url)
90 expect(res.body.total).to.equal(2)
91 expect(res.body.data).to.be.an('array')
92 expect(res.body.data.length).to.equal(2)
96 const res = await searchVideo(servers[ 1 ].url, 'video')
98 expect(res.body.total).to.equal(2)
99 expect(res.body.data).to.be.an('array')
100 expect(res.body.data.length).to.equal(2)
105 describe('When listing manually blacklisted videos', function () {
106 it('Should display all the blacklisted videos', async function () {
107 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
109 expect(res.body.total).to.equal(2)
111 const blacklistedVideos = res.body.data
112 expect(blacklistedVideos).to.be.an('array')
113 expect(blacklistedVideos.length).to.equal(2)
115 for (const blacklistedVideo of blacklistedVideos) {
116 expect(blacklistedVideo.reason).to.equal('super reason')
117 videoId = blacklistedVideo.video.id
121 it('Should display all the blacklisted videos when applying manual type filter', async function () {
122 const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.MANUAL)
124 expect(res.body.total).to.equal(2)
126 const blacklistedVideos = res.body.data
127 expect(blacklistedVideos).to.be.an('array')
128 expect(blacklistedVideos.length).to.equal(2)
131 it('Should display nothing when applying automatic type filter', async function () {
132 const res = await getBlacklistedVideosListWithTypeFilter(servers[0].url, servers[0].accessToken, VideoBlacklistType.AUTO_BEFORE_PUBLISHED) // tslint:disable:max-line-length
134 expect(res.body.total).to.equal(0)
136 const blacklistedVideos = res.body.data
137 expect(blacklistedVideos).to.be.an('array')
138 expect(blacklistedVideos.length).to.equal(0)
141 it('Should get the correct sort when sorting by descending id', async function () {
142 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
143 expect(res.body.total).to.equal(2)
145 const blacklistedVideos = res.body.data
146 expect(blacklistedVideos).to.be.an('array')
147 expect(blacklistedVideos.length).to.equal(2)
149 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
151 expect(blacklistedVideos).to.deep.equal(result)
154 it('Should get the correct sort when sorting by descending video name', async function () {
155 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
156 expect(res.body.total).to.equal(2)
158 const blacklistedVideos = res.body.data
159 expect(blacklistedVideos).to.be.an('array')
160 expect(blacklistedVideos.length).to.equal(2)
162 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
164 expect(blacklistedVideos).to.deep.equal(result)
167 it('Should get the correct sort when sorting by ascending creation date', async function () {
168 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
169 expect(res.body.total).to.equal(2)
171 const blacklistedVideos = res.body.data
172 expect(blacklistedVideos).to.be.an('array')
173 expect(blacklistedVideos.length).to.equal(2)
175 const result = orderBy(res.body.data, [ 'createdAt' ])
177 expect(blacklistedVideos).to.deep.equal(result)
181 describe('When updating blacklisted videos', function () {
182 it('Should change the reason', async function () {
183 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
185 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
186 const video = res.body.data.find(b => b.video.id === videoId)
188 expect(video.reason).to.equal('my super reason updated')
192 describe('When listing my videos', function () {
193 it('Should display blacklisted videos', async function () {
194 await blacklistVideosOnServer(servers[1])
196 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
198 expect(res.body.total).to.equal(2)
199 expect(res.body.data).to.have.lengthOf(2)
201 for (const video of res.body.data) {
202 expect(video.blacklisted).to.be.true
203 expect(video.blacklistedReason).to.equal('super reason')
208 describe('When removing a blacklisted video', function () {
209 let videoToRemove: VideoBlacklist
212 it('Should not have any video in videos list on server 1', async function () {
213 const res = await getVideosList(servers[0].url)
214 expect(res.body.total).to.equal(0)
215 expect(res.body.data).to.be.an('array')
216 expect(res.body.data.length).to.equal(0)
219 it('Should remove a video from the blacklist on server 1', async function () {
220 // Get one video in the blacklist
221 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
222 videoToRemove = res.body.data[0]
223 blacklist = res.body.data.slice(1)
226 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
229 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
230 const res = await getVideosList(servers[0].url)
231 expect(res.body.total).to.equal(1)
233 const videos = res.body.data
234 expect(videos).to.be.an('array')
235 expect(videos.length).to.equal(1)
237 expect(videos[0].name).to.equal(videoToRemove.video.name)
238 expect(videos[0].id).to.equal(videoToRemove.video.id)
241 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
242 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
243 expect(res.body.total).to.equal(1)
245 const videos = res.body.data
246 expect(videos).to.be.an('array')
247 expect(videos.length).to.equal(1)
248 expect(videos).to.deep.equal(blacklist)
252 describe('When blacklisting local videos', function () {
253 let video3UUID: string
254 let video4UUID: string
256 before(async function () {
260 const res = await uploadVideo(servers[0].url, servers[0].accessToken, { name: 'Video 3' })
261 video3UUID = res.body.video.uuid
264 const res = await uploadVideo(servers[ 0 ].url, servers[ 0 ].accessToken, { name: 'Video 4' })
265 video4UUID = res.body.video.uuid
268 await waitJobs(servers)
271 it('Should blacklist video 3 and keep it federated', async function () {
274 await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video3UUID, 'super reason', false)
276 await waitJobs(servers)
279 const res = await getVideosList(servers[ 0 ].url)
280 expect(res.body.data.find(v => v.uuid === video3UUID)).to.be.undefined
284 const res = await getVideosList(servers[ 1 ].url)
285 expect(res.body.data.find(v => v.uuid === video3UUID)).to.not.be.undefined
289 it('Should unfederate the video', async function () {
292 await addVideoToBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, 'super reason', true)
294 await waitJobs(servers)
296 for (const server of servers) {
297 const res = await getVideosList(server.url)
298 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
302 it('Should have the video unfederated even after an Update AP message', async function () {
305 await updateVideo(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID, { description: 'super description' })
307 await waitJobs(servers)
309 for (const server of servers) {
310 const res = await getVideosList(server.url)
311 expect(res.body.data.find(v => v.uuid === video4UUID)).to.be.undefined
315 it('Should have the correct video blacklist unfederate attribute', async function () {
316 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
318 const blacklistedVideos: VideoBlacklist[] = res.body.data
319 const video3Blacklisted = blacklistedVideos.find(b => b.video.uuid === video3UUID)
320 const video4Blacklisted = blacklistedVideos.find(b => b.video.uuid === video4UUID)
322 expect(video3Blacklisted.unfederated).to.be.false
323 expect(video4Blacklisted.unfederated).to.be.true
326 it('Should remove the video from blacklist and refederate the video', async function () {
329 await removeVideoFromBlacklist(servers[ 0 ].url, servers[ 0 ].accessToken, video4UUID)
331 await waitJobs(servers)
333 for (const server of servers) {
334 const res = await getVideosList(server.url)
335 expect(res.body.data.find(v => v.uuid === video4UUID)).to.not.be.undefined
341 after(async function () {
342 killallServers(servers)