1 /* tslint:disable:no-unused-expressions */
3 import * as chai from 'chai'
4 import * as lodash from 'lodash'
8 flushAndRunMultipleServers,
9 getBlacklistedVideosList,
10 getSortedBlacklistedVideosList,
13 removeVideoFromBlacklist,
15 setAccessTokensToServers,
17 } from '../../utils/index'
18 import { doubleFollow } from '../../utils/server/follows'
19 import { waitJobs } from '../../utils/server/jobs'
21 const expect = chai.expect
22 const orderBy = lodash.orderBy
24 describe('Test video blacklist management', function () {
25 let servers: ServerInfo[] = []
27 async function blacklistVideosOnServer (server: ServerInfo) {
28 const res = await getVideosList(server.url)
30 const videos = res.body.data
31 for (let video of videos) {
32 await addVideoToBlacklist(server.url, server.accessToken, video.id)
36 before(async function () {
40 servers = await flushAndRunMultipleServers(2)
42 // Get the access tokens
43 await setAccessTokensToServers(servers)
45 // Server 1 and server 2 follow each other
46 await doubleFollow(servers[0], servers[1])
48 // Upload 2 videos on server 2
49 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
50 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
52 // Wait videos propagation, server 2 has transcoding enabled
53 await waitJobs(servers)
55 // Blacklist the two videos on server 1
56 await blacklistVideosOnServer(servers[0])
59 describe('When listing blacklisted videos', function () {
60 it('Should display all the blacklisted videos', async function () {
61 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
63 expect(res.body.total).to.equal(2)
65 const videos = res.body.data
66 expect(videos).to.be.an('array')
67 expect(videos.length).to.equal(2)
70 it('Should get the correct sort when sorting by descending id', async function () {
71 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
72 expect(res.body.total).to.equal(2)
74 const videos = res.body.data
75 expect(videos).to.be.an('array')
76 expect(videos.length).to.equal(2)
78 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
80 expect(videos).to.deep.equal(result)
83 it('Should get the correct sort when sorting by descending video name', async function () {
84 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
85 expect(res.body.total).to.equal(2)
87 const videos = res.body.data
88 expect(videos).to.be.an('array')
89 expect(videos.length).to.equal(2)
91 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
93 expect(videos).to.deep.equal(result)
96 it('Should get the correct sort when sorting by ascending creation date', async function () {
97 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
98 expect(res.body.total).to.equal(2)
100 const videos = res.body.data
101 expect(videos).to.be.an('array')
102 expect(videos.length).to.equal(2)
104 const result = orderBy(res.body.data, [ 'createdAt' ])
106 expect(videos).to.deep.equal(result)
110 describe('When removing a blacklisted video', function () {
114 it('Should not have any video in videos list on server 1', async function () {
115 const res = await getVideosList(servers[0].url)
116 expect(res.body.total).to.equal(0)
117 expect(res.body.data).to.be.an('array')
118 expect(res.body.data.length).to.equal(0)
121 it('Should remove a video from the blacklist on server 1', async function () {
122 // Get one video in the blacklist
123 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
124 videoToRemove = res.body.data[0]
125 blacklist = res.body.data.slice(1)
128 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId)
131 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
132 const res = await getVideosList(servers[0].url)
133 expect(res.body.total).to.equal(1)
135 const videos = res.body.data
136 expect(videos).to.be.an('array')
137 expect(videos.length).to.equal(1)
139 expect(videos[0].name).to.equal(videoToRemove.name)
140 expect(videos[0].id).to.equal(videoToRemove.videoId)
143 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
144 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
145 expect(res.body.total).to.equal(1)
147 const videos = res.body.data
148 expect(videos).to.be.an('array')
149 expect(videos.length).to.equal(1)
150 expect(videos).to.deep.equal(blacklist)
154 after(async function () {
155 killallServers(servers)