Server: add tests for video blacklists
This commit is contained in:
parent
3eeeb87fe6
commit
843aa7ba03
8 changed files with 300 additions and 7 deletions
|
@ -7,3 +7,4 @@ require('./users')
|
|||
require('./requests')
|
||||
require('./videos')
|
||||
require('./video-abuses')
|
||||
require('./video-blacklists')
|
||||
|
|
|
@ -129,7 +129,7 @@ describe('Test video abuses API validators', function () {
|
|||
const basePath = '/api/v1/videos/'
|
||||
|
||||
it('Should fail with nothing', function (done) {
|
||||
const path = basePath + server.video + '/abuse'
|
||||
const path = basePath + server.video.id + '/abuse'
|
||||
const data = {}
|
||||
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) {
|
||||
const data = {}
|
||||
const path = basePath + server.video + '/abuse'
|
||||
const path = basePath + server.video.id + '/abuse'
|
||||
requestsUtils.makePostBodyRequest(server.url, path, 'hello', data, done, 401)
|
||||
})
|
||||
|
||||
|
@ -150,7 +150,7 @@ describe('Test video abuses API validators', function () {
|
|||
const data = {
|
||||
reason: 'h'
|
||||
}
|
||||
const path = basePath + server.video + '/abuse'
|
||||
const path = basePath + server.video.id + '/abuse'
|
||||
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
|
||||
})
|
||||
|
||||
|
@ -161,7 +161,7 @@ describe('Test video abuses API validators', function () {
|
|||
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef' +
|
||||
'0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef0123456789abcdef'
|
||||
}
|
||||
const path = basePath + server.video + '/abuse'
|
||||
const path = basePath + server.video.id + '/abuse'
|
||||
requestsUtils.makePostBodyRequest(server.url, path, server.accessToken, data, done)
|
||||
})
|
||||
})
|
||||
|
|
123
server/tests/api/check-params/video-blacklists.js
Normal file
123
server/tests/api/check-params/video-blacklists.js
Normal 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()
|
||||
}
|
||||
})
|
||||
})
|
|
@ -6,6 +6,8 @@ require('./check-params')
|
|||
require('./friends-basic')
|
||||
require('./users')
|
||||
require('./single-pod')
|
||||
require('./video-abuse')
|
||||
require('./video-blacklist')
|
||||
require('./multiple-pods')
|
||||
require('./requests')
|
||||
require('./friends-advanced')
|
||||
|
|
|
@ -38,7 +38,7 @@ describe('Test video abuses', function () {
|
|||
})
|
||||
}, next)
|
||||
},
|
||||
// Pod 1 make friends too
|
||||
// Pod 1 makes friend with pod 2
|
||||
function (next) {
|
||||
const server = servers[0]
|
||||
podsUtils.makeFriends(server.url, server.accessToken, next)
|
||||
|
|
138
server/tests/api/video-blacklist.js
Normal file
138
server/tests/api/video-blacklist.js
Normal 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()
|
||||
}
|
||||
})
|
||||
})
|
|
@ -2,7 +2,7 @@
|
|||
|
||||
const request = require('supertest')
|
||||
|
||||
const videosUtils = {
|
||||
const videosAbuseUtils = {
|
||||
getVideoAbusesList,
|
||||
getVideoAbusesListPagination,
|
||||
getVideoAbusesListSort,
|
||||
|
@ -70,4 +70,4 @@ function getVideoAbusesListSort (url, token, sort, end) {
|
|||
|
||||
// ---------------------------------------------------------------------------
|
||||
|
||||
module.exports = videosUtils
|
||||
module.exports = videosAbuseUtils
|
||||
|
|
29
server/tests/utils/video-blacklists.js
Normal file
29
server/tests/utils/video-blacklists.js
Normal 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
|
Loading…
Reference in a new issue