1
0
Fork 0

Add video category support

This commit is contained in:
Chocobozzz 2017-03-22 21:15:55 +01:00
parent 2d7653dc87
commit 6e07c3de88
28 changed files with 324 additions and 30 deletions

View file

@ -2,6 +2,7 @@ import { Component, OnInit, ViewContainerRef } from '@angular/core';
import { Router } from '@angular/router'; import { Router } from '@angular/router';
import { AuthService } from './core'; import { AuthService } from './core';
import { VideoService } from './videos';
import { UserService } from './shared'; import { UserService } from './shared';
@Component({ @Component({
@ -27,6 +28,7 @@ export class AppComponent implements OnInit {
private router: Router, private router: Router,
private authService: AuthService, private authService: AuthService,
private userService: UserService, private userService: UserService,
private videoService: VideoService,
viewContainerRef: ViewContainerRef viewContainerRef: ViewContainerRef
) {} ) {}
@ -35,6 +37,8 @@ export class AppComponent implements OnInit {
// The service will automatically redirect to the login page if the token is not valid anymore // The service will automatically redirect to the login page if the token is not valid anymore
this.userService.checkTokenValidity(); this.userService.checkTokenValidity();
} }
this.videoService.loadVideoCategories();
} }
isInAdmin() { isInAdmin() {

View file

@ -8,6 +8,12 @@ export const VIDEO_NAME = {
'maxlength': 'Video name cannot be more than 50 characters long.' 'maxlength': 'Video name cannot be more than 50 characters long.'
} }
}; };
export const VIDEO_CATEGORY = {
VALIDATORS: [ Validators.required ],
MESSAGES: {
'required': 'Video category is required.'
}
};
export const VIDEO_DESCRIPTION = { export const VIDEO_DESCRIPTION = {
VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ], VALIDATORS: [ Validators.required, Validators.minLength(3), Validators.maxLength(250) ],
MESSAGES: { MESSAGES: {

View file

@ -2,6 +2,7 @@ export class Video {
author: string; author: string;
by: string; by: string;
createdAt: Date; createdAt: Date;
categoryLabel: string;
description: string; description: string;
duration: string; duration: string;
id: string; id: string;
@ -31,6 +32,7 @@ export class Video {
constructor(hash: { constructor(hash: {
author: string, author: string,
createdAt: string, createdAt: string,
categoryLabel: string,
description: string, description: string,
duration: number; duration: number;
id: string, id: string,
@ -46,6 +48,7 @@ export class Video {
}) { }) {
this.author = hash.author; this.author = hash.author;
this.createdAt = new Date(hash.createdAt); this.createdAt = new Date(hash.createdAt);
this.categoryLabel = hash.categoryLabel;
this.description = hash.description; this.description = hash.description;
this.duration = Video.createDurationString(hash.duration); this.duration = Video.createDurationString(hash.duration);
this.id = hash.id; this.id = hash.id;

View file

@ -22,6 +22,8 @@ import { Video } from './video.model';
export class VideoService { export class VideoService {
private static BASE_VIDEO_URL = '/api/v1/videos/'; private static BASE_VIDEO_URL = '/api/v1/videos/';
videoCategories: Array<{ id: number, label: string }> = [];
constructor( constructor(
private authService: AuthService, private authService: AuthService,
private authHttp: AuthHttp, private authHttp: AuthHttp,
@ -30,6 +32,19 @@ export class VideoService {
private restService: RestService private restService: RestService
) {} ) {}
loadVideoCategories() {
return this.http.get(VideoService.BASE_VIDEO_URL + 'categories')
.map(this.restExtractor.extractDataGet)
.subscribe(data => {
Object.keys(data).forEach(categoryKey => {
this.videoCategories.push({
id: parseInt(categoryKey),
label: data[categoryKey]
});
});
});
}
getVideo(id: string): Observable<Video> { getVideo(id: string): Observable<Video> {
return this.http.get(VideoService.BASE_VIDEO_URL + id) return this.http.get(VideoService.BASE_VIDEO_URL + id)
.map(this.restExtractor.extractDataGet) .map(this.restExtractor.extractDataGet)

View file

@ -14,6 +14,18 @@
</div> </div>
</div> </div>
<div class="form-group">
<label for="category">Category</label>
<select class="form-control" id="category" formControlName="category">
<option></option>
<option *ngFor="let category of videoCategories" [value]="category.id">{{ category.label }}</option>
</select>
<div *ngIf="formErrors.category" class="alert alert-danger">
{{ formErrors.category }}
</div>
</div>
<div class="form-group"> <div class="form-group">
<label for="tags">Tags</label> <span class="little-information">(press enter to add the tag)</span> <label for="tags">Tags</label> <span class="little-information">(press enter to add the tag)</span>
<input <input

View file

@ -6,7 +6,14 @@ import { FileUploader } from 'ng2-file-upload/ng2-file-upload';
import { NotificationsService } from 'angular2-notifications'; import { NotificationsService } from 'angular2-notifications';
import { AuthService } from '../../core'; import { AuthService } from '../../core';
import { FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../shared'; import {
FormReactive,
VIDEO_NAME,
VIDEO_CATEGORY,
VIDEO_DESCRIPTION,
VIDEO_TAGS
} from '../../shared';
import { VideoService } from '../shared';
@Component({ @Component({
selector: 'my-videos-add', selector: 'my-videos-add',
@ -17,16 +24,19 @@ import { FormReactive, VIDEO_NAME, VIDEO_DESCRIPTION, VIDEO_TAGS } from '../../s
export class VideoAddComponent extends FormReactive implements OnInit { export class VideoAddComponent extends FormReactive implements OnInit {
tags: string[] = []; tags: string[] = [];
uploader: FileUploader; uploader: FileUploader;
videoCategories = [];
error: string = null; error: string = null;
form: FormGroup; form: FormGroup;
formErrors = { formErrors = {
name: '', name: '',
category: '',
description: '', description: '',
currentTag: '' currentTag: ''
}; };
validationMessages = { validationMessages = {
name: VIDEO_NAME.MESSAGES, name: VIDEO_NAME.MESSAGES,
category: VIDEO_CATEGORY.MESSAGES,
description: VIDEO_DESCRIPTION.MESSAGES, description: VIDEO_DESCRIPTION.MESSAGES,
currentTag: VIDEO_TAGS.MESSAGES currentTag: VIDEO_TAGS.MESSAGES
}; };
@ -40,7 +50,8 @@ export class VideoAddComponent extends FormReactive implements OnInit {
private elementRef: ElementRef, private elementRef: ElementRef,
private formBuilder: FormBuilder, private formBuilder: FormBuilder,
private router: Router, private router: Router,
private notificationsService: NotificationsService private notificationsService: NotificationsService,
private videoService: VideoService
) { ) {
super(); super();
} }
@ -56,6 +67,7 @@ export class VideoAddComponent extends FormReactive implements OnInit {
buildForm() { buildForm() {
this.form = this.formBuilder.group({ this.form = this.formBuilder.group({
name: [ '', VIDEO_NAME.VALIDATORS ], name: [ '', VIDEO_NAME.VALIDATORS ],
category: [ '', VIDEO_CATEGORY.VALIDATORS ],
description: [ '', VIDEO_DESCRIPTION.VALIDATORS ], description: [ '', VIDEO_DESCRIPTION.VALIDATORS ],
currentTag: [ '', VIDEO_TAGS.VALIDATORS ] currentTag: [ '', VIDEO_TAGS.VALIDATORS ]
}); });
@ -64,6 +76,8 @@ export class VideoAddComponent extends FormReactive implements OnInit {
} }
ngOnInit() { ngOnInit() {
this.videoCategories = this.videoService.videoCategories;
this.uploader = new FileUploader({ this.uploader = new FileUploader({
authToken: this.authService.getRequestHeaderValue(), authToken: this.authService.getRequestHeaderValue(),
queueLimit: 1, queueLimit: 1,
@ -73,9 +87,11 @@ export class VideoAddComponent extends FormReactive implements OnInit {
this.uploader.onBuildItemForm = (item, form) => { this.uploader.onBuildItemForm = (item, form) => {
const name = this.form.value['name']; const name = this.form.value['name'];
const category = this.form.value['category'];
const description = this.form.value['description']; const description = this.form.value['description'];
form.append('name', name); form.append('name', name);
form.append('category', category);
form.append('description', description); form.append('description', description);
for (let i = 0; i < this.tags.length; i++) { for (let i = 0; i < this.tags.length; i++) {

View file

@ -107,6 +107,13 @@
</div> </div>
</div> </div>
<div id="video-category" class="row">
<div class="col-md-12">
<span id="category-label">Category:</span>
{{ video.categoryLabel }}
</div>
</div>
<div id="video-description" class="row"> <div id="video-description" class="row">
<div class="col-md-12"> <div class="col-md-12">
<div id="description-label">Description</div> <div id="description-label">Description</div>

View file

@ -111,8 +111,16 @@
} }
} }
#video-category {
margin-top: 10px;
#category-label {
font-weight: bold;
}
}
#video-description { #video-description {
margin-top: 15px; margin-top: 10px;
#description-label { #description-label {
font-weight: bold; font-weight: bold;

View file

@ -294,6 +294,7 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) {
remoteId: videoToCreateData.remoteId, remoteId: videoToCreateData.remoteId,
extname: videoToCreateData.extname, extname: videoToCreateData.extname,
infoHash: videoToCreateData.infoHash, infoHash: videoToCreateData.infoHash,
category: videoToCreateData.category,
description: videoToCreateData.description, description: videoToCreateData.description,
authorId: author.id, authorId: author.id,
duration: videoToCreateData.duration, duration: videoToCreateData.duration,
@ -390,6 +391,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
const options = { transaction: t } const options = { transaction: t }
videoInstance.set('name', videoAttributesToUpdate.name) videoInstance.set('name', videoAttributesToUpdate.name)
videoInstance.set('category', videoAttributesToUpdate.category)
videoInstance.set('description', videoAttributesToUpdate.description) videoInstance.set('description', videoAttributesToUpdate.description)
videoInstance.set('infoHash', videoAttributesToUpdate.infoHash) videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
videoInstance.set('duration', videoAttributesToUpdate.duration) videoInstance.set('duration', videoAttributesToUpdate.duration)

View file

@ -45,6 +45,8 @@ const storage = multer.diskStorage({
const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
router.get('/categories', listVideoCategories)
router.get('/abuse', router.get('/abuse',
oAuth.authenticate, oAuth.authenticate,
admin.ensureIsAdmin, admin.ensureIsAdmin,
@ -110,6 +112,10 @@ module.exports = router
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
function listVideoCategories (req, res, next) {
res.json(constants.VIDEO_CATEGORIES)
}
function rateVideoRetryWrapper (req, res, next) { function rateVideoRetryWrapper (req, res, next) {
const options = { const options = {
arguments: [ req, res ], arguments: [ req, res ],
@ -300,6 +306,7 @@ function addVideo (req, res, videoFile, finalCallback) {
name: videoInfos.name, name: videoInfos.name,
remoteId: null, remoteId: null,
extname: path.extname(videoFile.filename), extname: path.extname(videoFile.filename),
category: videoInfos.category,
description: videoInfos.description, description: videoInfos.description,
duration: videoFile.duration, duration: videoFile.duration,
authorId: author.id authorId: author.id
@ -413,6 +420,7 @@ function updateVideo (req, res, finalCallback) {
} }
if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category)
if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
videoInstance.save(options).asCallback(function (err) { videoInstance.save(options).asCallback(function (err) {

View file

@ -85,6 +85,7 @@ module.exports = remoteVideosValidators
function isCommonVideoAttributesValid (video) { function isCommonVideoAttributesValid (video) {
return videosValidators.isVideoDateValid(video.createdAt) && return videosValidators.isVideoDateValid(video.createdAt) &&
videosValidators.isVideoDateValid(video.updatedAt) && videosValidators.isVideoDateValid(video.updatedAt) &&
videosValidators.isVideoCategoryValid(video.category) &&
videosValidators.isVideoDescriptionValid(video.description) && videosValidators.isVideoDescriptionValid(video.description) &&
videosValidators.isVideoDurationValid(video.duration) && videosValidators.isVideoDurationValid(video.duration) &&
videosValidators.isVideoInfoHashValid(video.infoHash) && videosValidators.isVideoInfoHashValid(video.infoHash) &&

View file

@ -13,6 +13,7 @@ const VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENT
const videosValidators = { const videosValidators = {
isVideoAuthorValid, isVideoAuthorValid,
isVideoDateValid, isVideoDateValid,
isVideoCategoryValid,
isVideoDescriptionValid, isVideoDescriptionValid,
isVideoDurationValid, isVideoDurationValid,
isVideoInfoHashValid, isVideoInfoHashValid,
@ -40,6 +41,10 @@ function isVideoDateValid (value) {
return validator.isDate(value) return validator.isDate(value)
} }
function isVideoCategoryValid (value) {
return constants.VIDEO_CATEGORIES[value] !== undefined
}
function isVideoDescriptionValid (value) { function isVideoDescriptionValid (value) {
return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
} }

View file

@ -5,7 +5,7 @@ const path = require('path')
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
const LAST_MIGRATION_VERSION = 25 const LAST_MIGRATION_VERSION = 30
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
@ -103,6 +103,27 @@ const VIDEO_RATE_TYPES = {
DISLIKE: 'dislike' DISLIKE: 'dislike'
} }
const VIDEO_CATEGORIES = {
1: 'Music',
2: 'Films',
3: 'Vehicles',
4: 'Art',
5: 'Sports',
6: 'Travels',
7: 'Gaming',
8: 'People',
9: 'Comedy',
10: 'Entertainment',
11: 'News',
12: 'Howto',
13: 'Education',
14: 'Activism',
15: 'Science & Technology',
16: 'Animals',
17: 'Kids',
18: 'Food'
}
// --------------------------------------------------------------------------- // ---------------------------------------------------------------------------
// Score a pod has when we create it as a friend // Score a pod has when we create it as a friend
@ -258,6 +279,7 @@ module.exports = {
STATIC_PATHS, STATIC_PATHS,
THUMBNAILS_SIZE, THUMBNAILS_SIZE,
USER_ROLES, USER_ROLES,
VIDEO_CATEGORIES,
VIDEO_RATE_TYPES VIDEO_RATE_TYPES
} }

View file

@ -0,0 +1,34 @@
'use strict'
const waterfall = require('async/waterfall')
// utils = { transaction, queryInterface, sequelize, Sequelize }
exports.up = function (utils, finalCallback) {
const q = utils.queryInterface
const Sequelize = utils.Sequelize
const data = {
type: Sequelize.INTEGER,
allowNull: false,
defaultValue: 0
}
waterfall([
function addCategoryColumn (callback) {
q.addColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(function (err) {
return callback(err)
})
},
function nullOnDefault (callback) {
data.defaultValue = null
q.changeColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(callback)
}
], finalCallback)
}
exports.down = function (options, callback) {
throw new Error('Not implemented.')
}

View file

@ -21,6 +21,7 @@ const validatorsVideos = {
function videosAdd (req, res, next) { function videosAdd (req, res, next) {
req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files) req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
req.checkBody('name', 'Should have a valid name').isVideoNameValid() req.checkBody('name', 'Should have a valid name').isVideoNameValid()
req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
req.checkBody('tags', 'Should have correct tags').isVideoTagsValid() req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
@ -47,6 +48,7 @@ function videosAdd (req, res, next) {
function videosUpdate (req, res, next) { function videosUpdate (req, res, next) {
req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid() req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid() req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()

View file

@ -51,6 +51,16 @@ module.exports = function (sequelize, DataTypes) {
isUUID: 4 isUUID: 4
} }
}, },
category: {
type: DataTypes.INTEGER,
allowNull: false,
validate: {
categoryValid: function (value) {
const res = customVideosValidators.isVideoCategoryValid(value)
if (res === false) throw new Error('Video category is not valid.')
}
}
},
description: { description: {
type: DataTypes.STRING, type: DataTypes.STRING,
allowNull: false, allowNull: false,
@ -360,9 +370,15 @@ function toFormatedJSON () {
podHost = constants.CONFIG.WEBSERVER.HOST podHost = constants.CONFIG.WEBSERVER.HOST
} }
// Maybe our pod is not up to date and there are new categories since our version
let categoryLabel = constants.VIDEO_CATEGORIES[this.category]
if (!categoryLabel) categoryLabel = 'Misc'
const json = { const json = {
id: this.id, id: this.id,
name: this.name, name: this.name,
category: this.category,
categoryLabel,
description: this.description, description: this.description,
podHost, podHost,
isLocal: this.isOwned(), isLocal: this.isOwned(),
@ -394,6 +410,7 @@ function toAddRemoteJSON (callback) {
const remoteVideo = { const remoteVideo = {
name: self.name, name: self.name,
category: self.category,
description: self.description, description: self.description,
infoHash: self.infoHash, infoHash: self.infoHash,
remoteId: self.id, remoteId: self.id,
@ -416,6 +433,7 @@ function toAddRemoteJSON (callback) {
function toUpdateRemoteJSON (callback) { function toUpdateRemoteJSON (callback) {
const json = { const json = {
name: this.name, name: this.name,
category: this.category,
description: this.description, description: this.description,
infoHash: this.infoHash, infoHash: this.infoHash,
remoteId: this.id, remoteId: this.id,

View file

@ -51,10 +51,11 @@ describe('Test users API validators', function () {
}, },
function (next) { function (next) {
const name = 'my super name for pod' const name = 'my super name for pod'
const category = 5
const description = 'my super description for pod' const description = 'my super description for pod'
const tags = [ 'tag' ] const tags = [ 'tag' ]
const file = 'video_short2.webm' const file = 'video_short2.webm'
videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
videosUtils.getVideosList(server.url, function (err, res) { videosUtils.getVideosList(server.url, function (err, res) {

View file

@ -62,10 +62,11 @@ describe('Test video abuses API validators', function () {
// Upload some videos on each pods // Upload some videos on each pods
function (next) { function (next) {
const name = 'my super name for pod' const name = 'my super name for pod'
const category = 2
const description = 'my super description for pod' const description = 'my super description for pod'
const tags = [ 'tag' ] const tags = [ 'tag' ]
const file = 'video_short2.webm' const file = 'video_short2.webm'
videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
videosUtils.getVideosList(server.url, function (err, res) { videosUtils.getVideosList(server.url, function (err, res) {

View file

@ -112,6 +112,7 @@ describe('Test videos API validator', function () {
it('Should fail without name', function (done) { it('Should fail without name', function (done) {
const data = { const data = {
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -124,6 +125,32 @@ describe('Test videos API 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',
category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
const attach = {
'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
}
requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
})
it('Should fail without a category', function (done) {
const data = {
name: 'my super name',
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
const attach = {
'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
}
requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
})
it('Should fail with a bad category', function (done) {
const data = {
name: 'my super name',
category: 125,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -136,6 +163,7 @@ describe('Test videos API 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',
category: 5,
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
const attach = { const attach = {
@ -147,6 +175,7 @@ describe('Test videos API validator', function () {
it('Should fail with a long description', function (done) { it('Should fail with a long description', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
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',
@ -161,6 +190,7 @@ describe('Test videos API validator', function () {
it('Should fail without tags', function (done) { it('Should fail without tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description' description: 'my super description'
} }
const attach = { const attach = {
@ -172,6 +202,7 @@ describe('Test videos API validator', function () {
it('Should fail with too many tags', function (done) { it('Should fail with too many tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
} }
@ -184,6 +215,7 @@ describe('Test videos API validator', function () {
it('Should fail with not enough tags', function (done) { it('Should fail with not enough tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ ] tags: [ ]
} }
@ -196,6 +228,7 @@ describe('Test videos API validator', function () {
it('Should fail with a tag length too low', function (done) { it('Should fail with a tag length too low', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 't' ] tags: [ 'tag1', 't' ]
} }
@ -208,6 +241,7 @@ describe('Test videos API validator', function () {
it('Should fail with a tag length too big', function (done) { it('Should fail with a tag length too big', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'mysupertagtoolong', 'tag1' ] tags: [ 'mysupertagtoolong', 'tag1' ]
} }
@ -220,6 +254,7 @@ describe('Test videos API validator', function () {
it('Should fail with malformed tags', function (done) { it('Should fail with malformed tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'my tag' ] tags: [ 'my tag' ]
} }
@ -232,6 +267,7 @@ describe('Test videos API 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',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -242,6 +278,7 @@ describe('Test videos API 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',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -254,6 +291,7 @@ describe('Test videos API 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',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -266,6 +304,7 @@ describe('Test videos API 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',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -302,6 +341,7 @@ describe('Test videos API validator', function () {
it('Should fail without a valid uuid', function (done) { it('Should fail without a valid uuid', function (done) {
const data = { const data = {
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -310,6 +350,7 @@ describe('Test videos API validator', function () {
it('Should fail with an unknown id', function (done) { it('Should fail with an unknown id', function (done) {
const data = { const data = {
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -319,6 +360,17 @@ describe('Test videos API 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',
category: 5,
description: 'my super description',
tags: [ 'tag1', 'tag2' ]
}
requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
})
it('Should fail with a bad category', function (done) {
const data = {
name: 'my super name',
category: 128,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2' ] tags: [ 'tag1', 'tag2' ]
} }
@ -328,6 +380,7 @@ describe('Test videos API validator', function () {
it('Should fail with a long description', function (done) { it('Should fail with a long description', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
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',
@ -339,6 +392,7 @@ describe('Test videos API validator', function () {
it('Should fail with too many tags', function (done) { it('Should fail with too many tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
} }
@ -348,6 +402,7 @@ describe('Test videos API validator', function () {
it('Should fail with not enough tags', function (done) { it('Should fail with not enough tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ ] tags: [ ]
} }
@ -357,6 +412,7 @@ describe('Test videos API validator', function () {
it('Should fail with a tag length too low', function (done) { it('Should fail with a tag length too low', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'tag1', 't' ] tags: [ 'tag1', 't' ]
} }
@ -366,6 +422,7 @@ describe('Test videos API validator', function () {
it('Should fail with a tag length too big', function (done) { it('Should fail with a tag length too big', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'mysupertagtoolong', 'tag1' ] tags: [ 'mysupertagtoolong', 'tag1' ]
} }
@ -375,6 +432,7 @@ describe('Test videos API validator', function () {
it('Should fail with malformed tags', function (done) { it('Should fail with malformed tags', function (done) {
const data = { const data = {
name: 'my super name', name: 'my super name',
category: 5,
description: 'my super description', description: 'my super description',
tags: [ 'my tag' ] tags: [ 'my tag' ]
} }

View file

@ -32,12 +32,13 @@ describe('Test advanced friends', function () {
function uploadVideo (podNumber, callback) { function uploadVideo (podNumber, callback) {
const name = 'my super video' const name = 'my super video'
const category = 5
const description = 'my super description' const description = 'my super description'
const tags = [ 'tag1', 'tag2' ] 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 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) return videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
} }
function getVideos (podNumber, callback) { function getVideos (podNumber, callback) {

View file

@ -81,10 +81,11 @@ describe('Test multiple pods', function () {
series([ series([
function (next) { function (next) {
const name = 'my super name for pod 1' const name = 'my super name for pod 1'
const category = 5
const description = 'my super description for pod 1' const description = 'my super description for pod 1'
const tags = [ 'tag1p1', 'tag2p1' ] const tags = [ 'tag1p1', 'tag2p1' ]
const file = 'video_short1.webm' const file = 'video_short1.webm'
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
setTimeout(next, 11000) setTimeout(next, 11000)
@ -104,6 +105,8 @@ describe('Test multiple pods', function () {
expect(videos.length).to.equal(1) expect(videos.length).to.equal(1)
const video = videos[0] const video = videos[0]
expect(video.name).to.equal('my super name for pod 1') expect(video.name).to.equal('my super name for pod 1')
expect(video.category).to.equal(5)
expect(video.categoryLabel).to.equal('Sports')
expect(video.description).to.equal('my super description for pod 1') expect(video.description).to.equal('my super description for pod 1')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
@ -144,10 +147,11 @@ describe('Test multiple pods', function () {
series([ series([
function (next) { function (next) {
const name = 'my super name for pod 2' const name = 'my super name for pod 2'
const category = 4
const description = 'my super description for pod 2' const description = 'my super description for pod 2'
const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
const file = 'video_short2.webm' const file = 'video_short2.webm'
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
setTimeout(next, 11000) setTimeout(next, 11000)
@ -167,6 +171,8 @@ describe('Test multiple pods', function () {
expect(videos.length).to.equal(2) expect(videos.length).to.equal(2)
const video = videos[1] const video = videos[1]
expect(video.name).to.equal('my super name for pod 2') expect(video.name).to.equal('my super name for pod 2')
expect(video.category).to.equal(4)
expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('my super description for pod 2') expect(video.description).to.equal('my super description for pod 2')
expect(video.podHost).to.equal('localhost:9002') expect(video.podHost).to.equal('localhost:9002')
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
@ -207,17 +213,19 @@ describe('Test multiple pods', function () {
series([ series([
function (next) { function (next) {
const name = 'my super name for pod 3' const name = 'my super name for pod 3'
const category = 6
const description = 'my super description for pod 3' const description = 'my super description for pod 3'
const tags = [ 'tag1p3' ] const tags = [ 'tag1p3' ]
const file = 'video_short3.webm' const file = 'video_short3.webm'
videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
const name = 'my super name for pod 3-2' const name = 'my super name for pod 3-2'
const category = 7
const description = 'my super description for pod 3-2' const description = 'my super description for pod 3-2'
const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
const file = 'video_short.webm' const file = 'video_short.webm'
videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
setTimeout(next, 22000) setTimeout(next, 22000)
@ -247,6 +255,8 @@ describe('Test multiple pods', function () {
} }
expect(video1.name).to.equal('my super name for pod 3') expect(video1.name).to.equal('my super name for pod 3')
expect(video1.category).to.equal(6)
expect(video1.categoryLabel).to.equal('Travels')
expect(video1.description).to.equal('my super description for pod 3') expect(video1.description).to.equal('my super description for pod 3')
expect(video1.podHost).to.equal('localhost:9003') expect(video1.podHost).to.equal('localhost:9003')
expect(video1.magnetUri).to.exist expect(video1.magnetUri).to.exist
@ -257,6 +267,8 @@ describe('Test multiple pods', function () {
expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true expect(miscsUtils.dateIsValid(video1.updatedAt)).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')
expect(video2.category).to.equal(7)
expect(video2.categoryLabel).to.equal('Gaming')
expect(video2.description).to.equal('my super description for pod 3-2') expect(video2.description).to.equal('my super description for pod 3-2')
expect(video2.podHost).to.equal('localhost:9003') expect(video2.podHost).to.equal('localhost:9003')
expect(video2.magnetUri).to.exist expect(video2.magnetUri).to.exist
@ -603,10 +615,11 @@ describe('Test multiple pods', function () {
this.timeout(15000) this.timeout(15000)
const name = 'my super video updated' const name = 'my super video updated'
const category = 10
const description = 'my super description updated' const description = 'my super description updated'
const tags = [ 'tagup1', 'tagup2' ] const tags = [ 'tagup1', 'tagup2' ]
videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) { videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, category, description, tags, function (err) {
if (err) throw err if (err) throw err
setTimeout(done, 11000) setTimeout(done, 11000)
@ -629,6 +642,8 @@ describe('Test multiple pods', function () {
}) })
expect(!!videoUpdated).to.be.true expect(!!videoUpdated).to.be.true
expect(videoUpdated.category).to.equal(10)
expect(videoUpdated.categoryLabel).to.equal('Entertainment')
expect(videoUpdated.description).to.equal('my super description updated') expect(videoUpdated.description).to.equal('my super description updated')
expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true

View file

@ -18,11 +18,12 @@ describe('Test requests stats', function () {
function uploadVideo (server, callback) { function uploadVideo (server, callback) {
const name = 'my super video' const name = 'my super video'
const category = 5
const description = 'my super description' const description = 'my super description'
const tags = [ 'tag1', 'tag2' ] const tags = [ 'tag1', 'tag2' ]
const fixture = 'video_short.webm' const fixture = 'video_short.webm'
videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
} }
function getRequestsStats (server, callback) { function getRequestsStats (server, callback) {

View file

@ -44,6 +44,19 @@ describe('Test a single pod', function () {
], done) ], done)
}) })
it('Should list video categories', function (done) {
videosUtils.getVideoCategories(server.url, function (err, res) {
if (err) throw err
const categories = res.body
expect(Object.keys(categories)).to.have.length.above(10)
expect(categories[11]).to.equal('News')
done()
})
})
it('Should not have videos', function (done) { it('Should not have videos', function (done) {
videosUtils.getVideosList(server.url, function (err, res) { videosUtils.getVideosList(server.url, function (err, res) {
if (err) throw err if (err) throw err
@ -60,9 +73,10 @@ describe('Test a single pod', function () {
this.timeout(5000) this.timeout(5000)
const name = 'my super name' const name = 'my super name'
const description = 'my super description' const description = 'my super description'
const category = 2
const tags = [ 'tag1', 'tag2', 'tag3' ] const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm' const file = 'video_short.webm'
videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, done)
}) })
it('Should seed the uploaded video', function (done) { it('Should seed the uploaded video', function (done) {
@ -78,6 +92,8 @@ describe('Test a single pod', function () {
const video = res.body.data[0] const video = res.body.data[0]
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.category).to.equal(2)
expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description') expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
@ -113,6 +129,8 @@ describe('Test a single pod', function () {
const video = res.body const video = res.body
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.category).to.equal(2)
expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description') expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.magnetUri).to.exist expect(video.magnetUri).to.exist
@ -152,6 +170,8 @@ describe('Test a single pod', function () {
const video = res.body.data[0] const video = res.body.data[0]
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.category).to.equal(2)
expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description') expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
@ -207,6 +227,8 @@ describe('Test a single pod', function () {
const video = res.body.data[0] const video = res.body.data[0]
expect(video.name).to.equal('my super name') expect(video.name).to.equal('my super name')
expect(video.category).to.equal(2)
expect(video.categoryLabel).to.equal('Films')
expect(video.description).to.equal('my super description') expect(video.description).to.equal('my super description')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
@ -301,9 +323,10 @@ describe('Test a single pod', function () {
each(videos, function (video, callbackEach) { each(videos, function (video, callbackEach) {
const name = video + ' name' const name = video + ' name'
const description = video + ' description' const description = video + ' description'
const category = 2
const tags = [ 'tag1', 'tag2', 'tag3' ] const tags = [ 'tag1', 'tag2', 'tag3' ]
videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, video, callbackEach)
}, done) }, done)
}) })
@ -468,7 +491,7 @@ describe('Test a single pod', function () {
// }) // })
// }) // })
it('Should search the good magnetUri video', function (done) { it('Should search the right magnetUri video', function (done) {
const video = videosListBase[0] const video = videosListBase[0]
videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
if (err) throw err if (err) throw err
@ -521,10 +544,11 @@ describe('Test a single pod', function () {
it('Should update a video', function (done) { it('Should update a video', function (done) {
const name = 'my super video updated' const name = 'my super video updated'
const category = 4
const description = 'my super description updated' const description = 'my super description updated'
const tags = [ 'tagup1', 'tagup2' ] const tags = [ 'tagup1', 'tagup2' ]
videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done) videosUtils.updateVideo(server.url, server.accessToken, videoId, name, category, description, tags, done)
}) })
it('Should have the video updated', function (done) { it('Should have the video updated', function (done) {
@ -536,6 +560,8 @@ describe('Test a single pod', function () {
const video = res.body const video = res.body
expect(video.name).to.equal('my super video updated') expect(video.name).to.equal('my super video updated')
expect(video.category).to.equal(4)
expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('my super description updated') expect(video.description).to.equal('my super description updated')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
@ -562,7 +588,7 @@ describe('Test a single pod', function () {
it('Should update only the tags of a video', function (done) { it('Should update only the tags of a video', function (done) {
const tags = [ 'tag1', 'tag2', 'supertag' ] const tags = [ 'tag1', 'tag2', 'supertag' ]
videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) { videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, null, tags, function (err) {
if (err) throw err if (err) throw err
videosUtils.getVideo(server.url, videoId, function (err, res) { videosUtils.getVideo(server.url, videoId, function (err, res) {
@ -571,6 +597,8 @@ describe('Test a single pod', function () {
const video = res.body const video = res.body
expect(video.name).to.equal('my super video updated') expect(video.name).to.equal('my super video updated')
expect(video.category).to.equal(4)
expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('my super description updated') expect(video.description).to.equal('my super description updated')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')
@ -587,7 +615,7 @@ describe('Test a single pod', function () {
it('Should update only the description of a video', function (done) { it('Should update only the description of a video', function (done) {
const description = 'hello everybody' const description = 'hello everybody'
videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) { videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, description, null, function (err) {
if (err) throw err if (err) throw err
videosUtils.getVideo(server.url, videoId, function (err, res) { videosUtils.getVideo(server.url, videoId, function (err, res) {
@ -596,6 +624,8 @@ describe('Test a single pod', function () {
const video = res.body const video = res.body
expect(video.name).to.equal('my super video updated') expect(video.name).to.equal('my super video updated')
expect(video.category).to.equal(4)
expect(video.categoryLabel).to.equal('Art')
expect(video.description).to.equal('hello everybody') expect(video.description).to.equal('hello everybody')
expect(video.podHost).to.equal('localhost:9001') expect(video.podHost).to.equal('localhost:9001')
expect(video.author).to.equal('root') expect(video.author).to.equal('root')

View file

@ -87,9 +87,10 @@ describe('Test users', function () {
const name = 'my super name' const name = 'my super name'
const description = 'my super description' const description = 'my super description'
const category = 5
const tags = [ 'tag1', 'tag2' ] const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm' const video = 'video_short.webm'
videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done) videosUtils.uploadVideo(server.url, accessToken, name, category, 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) {
@ -113,10 +114,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) {
const name = 'my super name' const name = 'my super name'
const category = 5
const description = 'my super description' const description = 'my super description'
const tags = [ 'tag1', 'tag2' ] const tags = [ 'tag1', 'tag2' ]
const video = 'video_short.webm' const video = 'video_short.webm'
videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) { videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, function (err, res) {
if (err) throw err if (err) throw err
videosUtils.getVideosList(server.url, function (err, res) { videosUtils.getVideosList(server.url, function (err, res) {
@ -133,10 +135,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) {
const name = 'my super name 2' const name = 'my super name 2'
const category = 5
const description = 'my super description 2' const description = 'my super description 2'
const tags = [ 'tag1' ] const tags = [ 'tag1' ]
const video = 'video_short.webm' const video = 'video_short.webm'
videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, done)
}) })
it('Should retrieve a video rating', function (done) { it('Should retrieve a video rating', function (done) {
@ -228,10 +231,11 @@ describe('Test users', function () {
this.timeout(5000) this.timeout(5000)
const name = 'my super name' const name = 'my super name'
const category = 5
const description = 'my super description' const description = 'my super description'
const tags = [ 'tag1', 'tag2', 'tag3' ] const tags = [ 'tag1', 'tag2', 'tag3' ]
const file = 'video_short.webm' const file = 'video_short.webm'
videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done) videosUtils.uploadVideo(server.url, accessTokenUser, name, category, description, tags, file, done)
}) })
it('Should list all the users', function (done) { it('Should list all the users', function (done) {

View file

@ -46,17 +46,19 @@ describe('Test video abuses', function () {
// Upload some videos on each pods // Upload some videos on each pods
function (next) { function (next) {
const name = 'my super name for pod 1' const name = 'my super name for pod 1'
const category = 5
const description = 'my super description for pod 1' const description = 'my super description for pod 1'
const tags = [ 'tag' ] const tags = [ 'tag' ]
const file = 'video_short2.webm' const file = 'video_short2.webm'
videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
}, },
function (next) { function (next) {
const name = 'my super name for pod 2' const name = 'my super name for pod 2'
const category = 5
const description = 'my super description for pod 2' const description = 'my super description for pod 2'
const tags = [ 'tag' ] const tags = [ 'tag' ]
const file = 'video_short2.webm' const file = 'video_short2.webm'
videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
}, },
// Wait videos propagation // Wait videos propagation
function (next) { function (next) {

View file

@ -201,13 +201,14 @@ function upload (servers, numServer, callback) {
if (!callback) callback = function () {} if (!callback) callback = function () {}
const name = Date.now() + ' name' const name = Date.now() + ' name'
const category = 4
const description = Date.now() + ' description' const description = Date.now() + ' description'
const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
const file = 'video_short1.webm' const file = 'video_short1.webm'
console.log('Uploading video to server ' + numServer) console.log('Uploading video to server ' + numServer)
videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, category, description, tags, file, callback)
} }
function update (servers, numServer, callback) { function update (servers, numServer, callback) {

View file

@ -9,6 +9,7 @@ program
.option('-u, --url <url>', 'Server url') .option('-u, --url <url>', 'Server url')
.option('-a, --access-token <token>', 'Access token') .option('-a, --access-token <token>', 'Access token')
.option('-n, --name <name>', 'Video name') .option('-n, --name <name>', 'Video name')
.option('-d, --category <category number>', 'Category number')
.option('-d, --description <description>', 'Video description') .option('-d, --description <description>', 'Video description')
.option('-t, --tags <tags>', 'Video tags', list) .option('-t, --tags <tags>', 'Video tags', list)
.option('-f, --file <file>', 'Video absolute file path') .option('-f, --file <file>', 'Video absolute file path')
@ -18,6 +19,7 @@ if (
!program.url || !program.url ||
!program.accessToken || !program.accessToken ||
!program.name || !program.name ||
!program.category ||
!program.description || !program.description ||
!program.tags || !program.tags ||
!Array.isArray(program.tags) || !Array.isArray(program.tags) ||
@ -34,6 +36,7 @@ fs.access(program.file, fs.F_OK, function (err) {
program.url, program.url,
program.accessToken, program.accessToken,
program.name, program.name,
program.category,
program.description, program.description,
program.tags, program.tags,
program.file program.file
@ -46,10 +49,10 @@ function list (val) {
return val.split(',') return val.split(',')
} }
function upload (url, accessToken, name, description, tags, file) { function upload (url, accessToken, name, category, description, tags, file) {
console.log('Uploading %s video...', program.name) console.log('Uploading %s video...', program.name)
utils.uploadVideo(url, accessToken, name, description, tags, file, function (err) { utils.uploadVideo(url, accessToken, name, category, description, tags, file, function (err) {
if (err) throw err if (err) throw err
console.log('Video uploaded.') console.log('Video uploaded.')

View file

@ -5,6 +5,7 @@ const pathUtils = require('path')
const request = require('supertest') const request = require('supertest')
const videosUtils = { const videosUtils = {
getVideoCategories,
getAllVideosListBy, getAllVideosListBy,
getVideo, getVideo,
getVideosList, getVideosList,
@ -22,6 +23,17 @@ const videosUtils = {
// ---------------------- Export functions -------------------- // ---------------------- Export functions --------------------
function getVideoCategories (url, end) {
const path = '/api/v1/videos/categories'
request(url)
.get(path)
.set('Accept', 'application/json')
.expect(200)
.expect('Content-Type', /json/)
.end(end)
}
function getAllVideosListBy (url, end) { function getAllVideosListBy (url, end) {
const path = '/api/v1/videos' const path = '/api/v1/videos'
@ -181,7 +193,7 @@ function testVideoImage (url, videoName, imagePath, callback) {
} }
} }
function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) { function uploadVideo (url, accessToken, name, category, description, tags, fixture, specialStatus, end) {
if (!end) { if (!end) {
end = specialStatus end = specialStatus
specialStatus = 204 specialStatus = 204
@ -194,6 +206,7 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
.set('Accept', 'application/json') .set('Accept', 'application/json')
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
.field('name', name) .field('name', name)
.field('category', category)
.field('description', description) .field('description', description)
for (let i = 0; i < tags.length; i++) { for (let i = 0; i < tags.length; i++) {
@ -212,7 +225,7 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
.end(end) .end(end)
} }
function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) { function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) {
if (!end) { if (!end) {
end = specialStatus end = specialStatus
specialStatus = 204 specialStatus = 204
@ -226,6 +239,7 @@ function updateVideo (url, accessToken, id, name, description, tags, specialStat
.set('Authorization', 'Bearer ' + accessToken) .set('Authorization', 'Bearer ' + accessToken)
if (name) req.field('name', name) if (name) req.field('name', name)
if (category) req.field('category', category)
if (description) req.field('description', description) if (description) req.field('description', description)
if (tags) { if (tags) {