1 /* tslint:disable:no-unused-expressions */
3 import * as chai from 'chai'
4 import * as lodash from 'lodash'
8 flushAndRunMultipleServers,
10 getBlacklistedVideosList,
11 getSortedBlacklistedVideosList,
14 removeVideoFromBlacklist,
16 setAccessTokensToServers,
19 } from '../../utils/index'
20 import { doubleFollow } from '../../utils/server/follows'
22 const expect = chai.expect
23 const orderBy = lodash.orderBy
25 describe('Test video blacklist management', function () {
26 let servers: ServerInfo[] = []
28 async function blacklistVideosOnServer (server: ServerInfo) {
29 const res = await getVideosList(server.url)
31 const videos = res.body.data
32 for (let video of videos) {
33 await addVideoToBlacklist(server.url, server.accessToken, video.id)
37 before(async function () {
41 servers = await flushAndRunMultipleServers(2)
43 // Get the access tokens
44 await setAccessTokensToServers(servers)
46 // Server 1 and server 2 follow each other
47 await doubleFollow(servers[0], servers[1])
49 // Upload 2 videos on server 2
50 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
51 await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
53 // Wait videos propagation, server 2 has transcoding enabled
56 // Blacklist the two videos on server 1
57 await blacklistVideosOnServer(servers[0])
60 describe('When listing blacklisted videos', function () {
61 it('Should display all the blacklisted videos', async function () {
62 const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
64 expect(res.body.total).to.equal(2)
66 const videos = res.body.data
67 expect(videos).to.be.an('array')
68 expect(videos.length).to.equal(2)
71 it('Should get the correct sort when sorting by descending id', async function () {
72 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
73 expect(res.body.total).to.equal(2)
75 const videos = res.body.data
76 expect(videos).to.be.an('array')
77 expect(videos.length).to.equal(2)
79 const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
81 expect(videos).to.deep.equal(result)
84 it('Should get the correct sort when sorting by descending video name', async function () {
85 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
86 expect(res.body.total).to.equal(2)
88 const videos = res.body.data
89 expect(videos).to.be.an('array')
90 expect(videos.length).to.equal(2)
92 const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
94 expect(videos).to.deep.equal(result)
97 it('Should get the correct sort when sorting by ascending creation date', async function () {
98 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
99 expect(res.body.total).to.equal(2)
101 const videos = res.body.data
102 expect(videos).to.be.an('array')
103 expect(videos.length).to.equal(2)
105 const result = orderBy(res.body.data, [ 'createdAt' ])
107 expect(videos).to.deep.equal(result)
111 describe('When removing a blacklisted video', function () {
115 it('Should not have any video in videos list on server 1', async function () {
116 const res = await getVideosList(servers[0].url)
117 expect(res.body.total).to.equal(0)
118 expect(res.body.data).to.be.an('array')
119 expect(res.body.data.length).to.equal(0)
122 it('Should remove a video from the blacklist on server 1', async function () {
123 // Get one video in the blacklist
124 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
125 videoToRemove = res.body.data[0]
126 blacklist = res.body.data.slice(1)
129 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId)
132 it('Should have the ex-blacklisted video in videos list on server 1', async function () {
133 const res = await getVideosList(servers[0].url)
134 expect(res.body.total).to.equal(1)
136 const videos = res.body.data
137 expect(videos).to.be.an('array')
138 expect(videos.length).to.equal(1)
140 expect(videos[0].name).to.equal(videoToRemove.name)
141 expect(videos[0].id).to.equal(videoToRemove.videoId)
144 it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
145 const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
146 expect(res.body.total).to.equal(1)
148 const videos = res.body.data
149 expect(videos).to.be.an('array')
150 expect(videos.length).to.equal(1)
151 expect(videos).to.deep.equal(blacklist)
155 after(async function () {
156 killallServers(servers)