Add tags support to server

This commit is contained in:
Chocobozzz 2016-06-06 14:15:03 +02:00
parent 8483b22164
commit be587647f9
14 changed files with 275 additions and 71 deletions

View File

@ -61,7 +61,6 @@
"scripty": "^1.5.0", "scripty": "^1.5.0",
"segfault-handler": "^1.0.0", "segfault-handler": "^1.0.0",
"ursa": "^0.9.1", "ursa": "^0.9.1",
"validator": "^5.0.0",
"webtorrent": "^0.93.2", "webtorrent": "^0.93.2",
"winston": "^2.1.1", "winston": "^2.1.1",
"ws": "^1.0.1" "ws": "^1.0.1"

View File

@ -115,7 +115,8 @@ function addVideo (req, res, next) {
magnetUri: torrent.magnetURI, magnetUri: torrent.magnetURI,
author: res.locals.oauth.token.user.username, author: res.locals.oauth.token.user.username,
duration: videoFile.duration, duration: videoFile.duration,
thumbnail: thumbnailName thumbnail: thumbnailName,
tags: videoInfos.tags
} }
Videos.add(videoData, function (err, insertedVideo) { Videos.add(videoData, function (err, insertedVideo) {
@ -156,7 +157,7 @@ function addVideo (req, res, next) {
return callback(null) return callback(null)
} }
], function (err) { ], function andFinally (err) {
if (err) { if (err) {
logger.error('Cannot insert the video.') logger.error('Cannot insert the video.')
return next(err) return next(err)
@ -228,7 +229,7 @@ function removeVideo (req, res, next) {
return callback(null) return callback(null)
} }
], function (err) { ], function andFinally (err) {
if (err) { if (err) {
logger.error('Errors when removed the video.', { error: err }) logger.error('Errors when removed the video.', { error: err })
return next(err) return next(err)
@ -259,6 +260,7 @@ function getFormatedVideo (videoObj) {
magnetUri: videoObj.magnetUri, magnetUri: videoObj.magnetUri,
author: videoObj.author, author: videoObj.author,
duration: videoObj.duration, duration: videoObj.duration,
tags: videoObj.tags,
thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail, thumbnailPath: constants.THUMBNAILS_STATIC_PATH + '/' + videoObj.thumbnail,
createdDate: videoObj.createdDate createdDate: videoObj.createdDate
} }

View File

@ -1,34 +1,47 @@
'use strict' 'use strict'
const validator = require('validator') const validator = require('express-validator').validator
const constants = require('../initializers/constants') const constants = require('../initializers/constants')
const VIDEOS_CONSTRAINTS_FIELDS = constants.VIDEOS_CONSTRAINTS_FIELDS
const customValidators = { const customValidators = {
eachIsRemoteVideosAddValid: eachIsRemoteVideosAddValid, exists: exists,
eachIsRemoteVideosRemoveValid: eachIsRemoteVideosRemoveValid, isEachAddRemoteVideosValid: isEachAddRemoteVideosValid,
isArray: isArray isEachRemoveRemoteVideosValid: isEachRemoveRemoteVideosValid,
isArray: isArray,
isVideoAuthorValid: isVideoAuthorValid,
isVideoDateValid: isVideoDateValid,
isVideoDescriptionValid: isVideoDescriptionValid,
isVideoDurationValid: isVideoDurationValid,
isVideoMagnetUriValid: isVideoMagnetUriValid,
isVideoNameValid: isVideoNameValid,
isVideoPodUrlValid: isVideoPodUrlValid,
isVideoTagsValid: isVideoTagsValid,
isVideoThumbnailValid: isVideoThumbnailValid
} }
function eachIsRemoteVideosAddValid (values) { function exists (value) {
return values.every(function (val) { return value !== undefined && value !== null
return validator.isLength(val.name, 1, 50) && }
validator.isLength(val.description, 1, 50) &&
validator.isLength(val.magnetUri, 10) && function isEachAddRemoteVideosValid (videos) {
validator.isURL(val.podUrl) && return videos.every(function (video) {
!isNaN(val.duration) && return isVideoAuthorValid(video.author) &&
val.duration >= 0 && isVideoDateValid(video.createdDate) &&
val.duration < constants.MAXIMUM_VIDEO_DURATION && isVideoDescriptionValid(video.description) &&
validator.isLength(val.author, 1, constants.MAXIMUM_AUTHOR_LENGTH) && isVideoDurationValid(video.duration) &&
validator.isBase64(val.thumbnailBase64) && isVideoMagnetUriValid(video.magnetUri) &&
validator.isByteLength(val.thumbnailBase64, { min: 0, max: 20000 }) && isVideoNameValid(video.name) &&
validator.isDate(val.createdDate) isVideoPodUrlValid(video.podUrl) &&
isVideoTagsValid(video.tags) &&
isVideoThumbnailValid(video.thumbnailBase64)
}) })
} }
function eachIsRemoteVideosRemoveValid (values) { function isEachRemoveRemoteVideosValid (videos) {
return values.every(function (val) { return videos.every(function (video) {
return validator.isLength(val.magnetUri, 10) return isVideoMagnetUriValid(video.magnetUri)
}) })
} }
@ -36,6 +49,50 @@ function isArray (value) {
return Array.isArray(value) return Array.isArray(value)
} }
function isVideoAuthorValid (value) {
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.AUTHOR)
}
function isVideoDateValid (value) {
return validator.isDate(value)
}
function isVideoDescriptionValid (value) {
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
}
function isVideoDurationValid (value) {
return validator.isInt(value + '', VIDEOS_CONSTRAINTS_FIELDS.DURATION)
}
function isVideoMagnetUriValid (value) {
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.MAGNET_URI)
}
function isVideoNameValid (value) {
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.NAME)
}
function isVideoPodUrlValid (value) {
return validator.isURL(value)
}
function isVideoTagsValid (tags) {
return isArray(tags) &&
validator.isInt(tags.length, VIDEOS_CONSTRAINTS_FIELDS.TAGS) &&
tags.every(function (tag) {
return validator.isAlphanumeric(tag) &&
validator.isLength(tag, VIDEOS_CONSTRAINTS_FIELDS.TAG)
})
}
function isVideoThumbnailValid (value) {
return validator.isBase64(value) &&
validator.isByteLength(value, VIDEOS_CONSTRAINTS_FIELDS.THUMBNAIL)
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
module.exports = customValidators module.exports = customValidators
// ---------------------------------------------------------------------------

View File

@ -9,11 +9,6 @@ let FRIEND_BASE_SCORE = 100
// Time to wait between requests to the friends (10 min) // Time to wait between requests to the friends (10 min)
let INTERVAL = 600000 let INTERVAL = 600000
// Max length of the author username
const MAXIMUM_AUTHOR_LENGTH = 20
// 2 hours maximum for the duration of a video (in seconds)
let MAXIMUM_VIDEO_DURATION = 7200
// Number of results by default for the pagination // Number of results by default for the pagination
const PAGINATION_COUNT_DEFAULT = 15 const PAGINATION_COUNT_DEFAULT = 15
@ -42,11 +37,22 @@ const THUMBNAILS_SIZE = '200x110'
// Path for access to thumbnails with express router // Path for access to thumbnails with express router
const THUMBNAILS_STATIC_PATH = '/static/thumbnails' const THUMBNAILS_STATIC_PATH = '/static/thumbnails'
const VIDEOS_CONSTRAINTS_FIELDS = {
NAME: { min: 1, max: 50 }, // Length
DESCRIPTION: { min: 1, max: 250 }, // Length
MAGNET_URI: { min: 10 }, // Length
DURATION: { min: 1, max: 7200 }, // Number
AUTHOR: { min: 3, max: 20 }, // Length
TAGS: { min: 1, max: 3 }, // Number of total tags
TAG: { min: 2, max: 10 }, // Length
THUMBNAIL: { min: 0, max: 20000 } // Bytes
}
// Special constants for a test instance // Special constants for a test instance
if (isTestInstance() === true) { if (isTestInstance() === true) {
FRIEND_BASE_SCORE = 20 FRIEND_BASE_SCORE = 20
INTERVAL = 10000 INTERVAL = 10000
MAXIMUM_VIDEO_DURATION = 14 VIDEOS_CONSTRAINTS_FIELDS.DURATION.max = 14
REQUEST_RETRIES = 2 REQUEST_RETRIES = 2
} }
@ -56,15 +62,14 @@ module.exports = {
API_VERSION: API_VERSION, API_VERSION: API_VERSION,
FRIEND_BASE_SCORE: FRIEND_BASE_SCORE, FRIEND_BASE_SCORE: FRIEND_BASE_SCORE,
INTERVAL: INTERVAL, INTERVAL: INTERVAL,
MAXIMUM_AUTHOR_LENGTH: MAXIMUM_AUTHOR_LENGTH,
MAXIMUM_VIDEO_DURATION: MAXIMUM_VIDEO_DURATION,
PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT, PAGINATION_COUNT_DEFAULT: PAGINATION_COUNT_DEFAULT,
PODS_SCORE: PODS_SCORE, PODS_SCORE: PODS_SCORE,
REQUEST_RETRIES: REQUEST_RETRIES, REQUEST_RETRIES: REQUEST_RETRIES,
SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS, SEARCHABLE_COLUMNS: SEARCHABLE_COLUMNS,
SORTABLE_COLUMNS: SORTABLE_COLUMNS, SORTABLE_COLUMNS: SORTABLE_COLUMNS,
THUMBNAILS_SIZE: THUMBNAILS_SIZE, THUMBNAILS_SIZE: THUMBNAILS_SIZE,
THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH THUMBNAILS_STATIC_PATH: THUMBNAILS_STATIC_PATH,
VIDEOS_CONSTRAINTS_FIELDS: VIDEOS_CONSTRAINTS_FIELDS
} }
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------

View File

@ -153,7 +153,8 @@ function createRemoteVideoObjects (videos, callback) {
magnetUri: video.magnetUri, magnetUri: video.magnetUri,
podUrl: video.podUrl, podUrl: video.podUrl,
duration: video.duration, duration: video.duration,
thumbnail: thumbnailName thumbnail: thumbnailName,
tags: video.tags
} }
remoteVideos.push(params) remoteVideos.push(params)

