2017-09-22 02:13:43 -05:00
|
|
|
/* tslint:disable:no-unused-expressions */
|
|
|
|
|
|
|
|
import * as chai from 'chai'
|
|
|
|
import * as lodash from 'lodash'
|
2017-11-17 05:05:59 -06:00
|
|
|
import 'mocha'
|
2017-09-22 02:13:43 -05:00
|
|
|
import {
|
2017-11-17 05:05:59 -06:00
|
|
|
addVideoToBlacklist,
|
2017-09-22 02:13:43 -05:00
|
|
|
flushAndRunMultipleServers,
|
2017-11-17 05:05:59 -06:00
|
|
|
getBlacklistedVideosList,
|
|
|
|
getSortedBlacklistedVideosList,
|
2017-09-22 02:13:43 -05:00
|
|
|
getVideosList,
|
2017-11-17 05:05:59 -06:00
|
|
|
killallServers,
|
2017-09-22 02:13:43 -05:00
|
|
|
removeVideoFromBlacklist,
|
2017-11-17 05:05:59 -06:00
|
|
|
ServerInfo,
|
|
|
|
setAccessTokensToServers,
|
2018-06-13 03:06:50 -05:00
|
|
|
uploadVideo
|
2017-12-28 06:59:22 -06:00
|
|
|
} from '../../utils/index'
|
|
|
|
import { doubleFollow } from '../../utils/server/follows'
|
2018-06-13 03:06:50 -05:00
|
|
|
import { waitJobs } from '../../utils/server/jobs'
|
2017-11-17 05:05:59 -06:00
|
|
|
|
|
|
|
const expect = chai.expect
|
|
|
|
const orderBy = lodash.orderBy
|
2017-09-22 02:13:43 -05:00
|
|
|
|
|
|
|
describe('Test video blacklist management', function () {
|
|
|
|
let servers: ServerInfo[] = []
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
async function blacklistVideosOnServer (server: ServerInfo) {
|
2017-09-22 02:13:43 -05:00
|
|
|
const res = await getVideosList(server.url)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
for (let video of videos) {
|
|
|
|
await addVideoToBlacklist(server.url, server.accessToken, video.id)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
before(async function () {
|
2017-11-17 08:42:12 -06:00
|
|
|
this.timeout(50000)
|
2017-09-22 02:13:43 -05:00
|
|
|
|
|
|
|
// Run servers
|
|
|
|
servers = await flushAndRunMultipleServers(2)
|
|
|
|
|
|
|
|
// Get the access tokens
|
|
|
|
await setAccessTokensToServers(servers)
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
// Server 1 and server 2 follow each other
|
|
|
|
await doubleFollow(servers[0], servers[1])
|
2017-09-22 02:13:43 -05:00
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
// Upload 2 videos on server 2
|
|
|
|
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 1st video', description: 'A video on server 2' })
|
|
|
|
await uploadVideo(servers[1].url, servers[1].accessToken, { name: 'My 2nd video', description: 'A video on server 2' })
|
2017-09-22 02:13:43 -05:00
|
|
|
|
2017-11-17 08:42:12 -06:00
|
|
|
// Wait videos propagation, server 2 has transcoding enabled
|
2018-06-13 03:06:50 -05:00
|
|
|
await waitJobs(servers)
|
2017-09-22 02:13:43 -05:00
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
// Blacklist the two videos on server 1
|
|
|
|
await blacklistVideosOnServer(servers[0])
|
2017-09-22 02:13:43 -05:00
|
|
|
})
|
|
|
|
|
|
|
|
describe('When listing blacklisted videos', function () {
|
|
|
|
it('Should display all the blacklisted videos', async function () {
|
|
|
|
const res = await getBlacklistedVideosList(servers[0].url, servers[0].accessToken)
|
|
|
|
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.be.an('array')
|
|
|
|
expect(videos.length).to.equal(2)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get the correct sort when sorting by descending id', async function () {
|
|
|
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-id')
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.be.an('array')
|
|
|
|
expect(videos.length).to.equal(2)
|
|
|
|
|
|
|
|
const result = orderBy(res.body.data, [ 'id' ], [ 'desc' ])
|
|
|
|
|
|
|
|
expect(videos).to.deep.equal(result)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get the correct sort when sorting by descending video name', async function () {
|
|
|
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.be.an('array')
|
|
|
|
expect(videos.length).to.equal(2)
|
|
|
|
|
|
|
|
const result = orderBy(res.body.data, [ 'name' ], [ 'desc' ])
|
|
|
|
|
|
|
|
expect(videos).to.deep.equal(result)
|
|
|
|
})
|
|
|
|
|
|
|
|
it('Should get the correct sort when sorting by ascending creation date', async function () {
|
|
|
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, 'createdAt')
|
|
|
|
expect(res.body.total).to.equal(2)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.be.an('array')
|
|
|
|
expect(videos.length).to.equal(2)
|
|
|
|
|
|
|
|
const result = orderBy(res.body.data, [ 'createdAt' ])
|
|
|
|
|
|
|
|
expect(videos).to.deep.equal(result)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
describe('When removing a blacklisted video', function () {
|
|
|
|
let videoToRemove
|
|
|
|
let blacklist = []
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should not have any video in videos list on server 1', async function () {
|
2017-09-22 02:13:43 -05:00
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(0)
|
|
|
|
expect(res.body.data).to.be.an('array')
|
|
|
|
expect(res.body.data.length).to.equal(0)
|
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should remove a video from the blacklist on server 1', async function () {
|
2017-09-22 02:13:43 -05:00
|
|
|
// Get one video in the blacklist
|
|
|
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
|
|
videoToRemove = res.body.data[0]
|
|
|
|
blacklist = res.body.data.slice(1)
|
|
|
|
|
|
|
|
// Remove it
|
|
|
|
await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, videoToRemove.videoId)
|
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should have the ex-blacklisted video in videos list on server 1', async function () {
|
2017-09-22 02:13:43 -05:00
|
|
|
const res = await getVideosList(servers[0].url)
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.be.an('array')
|
|
|
|
expect(videos.length).to.equal(1)
|
|
|
|
|
|
|
|
expect(videos[0].name).to.equal(videoToRemove.name)
|
|
|
|
expect(videos[0].id).to.equal(videoToRemove.videoId)
|
|
|
|
})
|
|
|
|
|
2017-11-17 05:05:59 -06:00
|
|
|
it('Should not have the ex-blacklisted video in videos blacklist list on server 1', async function () {
|
2017-09-22 02:13:43 -05:00
|
|
|
const res = await getSortedBlacklistedVideosList(servers[0].url, servers[0].accessToken, '-name')
|
|
|
|
expect(res.body.total).to.equal(1)
|
|
|
|
|
|
|
|
const videos = res.body.data
|
|
|
|
expect(videos).to.be.an('array')
|
|
|
|
expect(videos.length).to.equal(1)
|
|
|
|
expect(videos).to.deep.equal(blacklist)
|
|
|
|
})
|
|
|
|
})
|
|
|
|
|
|
|
|
after(async function () {
|
|
|
|
killallServers(servers)
|
|
|
|
})
|
|
|
|
})
|