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,
16 setAccessTokensToServers,
19 } from '../../../../shared/utils/index'
20 import { doubleFollow } from '../../../../shared/utils/server/follows'
21 import { waitJobs } from '../../../../shared/utils/server/jobs'
22 import { VideoAbuse } from '../../../../shared/models/videos'
24 const expect = chai.expect
26 describe('Test video blacklist management', function () {
27 let servers: ServerInfo[] = []
30 async function blacklistVideosOnServer (server: ServerInfo) {
31 const res = await getVideosList(server.url)
33 const videos = res.body.data
34 for (let video of videos) {
35 await addVideoToBlacklist(server.url, server.accessToken, video.id, 'super reason')
39 before(async function () {
43 servers = await flushAndRunMultipleServers(2)
45 // Get the access tokens
46 await setAccessTokensToServers(servers)
48 // Server 1 and server 2 follow each other
49 await doubleFollow(servers[0], servers[1])
51 // Upload 2 videos on server 2
52 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
53 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
55 // Wait videos propagation, server 2 has transcoding enabled
56 await waitJobs(servers)
58 // Blacklist the two videos on server 1
59 await blacklistVideosOnServer(servers[0])
62 describe('When listing blacklisted videos', function () {
63 it('Should display all the blacklisted videos', async function () {
64 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
66 expect(res.body.total).to.equal(2)
68 const blacklistedVideos = res.body.data
69 expect(blacklistedVideos).to.be.an('array')
70 expect(blacklistedVideos.length).to.equal(2)
72 for (const blacklistedVideo of blacklistedVideos) {
73 expect(blacklistedVideo.reason).to.equal('super reason')
74 videoId = blacklistedVideo.video.id
78 it('Should get the correct sort when sorting by descending id', async function () {
79 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
80 expect(res.body.total).to.equal(2)
82 const blacklistedVideos = res.body.data
83 expect(blacklistedVideos).to.be.an('array')
84 expect(blacklistedVideos.length).to.equal(2)
86 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
88 expect(blacklistedVideos).to.deep.equal(result)
91 it('Should get the correct sort when sorting by descending video name', async function () {
92 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
93 expect(res.body.total).to.equal(2)
95 const blacklistedVideos = res.body.data
96 expect(blacklistedVideos).to.be.an('array')
97 expect(blacklistedVideos.length).to.equal(2)
99 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
101 expect(blacklistedVideos).to.deep.equal(result)
104 it('Should get the correct sort when sorting by ascending creation date', async function () {
105 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
106 expect(res.body.total).to.equal(2)
108 const blacklistedVideos = res.body.data
109 expect(blacklistedVideos).to.be.an('array')
110 expect(blacklistedVideos.length).to.equal(2)
112 const result = orderBy(res.body.data, [ 'createdAt' ])
114 expect(blacklistedVideos).to.deep.equal(result)
118 describe('When updating blacklisted videos', function () {
119 it('Should change the reason', async function () {
120 await updateVideoBlacklist(servers[0].url, servers[0].accessToken, videoId, 'my super reason updated')
122 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
123 const video = res.body.data.find(b => b.video.id === videoId)
125 expect(video.reason).to.equal('my super reason updated')
129 describe('When listing my videos', function () {
130 it('Should display blacklisted videos', async function () {
131 await blacklistVideosOnServer(servers[1])
133 const res = await getMyVideos(servers[1].url, servers[1].accessToken, 0, 5)
135 expect(res.body.total).to.equal(2)
136 expect(res.body.data).to.have.lengthOf(2)
138 for (const video of res.body.data) {
139 expect(video.blacklisted).to.be.true
140 expect(video.blacklistedReason).to.equal('super reason')
145 describe('When removing a blacklisted video', function () {
146 let videoToRemove: VideoAbuse
149 it('Should not have any video in videos list on server 1', async function () {
150 const res = await getVideosList(servers[0].url)
151 expect(res.body.total).to.equal(0)
152 expect(res.body.data).to.be.an('array')
153 expect(res.body.data.length).to.equal(0)
156 it('Should remove a video from the blacklist on server 1', async function () {
157 // Get one video in the blacklist
158 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
159 videoToRemove = res.body.data[0]
160 blacklist = res.body.data.slice(1)
163 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.video.id)
166 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
167 const res = await getVideosList(servers[0].url)
168 expect(res.body.total).to.equal(1)
170 const videos = res.body.data
171 expect(videos).to.be.an('array')
172 expect(videos.length).to.equal(1)
174 expect(videos[0].name).to.equal(videoToRemove.video.name)
175 expect(videos[0].id).to.equal(videoToRemove.video.id)
178 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
179 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
180 expect(res.body.total).to.equal(1)
182 const videos = res.body.data
183 expect(videos).to.be.an('array')
184 expect(videos.length).to.equal(1)
185 expect(videos).to.deep.equal(blacklist)
189 after(async function () {
190 killallServers(servers)