View File

@ -11,7 +11,7 @@ const reqValidatorsRemote = {
function remoteVideosAdd (req, res, next) { function remoteVideosAdd (req, res, next) {
req.checkBody('data').isArray() req.checkBody('data').isArray()
req.checkBody('data').eachIsRemoteVideosAddValid() req.checkBody('data').isEachAddRemoteVideosValid()
logger.debug('Checking remoteVideosAdd parameters', { parameters: req.body }) logger.debug('Checking remoteVideosAdd parameters', { parameters: req.body })
@ -20,7 +20,7 @@ function remoteVideosAdd (req, res, next) {
function remoteVideosRemove (req, res, next) { function remoteVideosRemove (req, res, next) {
req.checkBody('data').isArray() req.checkBody('data').isArray()
req.checkBody('data').eachIsRemoteVideosRemoveValid() req.checkBody('data').isEachRemoveRemoteVideosValid()
logger.debug('Checking remoteVideosRemove parameters', { parameters: req.body }) logger.debug('Checking remoteVideosRemove parameters', { parameters: req.body })

View File

@ -2,6 +2,7 @@
const checkErrors = require('./utils').checkErrors const checkErrors = require('./utils').checkErrors
const constants = require('../../initializers/constants') const constants = require('../../initializers/constants')
const customValidators = require('../../helpers/customValidators')
const logger = require('../../helpers/logger') const logger = require('../../helpers/logger')
const videos = require('../../lib/videos') const videos = require('../../lib/videos')
const Videos = require('../../models/videos') const Videos = require('../../models/videos')
@ -16,8 +17,9 @@ const reqValidatorsVideos = {
function videosAdd (req, res, next) { function videosAdd (req, res, next) {
req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty() req.checkFiles('videofile[0].originalname', 'Should have an input video').notEmpty()
req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i) req.checkFiles('videofile[0].mimetype', 'Should have a correct mime type').matches(/video\/(webm)|(mp4)|(ogg)/i)
req.checkBody('name', 'Should have a name').isLength(1, 50) req.checkBody('name', 'Should have a valid name').isVideoNameValid()
req.checkBody('description', 'Should have a description').isLength(1, 250) req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files }) logger.debug('Checking videosAdd parameters', { parameters: req.body, files: req.files })
@ -29,7 +31,7 @@ function videosAdd (req, res, next) {
return res.status(400).send('Cannot retrieve metadata of the file.') return res.status(400).send('Cannot retrieve metadata of the file.')
} }
if (duration > constants.MAXIMUM_VIDEO_DURATION) { if (!customValidators.isVideoDurationValid(duration)) {
return res.status(400).send('Duration of the video file is too big (max: ' + constants.MAXIMUM_VIDEO_DURATION + 's).') return res.status(400).send('Duration of the video file is too big (max: ' + constants.MAXIMUM_VIDEO_DURATION + 's).')
} }
@ -48,7 +50,7 @@ function videosGet (req, res, next) {
Videos.get(req.params.id, function (err, video) { Videos.get(req.params.id, function (err, video) {
if (err) { if (err) {
logger.error('Error in videosGet request validator.', { error: err }) logger.error('Error in videosGet request validator.', { error: err })
res.sendStatus(500) return res.sendStatus(500)
} }
const state = videos.getVideoState(video) const state = videos.getVideoState(video)
@ -68,7 +70,7 @@ function videosRemove (req, res, next) {
Videos.get(req.params.id, function (err, video) { Videos.get(req.params.id, function (err, video) {
if (err) { if (err) {
logger.error('Error in videosRemove request validator.', { error: err }) logger.error('Error in videosRemove request validator.', { error: err })
res.sendStatus(500) return res.sendStatus(500)
} }
const state = videos.getVideoState(video) const state = videos.getVideoState(video)
@ -82,7 +84,7 @@ function videosRemove (req, res, next) {
function videosSearch (req, res, next) { function videosSearch (req, res, next) {
const searchableColumns = constants.SEARCHABLE_COLUMNS.VIDEOS const searchableColumns = constants.SEARCHABLE_COLUMNS.VIDEOS
req.checkParams('value', 'Should have a name').notEmpty() req.checkParams('value', 'Should have a valid search').notEmpty()
req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns) req.checkQuery('field', 'Should have correct searchable column').optional().isIn(searchableColumns)
logger.debug('Checking videosSearch parameters', { parameters: req.params }) logger.debug('Checking videosSearch parameters', { parameters: req.params })

View File

@ -21,6 +21,7 @@ const videosSchema = mongoose.Schema({
author: String, author: String,
duration: Number, duration: Number,
thumbnail: String, thumbnail: String,
tags: [ String ],
createdDate: { createdDate: {
type: Date, type: Date,
default: Date.now default: Date.now

View File

@ -23,7 +23,14 @@ describe('Test parameters validator', function () {
Object.keys(fields).forEach(function (field) { Object.keys(fields).forEach(function (field) {
const value = fields[field] const value = fields[field]
if (Array.isArray(value)) {
for (let i = 0; i < value.length; i++) {
req.field(field + '[' + i + ']', value[i])
}
} else {
req.field(field, value) req.field(field, value)
}
}) })
Object.keys(attaches).forEach(function (attach) { Object.keys(attaches).forEach(function (attach) {
@ -198,7 +205,8 @@ describe('Test parameters validator', function () {
it('Should fail without name', function (done) { it('Should fail without name', function (done) {
const data = { const data = {
description: 'my super description' description: 'my super description',
tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
@ -209,7 +217,8 @@ describe('Test parameters validator', function () {
it('Should fail with a long name', function (done) { it('Should fail with a long name', function (done) {
const data = { const data = {
name: 'My very very very very very very very very very very very very very very very very long name', name: 'My very very very very very very very very very very very very very very very very long name',
description: 'my super description' description: 'my super description',
tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
@ -219,7 +228,8 @@ describe('Test parameters validator', function () {
it('Should fail without description', function (done) { it('Should fail without description', function (done) {
const data = { const data = {
name: 'my super name' name: 'my super name',
tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
@ -232,7 +242,79 @@ describe('Test parameters validator', function () {
name: 'my super name', name: 'my super name',
description: 'my super description which is very very very very very very very very very very very very very very' + description: 'my super description which is very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very very very very very very very' + 'very very very very very very very very very very very very very very very very very very very very very' +
'very very very very very very very very very very very very very very very long' 'very very very very very very very very very very very very very very very long',
tags: [ 'tag1', 'tag2' ]
}
const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
it('Should fail without tags', function (done) {
const data = {
name: 'my super name',
description: 'my super description'
}
const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
it('Should fail with too many tags', function (done) {
const data = {
name: 'my super name',
description: 'my super description',
tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
}
const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
it('Should fail with not enough tags', function (done) {
const data = {
name: 'my super name',
description: 'my super description',
tags: [ ]
}
const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
it('Should fail with a tag length too low', function (done) {
const data = {
name: 'my super name',
description: 'my super description',
tags: [ 'tag1', 't' ]
}
const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
it('Should fail with a tag length too big', function (done) {
const data = {
name: 'my super name',
description: 'my super description',
tags: [ 'mysupertagtoolong', 'tag1' ]
}
const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
}
makePostRequest(path, server.accessToken, data, attach, done)
})
it('Should fail with malformed tags', function (done) {
const data = {
name: 'my super name',
description: 'my super description',
tags: [ 'my tag' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')
@ -243,7 +325,8 @@ describe('Test parameters validator', function () {
it('Should fail without an input file', function (done) { it('Should fail without an input file', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
description: 'my super description' description: 'my super description',
tags: [ 'tag1', 'tag2' ]
} }
const attach = {} const attach = {}
makePostRequest(path, server.accessToken, data, attach, done) makePostRequest(path, server.accessToken, data, attach, done)
@ -252,7 +335,8 @@ describe('Test parameters validator', function () {
it('Should fail without an incorrect input file', function (done) { it('Should fail without an incorrect input file', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
description: 'my super description' description: 'my super description',
tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm')
@ -263,7 +347,8 @@ describe('Test parameters validator', function () {
it('Should fail with a too big duration', function (done) { it('Should fail with a too big duration', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
description: 'my super description' description: 'my super description',
tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm')
@ -274,7 +359,8 @@ describe('Test parameters validator', function () {
it('Should succeed with the correct parameters', function (done) { it('Should succeed with the correct parameters', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
description: 'my super description' description: 'my super description',
tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm')

View File

@ -27,10 +27,11 @@ describe('Test advanced friends', function () {
function uploadVideo (podNumber, callback) { function uploadVideo (podNumber, callback) {
const name = 'my super video' const name = 'my super video'
const description = 'my super description' const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const fixture = 'video_short.webm' const fixture = 'video_short.webm'
const server = servers[podNumber - 1] const server = servers[podNumber - 1]
return utils.uploadVideo(server.url, server.accessToken, name, description, fixture, callback) return utils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback)
} }
function getVideos (podNumber, callback) { function getVideos (podNumber, callback) {

View File

@ -75,7 +75,11 @@ describe('Test multiple pods', function () {
async.series([ async.series([
function (next) { function (next) {
utils.uploadVideo(servers[0].url, servers[0].accessToken, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next) const name = 'my super name for pod 1'
const description = 'my super description for pod 1'
const tags = [ 'tag1p1', 'tag2p1' ]
const file = 'video_short1.webm'
utils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next)
}, },
function (next) { function (next) {
setTimeout(next, 11000) setTimeout(next, 11000)
@ -99,6 +103,7 @@ describe('Test multiple pods', function () {
expect(video.podUrl).to.equal('localhost:9001') expect(video.podUrl).to.equal('localhost:9001')
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
expect(video.duration).to.equal(10) expect(video.duration).to.equal(10)
expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
expect(utils.dateIsValid(video.createdDate)).to.be.true expect(utils.dateIsValid(video.createdDate)).to.be.true
if (server.url !== 'http://localhost:9001') { if (server.url !== 'http://localhost:9001') {
@ -131,7 +136,11 @@ describe('Test multiple pods', function () {
async.series([ async.series([
function (next) { function (next) {
utils.uploadVideo(servers[1].url, servers[1].accessToken, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) const name = 'my super name for pod 2'
const description = 'my super description for pod 2'
const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
const file = 'video_short2.webm'
utils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next)
}, },
function (next) { function (next) {
setTimeout(next, 11000) setTimeout(next, 11000)
@ -155,6 +164,7 @@ describe('Test multiple pods', function () {
expect(video.podUrl).to.equal('localhost:9002') expect(video.podUrl).to.equal('localhost:9002')
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
expect(video.duration).to.equal(5) expect(video.duration).to.equal(5)
expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
expect(utils.dateIsValid(video.createdDate)).to.be.true expect(utils.dateIsValid(video.createdDate)).to.be.true
if (server.url !== 'http://localhost:9002') { if (server.url !== 'http://localhost:9002') {
@ -187,10 +197,18 @@ describe('Test multiple pods', function () {
async.series([ async.series([
function (next) { function (next) {
utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) const name = 'my super name for pod 3'
const description = 'my super description for pod 3'
const tags = [ 'tag1p3' ]
const file = 'video_short3.webm'
utils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
}, },
function (next) { function (next) {
utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) const name = 'my super name for pod 3-2'
const description = 'my super description for pod 3-2'
const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
const file = 'video_short.webm'
utils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next)
}, },
function (next) { function (next) {
setTimeout(next, 22000) setTimeout(next, 22000)
@ -224,6 +242,7 @@ describe('Test multiple pods', function () {
expect(video1.podUrl).to.equal('localhost:9003') expect(video1.podUrl).to.equal('localhost:9003')
expect(video1.magnetUri).to.exist expect(video1.magnetUri).to.exist
expect(video1.duration).to.equal(5) expect(video1.duration).to.equal(5)
expect(video1.tags).to.deep.equal([ 'tag1p3' ])
expect(utils.dateIsValid(video1.createdDate)).to.be.true expect(utils.dateIsValid(video1.createdDate)).to.be.true
expect(video2.name).to.equal('my super name for pod 3-2') expect(video2.name).to.equal('my super name for pod 3-2')
@ -231,6 +250,7 @@ describe('Test multiple pods', function () {
expect(video2.podUrl).to.equal('localhost:9003') expect(video2.podUrl).to.equal('localhost:9003')
expect(video2.magnetUri).to.exist expect(video2.magnetUri).to.exist
expect(video2.duration).to.equal(5) expect(video2.duration).to.equal(5)
expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
expect(utils.dateIsValid(video2.createdDate)).to.be.true expect(utils.dateIsValid(video2.createdDate)).to.be.true
if (server.url !== 'http://localhost:9003') { if (server.url !== 'http://localhost:9003') {

View File

@ -57,7 +57,11 @@ describe('Test a single pod', function () {
it('Should upload the video', function (done) { it('Should upload the video', function (done) {
this.timeout(5000) this.timeout(5000)
utils.uploadVideo(server.url, server.accessToken, 'my super name', 'my super description', 'video_short.webm', done) const name = 'my super name'
const description = 'my super description'
const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm'
utils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done)
}) })
it('Should seed the uploaded video', function (done) { it('Should seed the uploaded video', function (done) {
@ -78,6 +82,7 @@ describe('Test a single pod', function () {
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(utils.dateIsValid(video.createdDate)).to.be.true expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
@ -112,6 +117,7 @@ describe('Test a single pod', function () {
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(utils.dateIsValid(video.createdDate)).to.be.true expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
@ -143,6 +149,7 @@ describe('Test a single pod', function () {
expect(video.podUrl).to.equal('localhost:9001') expect(video.podUrl).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(utils.dateIsValid(video.createdDate)).to.be.true expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
@ -168,6 +175,7 @@ describe('Test a single pod', function () {
expect(video.podUrl).to.equal('localhost:9001') expect(video.podUrl).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
expect(video.isLocal).to.be.true expect(video.isLocal).to.be.true
expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
expect(utils.dateIsValid(video.createdDate)).to.be.true expect(utils.dateIsValid(video.createdDate)).to.be.true
utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
@ -235,7 +243,11 @@ describe('Test a single pod', function () {
'video_short1.webm', 'video_short2.webm', 'video_short3.webm' 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
] ]
async.each(videos, function (video, callbackEach) { async.each(videos, function (video, callbackEach) {
utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach) const name = video + ' name'
const description = video + ' description'
const tags = [ 'tag1', 'tag2', 'tag3' ]
utils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach)
}, done) }, done)
}) })

View File

@ -79,7 +79,12 @@ describe('Test users', function () {
it('Should not be able to upload a video', function (done) { it('Should not be able to upload a video', function (done) {
accessToken = 'mysupertoken' accessToken = 'mysupertoken'
utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done)
const name = 'my super name'
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm'
utils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done)
}) })
it('Should not be able to make friends', function (done) { it('Should not be able to make friends', function (done) {
@ -102,7 +107,11 @@ describe('Test users', function () {
}) })
it('Should upload the video with the correct token', function (done) { it('Should upload the video with the correct token', function (done) {
utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) { const name = 'my super name'
const description = 'my super description'
const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm'
utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) {
if (err) throw err if (err) throw err
utils.getVideosList(server.url, function (err, res) { utils.getVideosList(server.url, function (err, res) {
@ -118,7 +127,11 @@ describe('Test users', function () {
}) })
it('Should upload the video again with the correct token', function (done) { it('Should upload the video again with the correct token', function (done) {
utils.uploadVideo(server.url, accessToken, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done) const name = 'my super name 2'
const description = 'my super description 2'
const tags = [ 'tag1' ]
const video = 'video_short.webm'
utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
}) })
it('Should not be able to remove the video with an incorrect token', function (done) { it('Should not be able to remove the video with an incorrect token', function (done) {

View File

@ -349,7 +349,7 @@ function testImage (url, videoName, imagePath, callback) {
}) })
} }
function uploadVideo (url, accessToken, name, description, fixture, specialStatus, end) { function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) {
if (!end) { if (!end) {
end = specialStatus end = specialStatus
specialStatus = 204 specialStatus = 204
@ -357,13 +357,18 @@ function uploadVideo (url, accessToken, name, description, fixture, specialStatu
const path = '/api/v1/videos' const path = '/api/v1/videos'
request(url) const req = request(url)
.post(path) .post(path)
.set('Accept', 'application/json') .set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.field('name', name) .field('name', name)
.field('description', description) .field('description', description)
.attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture))
for (let i = 0; i < tags.length; i++) {
req.field('tags[' + i + ']', tags[i])
}
req.attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture))
.expect(specialStatus) .expect(specialStatus)
.end(end) .end(end)
} }