1 /* tslint:disable:no-unused-expression */
3 import * as chai from 'chai'
4 import * as lodash from 'lodash'
8 flushAndRunMultipleServers,
9 getBlacklistedVideosList,
11 getSortedBlacklistedVideosList,
14 removeVideoFromBlacklist,
16 setAccessTokensToServers,
19 } from '../../utils/index'
20 import { doubleFollow } from '../../utils/server/follows'
21 import { waitJobs } from '../../utils/server/jobs'
22 import { VideoAbuse } from '../../../../shared/models/videos'
24 const expect = chai.expect
25 const orderBy = lodash.orderBy
27 describe('Test video blacklist management', function () {
28 let servers: ServerInfo[] = []
31 async function blacklistVideosOnServer (server: ServerInfo) {
32 const res = await getVideosList(server.url)
34 const videos = res.body.data
35 for (let video of videos) {
36 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
40 before(async function () {
44 servers = await flushAndRunMultipleServers(2)
46 // Get the access tokens
47 await setAccessTokensToServers(servers)
49 // Server 1 and server 2 follow each other
50 await doubleFollow(servers[0], servers[1])
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' })
56 // Wait videos propagation, server 2 has transcoding enabled
57 await waitJobs(servers)
59 // Blacklist the two videos on server 1
60 await blacklistVideosOnServer(servers[0])
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)
67 expect(res.body.total).to.equal(2)
69 const blacklistedVideos = res.body.data
70 expect(blacklistedVideos).to.be.an('array')
71 expect(blacklistedVideos.length).to.equal(2)
73 for (const blacklistedVideo of blacklistedVideos) {
74 expect(blacklistedVideo.reason).to.equal('super reason')
75 videoId = blacklistedVideo.video.id
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)
83 const blacklistedVideos = res.body.data
84 expect(blacklistedVideos).to.be.an('array')
85 expect(blacklistedVideos.length).to.equal(2)
87 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
89 expect(blacklistedVideos).to.deep.equal(result)
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)
96 const blacklistedVideos = res.body.data
97 expect(blacklistedVideos).to.be.an('array')
98 expect(blacklistedVideos.length).to.equal(2)
100 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
102 expect(blacklistedVideos).to.deep.equal(result)
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)
109 const blacklistedVideos = res.body.data
110 expect(blacklistedVideos).to.be.an('array')
111 expect(blacklistedVideos.length).to.equal(2)
113 const result = orderBy(res.body.data, [ 'createdAt' ])
115 expect(blacklistedVideos).to.deep.equal(result)
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')
123 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
124 const video = res.body.data.find(b => b.video.id === videoId)
126 expect(video.reason).to.equal('my super reason updated')
130 describe('When listing my videos', function () {
131 it('Should display blacklisted videos', async function () {
132 await blacklistVideosOnServer(servers[1])
134 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
136 expect(res.body.total).to.equal(2)
137 expect(res.body.data).to.have.lengthOf(2)
139 for (const video of res.body.data) {
140 expect(video.blacklisted).to.be.true
141 expect(video.blacklistedReason).to.equal('super reason')
146 describe('When removing a blacklisted video', function () {
147 let videoToRemove: VideoAbuse
150 it('Should not have any video in videos list on server 1', async function () {
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)
157 it('Should remove a video from the blacklist on server 1', async function () {
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)
164 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
167 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
168 const res = await getVideosList(servers[0].url)
169 expect(res.body.total).to.equal(1)
171 const videos = res.body.data
172 expect(videos).to.be.an('array')
173 expect(videos.length).to.equal(1)
175 expect(videos[0].name).to.equal(videoToRemove.video.name)
176 expect(videos[0].id).to.equal(videoToRemove.video.id)
179 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
180 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
181 expect(res.body.total).to.equal(1)
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)
190 after(async function () {
191 killallServers(servers)