PeerTube/server/tests/api/video-blacklist.ts

99 lines
2.7 KiB
TypeScript
Raw Normal View History

2017-09-04 14:21:47 -05:00
/* tslint:disable:no-unused-expression */
import * as chai from 'chai'
2017-11-17 05:05:59 -06:00
import 'mocha'
2017-09-04 14:21:47 -05:00
import {
2017-11-17 05:05:59 -06:00
addVideoToBlacklist,
flushAndRunMultipleServers,
2017-09-04 14:21:47 -05:00
flushTests,
getVideosList,
2017-11-17 05:05:59 -06:00
killallServers,
2017-09-04 14:21:47 -05:00
searchVideo,
2017-11-17 05:05:59 -06:00
ServerInfo,
setAccessTokensToServers,
uploadVideo,
wait
2017-09-04 14:21:47 -05:00
} from '../utils'
2017-11-17 05:05:59 -06:00
import { doubleFollow } from '../utils/follows'
const expect = chai.expect
2017-09-04 14:21:47 -05:00
describe('Test video blacklists', function () {
let servers: ServerInfo[] = []
before(async function () {
this.timeout(50000)
2017-09-04 14:21:47 -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-04 14:21:47 -05:00
2017-11-17 05:05:59 -06:00
// Upload a video on server 2
2017-09-04 14:21:47 -05:00
const videoAttributes = {
2017-11-17 05:05:59 -06:00
name: 'my super name for server 2',
description: 'my super description for server 2'
2017-09-04 14:21:47 -05:00
}
await uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes)
// Wait videos propagation, server 2 has transcoding enabled
await wait(10000)
2017-09-04 14:21:47 -05:00
const res = await getVideosList(servers[0].url)
const videos = res.body.data
expect(videos.length).to.equal(1)
2017-11-17 05:05:59 -06:00
servers[0].remoteVideo = videos.find(video => video.name === 'my super name for server 2')
2017-09-04 14:21:47 -05:00
})
2017-11-17 05:05:59 -06:00
it('Should blacklist a remote video on server 1', async function () {
2017-09-04 14:21:47 -05:00
await addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id)
})
2017-11-17 05:05:59 -06:00
it('Should not have the video blacklisted in videos list on server 1', async function () {
2017-09-04 14:21:47 -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 not have the video blacklisted in videos search on server 1', async function () {
2017-09-04 14:21:47 -05:00
const res = await searchVideo(servers[0].url, 'name')
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 have the blacklisted video in videos list on server 2', async function () {
2017-09-04 14:21:47 -05:00
const res = await getVideosList(servers[1].url)
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(1)
})
2017-11-17 05:05:59 -06:00
it('Should have the video blacklisted in videos search on server 2', async function () {
2017-09-04 14:21:47 -05:00
const res = await searchVideo(servers[1].url, 'name')
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(1)
})
after(async function () {
killallServers(servers)
// Keep the logs if the test failed
if (this['ok']) {
await flushTests()
}
})
})