Server: add tests for video blacklists

This commit is contained in:
Chocobozzz 2017-05-01 19:04:29 +02:00
parent 3eeeb87fe6
commit 843aa7ba03
8 changed files with 300 additions and 7 deletions

View File

@ -7,3 +7,4 @@ require('./users')
require('./requests') require('./requests')
require('./videos') require('./videos')
require('./video-abuses') require('./video-abuses')
require('./video-blacklists')

View File

@ -129,7 +129,7 @@ describe('Test video abuses API validators', function () {
const basePath = '/api/v1/videos/' const basePath = '/api/v1/videos/'
it('Should fail with nothing', function (done) { it('Should fail with nothing', function (done) {
const path = basePath + server.video + '/abuse' const path = basePath + server.video.id + '/abuse'
const data = {} const data = {}
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
}) })
@ -142,7 +142,7 @@ describe('Test video abuses API validators', function () {
it('Should fail with a non authenticated user', function (done) { it('Should fail with a non authenticated user', function (done) {
const data = {} const data = {}
const path = basePath + server.video + '/abuse' const path = basePath + server.video.id + '/abuse'
requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401) requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
}) })
@ -150,7 +150,7 @@ describe('Test video abuses API validators', function () {
const data = { const data = {
reason: 'h' reason: 'h'
} }
const path = basePath + server.video + '/abuse' const path = basePath + server.video.id + '/abuse'
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
}) })
@ -161,7 +161,7 @@ describe('Test video abuses API validators', function () {
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' + '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' '0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
} }
const path = basePath + server.video + '/abuse' const path = basePath + server.video.id + '/abuse'
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done) requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
}) })
}) })

View File

@ -0,0 +1,123 @@
/* eslint-disable no-unused-expressions */
'use strict'
const series = require('async/series')
const loginUtils = require('../../utils/login')
const requestsUtils = require('../../utils/requests')
const serversUtils = require('../../utils/servers')
const usersUtils = require('../../utils/users')
const videosUtils = require('../../utils/videos')
describe('Test video blacklists API validators', function () {
let server = null
let userAccessToken = null
// ---------------------------------------------------------------
before(function (done) {
this.timeout(20000)
series([
function (next) {
serversUtils.flushTests(next)
},
function (next) {
serversUtils.runServer(1, function (server1) {
server = server1
next()
})
},
function (next) {
loginUtils.loginAndGetAccessToken(server, function (err, token) {
if (err) throw err
server.accessToken = token
next()
})
},
function (next) {
const username = 'user1'
const password = 'my super password'
usersUtils.createUser(server.url, server.accessToken, username, password, next)
},
function (next) {
const user = {
username: 'user1',
password: 'my super password'
}
loginUtils.getUserAccessToken(server, user, function (err, accessToken) {
if (err) throw err
userAccessToken = accessToken
next()
})
},
// Upload a video
function (next) {
const videoAttributes = {}
videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, next)
},
function (next) {
videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err
const videos = res.body.data
server.video = videos[0]
next()
})
}
], done)
})
describe('When adding a video in blacklist', function () {
const basePath = '/api/v1/videos/'
it('Should fail with nothing', function (done) {
const path = basePath + server.video + '/blacklist'
const data = {}
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
})
it('Should fail with a wrong video', function (done) {
const wrongPath = '/api/v1/videos/blabla/blacklist'
const data = {}
requestsUtils.makePostBodyRequest(server.url, wrongPath, server.accessToken, data, done)
})
it('Should fail with a non authenticated user', function (done) {
const data = {}
const path = basePath + server.video + '/blacklist'
requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
})
it('Should fail with a non admin user', function (done) {
const data = {}
const path = basePath + server.video + '/blacklist'
requestsUtils.makePostBodyRequest(server.url, path, userAccessToken, data, done, 403)
})
it('Should fail with a local video', function (done) {
const data = {}
const path = basePath + server.video.id + '/blacklist'
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done, 403)
})
})
after(function (done) {
process.kill(-server.app.pid)
// Keep the logs if the test failed
if (this.ok) {
serversUtils.flushTests(done)
} else {
done()
}
})
})

View File

@ -6,6 +6,8 @@ require('./check-params')
require('./friends-basic') require('./friends-basic')
require('./users') require('./users')
require('./single-pod') require('./single-pod')
require('./video-abuse')
require('./video-blacklist')
require('./multiple-pods') require('./multiple-pods')
require('./requests') require('./requests')
require('./friends-advanced') require('./friends-advanced')

View File

@ -38,7 +38,7 @@ describe('Test video abuses', function () {
}) })
}, next) }, next)
}, },
// Pod 1 make friends too // Pod 1 makes friend with pod 2
function (next) { function (next) {
const server = servers[0] const server = servers[0]
podsUtils.makeFriends(server.url, server.accessToken, next) podsUtils.makeFriends(server.url, server.accessToken, next)

View File

@ -0,0 +1,138 @@
/* eslint-disable no-unused-expressions */
'use strict'
const chai = require('chai')
const each = require('async/each')
const expect = chai.expect
const series = require('async/series')
const loginUtils = require('../utils/login')
const podsUtils = require('../utils/pods')
const serversUtils = require('../utils/servers')
const videosUtils = require('../utils/videos')
const videoBlacklistsUtils = require('../utils/video-blacklists')
describe('Test video blacklists', function () {
let servers = []
before(function (done) {
this.timeout(30000)
series([
// Run servers
function (next) {
serversUtils.flushAndRunMultipleServers(2, function (serversRun) {
servers = serversRun
next()
})
},
// Get the access tokens
function (next) {
each(servers, function (server, callbackEach) {
loginUtils.loginAndGetAccessToken(server, function (err, accessToken) {
if (err) return callbackEach(err)
server.accessToken = accessToken
callbackEach()
})
}, next)
},
// Pod 1 makes friend with pod 2
function (next) {
const server = servers[0]
podsUtils.makeFriends(server.url, server.accessToken, next)
},
// Upload a video on pod 2
function (next) {
const videoAttributes = {
name: 'my super name for pod 2',
description: 'my super description for pod 2'
}
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, videoAttributes, next)
},
// Wait videos propagation
function (next) {
setTimeout(next, 11000)
},
function (next) {
videosUtils.getVideosList(servers[0].url, function (err, res) {
if (err) throw err
const videos = res.body.data
expect(videos.length).to.equal(1)
servers[0].remoteVideo = videos.find(function (video) { return video.name === 'my super name for pod 2' })
next()
})
}
], done)
})
it('Should blacklist a remote video on pod 1', function (done) {
videoBlacklistsUtils.addVideoToBlacklist(servers[0].url, servers[0].accessToken, servers[0].remoteVideo.id, done)
})
it('Should not have the video blacklisted in videos list on pod 1', function (done) {
videosUtils.getVideosList(servers[0].url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(0)
done()
})
})
it('Should not have the video blacklisted in videos search on pod 1', function (done) {
videosUtils.searchVideo(servers[0].url, 'name', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(0)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(0)
done()
})
})
it('Should have the blacklisted video in videos list on pod 2', function (done) {
videosUtils.getVideosList(servers[1].url, function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(1)
done()
})
})
it('Should have the video blacklisted in videos search on pod 2', function (done) {
videosUtils.searchVideo(servers[1].url, 'name', function (err, res) {
if (err) throw err
expect(res.body.total).to.equal(1)
expect(res.body.data).to.be.an('array')
expect(res.body.data.length).to.equal(1)
done()
})
})
after(function (done) {
servers.forEach(function (server) {
process.kill(-server.app.pid)
})
// Keep the logs if the test failed
if (this.ok) {
serversUtils.flushTests(done)
} else {
done()
}
})
})

View File

@ -2,7 +2,7 @@
const request = require('supertest') const request = require('supertest')
const videosUtils = { const videosAbuseUtils = {
getVideoAbusesList, getVideoAbusesList,
getVideoAbusesListPagination, getVideoAbusesListPagination,
getVideoAbusesListSort, getVideoAbusesListSort,
@ -70,4 +70,4 @@ function getVideoAbusesListSort (url, token, sort, end) {
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
module.exports = videosUtils module.exports = videosAbuseUtils

View File

@ -0,0 +1,29 @@
'use strict'
const request = require('supertest')
const videosBlacklistsUtils = {
addVideoToBlacklist
}
// ---------------------- Export functions --------------------
function addVideoToBlacklist (url, token, videoId, specialStatus, end) {
if (!end) {
end = specialStatus
specialStatus = 204
}
const path = '/api/v1/videos/' + videoId + '/blacklist'
request(url)
.post(path)
.set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + token)
.expect(specialStatus)
.end(end)
}
// ---------------------------------------------------------------------------
module.exports = videosBlacklistsUtils