aboutsummaryrefslogtreecommitdiffhomepage
path: root/server
diff options
context:
space:
mode:
Diffstat (limited to 'server')
-rw-r--r--server/controllers/api/remote/videos.js2
-rw-r--r--server/controllers/api/videos.js8
-rw-r--r--server/helpers/custom-validators/remote/videos.js1
-rw-r--r--server/helpers/custom-validators/videos.js5
-rw-r--r--server/initializers/constants.js24
-rw-r--r--server/initializers/migrations/0030-video-category.js34
-rw-r--r--server/middlewares/validators/videos.js2
-rw-r--r--server/models/video.js18
-rw-r--r--server/tests/api/check-params/users.js3
-rw-r--r--server/tests/api/check-params/video-abuses.js3
-rw-r--r--server/tests/api/check-params/videos.js58
-rw-r--r--server/tests/api/friends-advanced.js3
-rw-r--r--server/tests/api/multiple-pods.js25
-rw-r--r--server/tests/api/requests.js3
-rw-r--r--server/tests/api/single-pod.js42
-rw-r--r--server/tests/api/users.js12
-rw-r--r--server/tests/api/video-abuse.js6
-rw-r--r--server/tests/real-world/real-world.js3
-rw-r--r--server/tests/real-world/tools/upload.js7
-rw-r--r--server/tests/utils/videos.js18
20 files changed, 250 insertions, 27 deletions
diff --git a/server/controllers/api/remote/videos.js b/server/controllers/api/remote/videos.js
index cbd58e0e4..c8ef0c445 100644
--- a/server/controllers/api/remote/videos.js
+++ b/server/controllers/api/remote/videos.js
@@ -294,6 +294,7 @@ function addRemoteVideo (videoToCreateData, fromPod, finalCallback) {
294 remoteId: videoToCreateData.remoteId, 294 remoteId: videoToCreateData.remoteId,
295 extname: videoToCreateData.extname, 295 extname: videoToCreateData.extname,
296 infoHash: videoToCreateData.infoHash, 296 infoHash: videoToCreateData.infoHash,
297 category: videoToCreateData.category,
297 description: videoToCreateData.description, 298 description: videoToCreateData.description,
298 authorId: author.id, 299 authorId: author.id,
299 duration: videoToCreateData.duration, 300 duration: videoToCreateData.duration,
@@ -390,6 +391,7 @@ function updateRemoteVideo (videoAttributesToUpdate, fromPod, finalCallback) {
390 const options = { transaction: t } 391 const options = { transaction: t }
391 392
392 videoInstance.set('name', videoAttributesToUpdate.name) 393 videoInstance.set('name', videoAttributesToUpdate.name)
394 videoInstance.set('category', videoAttributesToUpdate.category)
393 videoInstance.set('description', videoAttributesToUpdate.description) 395 videoInstance.set('description', videoAttributesToUpdate.description)
394 videoInstance.set('infoHash', videoAttributesToUpdate.infoHash) 396 videoInstance.set('infoHash', videoAttributesToUpdate.infoHash)
395 videoInstance.set('duration', videoAttributesToUpdate.duration) 397 videoInstance.set('duration', videoAttributesToUpdate.duration)
diff --git a/server/controllers/api/videos.js b/server/controllers/api/videos.js
index 9acdb8fd2..8c69ff4e5 100644
--- a/server/controllers/api/videos.js
+++ b/server/controllers/api/videos.js
@@ -45,6 +45,8 @@ const storage = multer.diskStorage({
45 45
46const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }]) 46const reqFiles = multer({ storage: storage }).fields([{ name: 'videofile', maxCount: 1 }])
47 47
48router.get('/categories', listVideoCategories)
49
48router.get('/abuse', 50router.get('/abuse',
49 oAuth.authenticate, 51 oAuth.authenticate,
50 admin.ensureIsAdmin, 52 admin.ensureIsAdmin,
@@ -110,6 +112,10 @@ module.exports = router
110 112
111// --------------------------------------------------------------------------- 113// ---------------------------------------------------------------------------
112 114
115function listVideoCategories (req, res, next) {
116 res.json(constants.VIDEO_CATEGORIES)
117}
118
113function rateVideoRetryWrapper (req, res, next) { 119function rateVideoRetryWrapper (req, res, next) {
114 const options = { 120 const options = {
115 arguments: [ req, res ], 121 arguments: [ req, res ],
@@ -300,6 +306,7 @@ function addVideo (req, res, videoFile, finalCallback) {
300 name: videoInfos.name, 306 name: videoInfos.name,
301 remoteId: null, 307 remoteId: null,
302 extname: path.extname(videoFile.filename), 308 extname: path.extname(videoFile.filename),
309 category: videoInfos.category,
303 description: videoInfos.description, 310 description: videoInfos.description,
304 duration: videoFile.duration, 311 duration: videoFile.duration,
305 authorId: author.id 312 authorId: author.id
@@ -413,6 +420,7 @@ function updateVideo (req, res, finalCallback) {
413 } 420 }
414 421
415 if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name) 422 if (videoInfosToUpdate.name) videoInstance.set('name', videoInfosToUpdate.name)
423 if (videoInfosToUpdate.category) videoInstance.set('category', videoInfosToUpdate.category)
416 if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description) 424 if (videoInfosToUpdate.description) videoInstance.set('description', videoInfosToUpdate.description)
417 425
418 videoInstance.save(options).asCallback(function (err) { 426 videoInstance.save(options).asCallback(function (err) {
diff --git a/server/helpers/custom-validators/remote/videos.js b/server/helpers/custom-validators/remote/videos.js
index e1636e0e6..701acdbfd 100644
--- a/server/helpers/custom-validators/remote/videos.js
+++ b/server/helpers/custom-validators/remote/videos.js
@@ -85,6 +85,7 @@ module.exports = remoteVideosValidators
85function isCommonVideoAttributesValid (video) { 85function isCommonVideoAttributesValid (video) {
86 return videosValidators.isVideoDateValid(video.createdAt) && 86 return videosValidators.isVideoDateValid(video.createdAt) &&
87 videosValidators.isVideoDateValid(video.updatedAt) && 87 videosValidators.isVideoDateValid(video.updatedAt) &&
88 videosValidators.isVideoCategoryValid(video.category) &&
88 videosValidators.isVideoDescriptionValid(video.description) && 89 videosValidators.isVideoDescriptionValid(video.description) &&
89 videosValidators.isVideoDurationValid(video.duration) && 90 videosValidators.isVideoDurationValid(video.duration) &&
90 videosValidators.isVideoInfoHashValid(video.infoHash) && 91 videosValidators.isVideoInfoHashValid(video.infoHash) &&
diff --git a/server/helpers/custom-validators/videos.js b/server/helpers/custom-validators/videos.js
index 648c7540b..92b366717 100644
--- a/server/helpers/custom-validators/videos.js
+++ b/server/helpers/custom-validators/videos.js
@@ -13,6 +13,7 @@ const VIDEO_EVENTS_CONSTRAINTS_FIELDS = constants.CONSTRAINTS_FIELDS.VIDEO_EVENT
13const videosValidators = { 13const videosValidators = {
14 isVideoAuthorValid, 14 isVideoAuthorValid,
15 isVideoDateValid, 15 isVideoDateValid,
16 isVideoCategoryValid,
16 isVideoDescriptionValid, 17 isVideoDescriptionValid,
17 isVideoDurationValid, 18 isVideoDurationValid,
18 isVideoInfoHashValid, 19 isVideoInfoHashValid,
@@ -40,6 +41,10 @@ function isVideoDateValid (value) {
40 return validator.isDate(value) 41 return validator.isDate(value)
41} 42}
42 43
44function isVideoCategoryValid (value) {
45 return constants.VIDEO_CATEGORIES[value] !== undefined
46}
47
43function isVideoDescriptionValid (value) { 48function isVideoDescriptionValid (value) {
44 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION) 49 return validator.isLength(value, VIDEOS_CONSTRAINTS_FIELDS.DESCRIPTION)
45} 50}
diff --git a/server/initializers/constants.js b/server/initializers/constants.js
index 96321b211..6c5287b19 100644
--- a/server/initializers/constants.js
+++ b/server/initializers/constants.js
@@ -5,7 +5,7 @@ const path = require('path')
5 5
6// --------------------------------------------------------------------------- 6// ---------------------------------------------------------------------------
7 7
8const LAST_MIGRATION_VERSION = 25 8const LAST_MIGRATION_VERSION = 30
9 9
10// --------------------------------------------------------------------------- 10// ---------------------------------------------------------------------------
11 11
@@ -103,6 +103,27 @@ const VIDEO_RATE_TYPES = {
103 DISLIKE: 'dislike' 103 DISLIKE: 'dislike'
104} 104}
105 105
106const VIDEO_CATEGORIES = {
107 1: 'Music',
108 2: 'Films',
109 3: 'Vehicles',
110 4: 'Art',
111 5: 'Sports',
112 6: 'Travels',
113 7: 'Gaming',
114 8: 'People',
115 9: 'Comedy',
116 10: 'Entertainment',
117 11: 'News',
118 12: 'Howto',
119 13: 'Education',
120 14: 'Activism',
121 15: 'Science & Technology',
122 16: 'Animals',
123 17: 'Kids',
124 18: 'Food'
125}
126
106// --------------------------------------------------------------------------- 127// ---------------------------------------------------------------------------
107 128
108// Score a pod has when we create it as a friend 129// Score a pod has when we create it as a friend
@@ -258,6 +279,7 @@ module.exports = {
258 STATIC_PATHS, 279 STATIC_PATHS,
259 THUMBNAILS_SIZE, 280 THUMBNAILS_SIZE,
260 USER_ROLES, 281 USER_ROLES,
282 VIDEO_CATEGORIES,
261 VIDEO_RATE_TYPES 283 VIDEO_RATE_TYPES
262} 284}
263 285
diff --git a/server/initializers/migrations/0030-video-category.js b/server/initializers/migrations/0030-video-category.js
new file mode 100644
index 000000000..ada95b2fe
--- /dev/null
+++ b/server/initializers/migrations/0030-video-category.js
@@ -0,0 +1,34 @@
1'use strict'
2
3const waterfall = require('async/waterfall')
4
5// utils = { transaction, queryInterface, sequelize, Sequelize }
6exports.up = function (utils, finalCallback) {
7 const q = utils.queryInterface
8 const Sequelize = utils.Sequelize
9
10 const data = {
11 type: Sequelize.INTEGER,
12 allowNull: false,
13 defaultValue: 0
14 }
15
16 waterfall([
17
18 function addCategoryColumn (callback) {
19 q.addColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(function (err) {
20 return callback(err)
21 })
22 },
23
24 function nullOnDefault (callback) {
25 data.defaultValue = null
26
27 q.changeColumn('Videos', 'category', data, { transaction: utils.transaction }).asCallback(callback)
28 }
29 ], finalCallback)
30}
31
32exports.down = function (options, callback) {
33 throw new Error('Not implemented.')
34}
diff --git a/server/middlewares/validators/videos.js b/server/middlewares/validators/videos.js
index 7dc79c56f..37cc13372 100644
--- a/server/middlewares/validators/videos.js
+++ b/server/middlewares/validators/videos.js
@@ -21,6 +21,7 @@ const validatorsVideos = {
21function videosAdd (req, res, next) { 21function videosAdd (req, res, next) {
22 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files) 22 req.checkBody('videofile', 'Should have a valid file').isVideoFile(req.files)
23 req.checkBody('name', 'Should have a valid name').isVideoNameValid() 23 req.checkBody('name', 'Should have a valid name').isVideoNameValid()
24 req.checkBody('category', 'Should have a valid category').isVideoCategoryValid()
24 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid() 25 req.checkBody('description', 'Should have a valid description').isVideoDescriptionValid()
25 req.checkBody('tags', 'Should have correct tags').isVideoTagsValid() 26 req.checkBody('tags', 'Should have correct tags').isVideoTagsValid()
26 27
@@ -47,6 +48,7 @@ function videosAdd (req, res, next) {
47function videosUpdate (req, res, next) { 48function videosUpdate (req, res, next) {
48 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4) 49 req.checkParams('id', 'Should have a valid id').notEmpty().isUUID(4)
49 req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid() 50 req.checkBody('name', 'Should have a valid name').optional().isVideoNameValid()
51 req.checkBody('category', 'Should have a valid category').optional().isVideoCategoryValid()
50 req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid() 52 req.checkBody('description', 'Should have a valid description').optional().isVideoDescriptionValid()
51 req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid() 53 req.checkBody('tags', 'Should have correct tags').optional().isVideoTagsValid()
52 54
diff --git a/server/models/video.js b/server/models/video.js
index 182555c85..c4c7b5de8 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -51,6 +51,16 @@ module.exports = function (sequelize, DataTypes) {
51 isUUID: 4 51 isUUID: 4
52 } 52 }
53 }, 53 },
54 category: {
55 type: DataTypes.INTEGER,
56 allowNull: false,
57 validate: {
58 categoryValid: function (value) {
59 const res = customVideosValidators.isVideoCategoryValid(value)
60 if (res === false) throw new Error('Video category is not valid.')
61 }
62 }
63 },
54 description: { 64 description: {
55 type: DataTypes.STRING, 65 type: DataTypes.STRING,
56 allowNull: false, 66 allowNull: false,
@@ -360,9 +370,15 @@ function toFormatedJSON () {
360 podHost = constants.CONFIG.WEBSERVER.HOST 370 podHost = constants.CONFIG.WEBSERVER.HOST
361 } 371 }
362 372
373 // Maybe our pod is not up to date and there are new categories since our version
374 let categoryLabel = constants.VIDEO_CATEGORIES[this.category]
375 if (!categoryLabel) categoryLabel = 'Misc'
376
363 const json = { 377 const json = {
364 id: this.id, 378 id: this.id,
365 name: this.name, 379 name: this.name,
380 category: this.category,
381 categoryLabel,
366 description: this.description, 382 description: this.description,
367 podHost, 383 podHost,
368 isLocal: this.isOwned(), 384 isLocal: this.isOwned(),
@@ -394,6 +410,7 @@ function toAddRemoteJSON (callback) {
394 410
395 const remoteVideo = { 411 const remoteVideo = {
396 name: self.name, 412 name: self.name,
413 category: self.category,
397 description: self.description, 414 description: self.description,
398 infoHash: self.infoHash, 415 infoHash: self.infoHash,
399 remoteId: self.id, 416 remoteId: self.id,
@@ -416,6 +433,7 @@ function toAddRemoteJSON (callback) {
416function toUpdateRemoteJSON (callback) { 433function toUpdateRemoteJSON (callback) {
417 const json = { 434 const json = {
418 name: this.name, 435 name: this.name,
436 category: this.category,
419 description: this.description, 437 description: this.description,
420 infoHash: this.infoHash, 438 infoHash: this.infoHash,
421 remoteId: this.id, 439 remoteId: this.id,
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js
index 11e2bada4..f6fbcf555 100644
--- a/server/tests/api/check-params/users.js
+++ b/server/tests/api/check-params/users.js
@@ -51,10 +51,11 @@ describe('Test users API validators', function () {
51 }, 51 },
52 function (next) { 52 function (next) {
53 const name = 'my super name for pod' 53 const name = 'my super name for pod'
54 const category = 5
54 const description = 'my super description for pod' 55 const description = 'my super description for pod'
55 const tags = [ 'tag' ] 56 const tags = [ 'tag' ]
56 const file = 'video_short2.webm' 57 const file = 'video_short2.webm'
57 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) 58 videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
58 }, 59 },
59 function (next) { 60 function (next) {
60 videosUtils.getVideosList(server.url, function (err, res) { 61 videosUtils.getVideosList(server.url, function (err, res) {
diff --git a/server/tests/api/check-params/video-abuses.js b/server/tests/api/check-params/video-abuses.js
index 7308637e2..061b80be8 100644
--- a/server/tests/api/check-params/video-abuses.js
+++ b/server/tests/api/check-params/video-abuses.js
@@ -62,10 +62,11 @@ describe('Test video abuses API validators', function () {
62 // Upload some videos on each pods 62 // Upload some videos on each pods
63 function (next) { 63 function (next) {
64 const name = 'my super name for pod' 64 const name = 'my super name for pod'
65 const category = 2
65 const description = 'my super description for pod' 66 const description = 'my super description for pod'
66 const tags = [ 'tag' ] 67 const tags = [ 'tag' ]
67 const file = 'video_short2.webm' 68 const file = 'video_short2.webm'
68 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next) 69 videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, next)
69 }, 70 },
70 function (next) { 71 function (next) {
71 videosUtils.getVideosList(server.url, function (err, res) { 72 videosUtils.getVideosList(server.url, function (err, res) {
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js
index 0f5f40b8e..fbfe6f137 100644
--- a/server/tests/api/check-params/videos.js
+++ b/server/tests/api/check-params/videos.js
@@ -112,6 +112,7 @@ describe('Test videos API validator', function () {
112 112
113 it('Should fail without name', function (done) { 113 it('Should fail without name', function (done) {
114 const data = { 114 const data = {
115 category: 5,
115 description: 'my super description', 116 description: 'my super description',
116 tags: [ 'tag1', 'tag2' ] 117 tags: [ 'tag1', 'tag2' ]
117 } 118 }
@@ -124,6 +125,32 @@ describe('Test videos API validator', function () {
124 it('Should fail with a long name', function (done) { 125 it('Should fail with a long name', function (done) {
125 const data = { 126 const data = {
126 name: 'My very very very very very very very very very very very very very very very very long name', 127 name: 'My very very very very very very very very very very very very very very very very long name',
128 category: 5,
129 description: 'my super description',
130 tags: [ 'tag1', 'tag2' ]
131 }
132 const attach = {
133 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
134 }
135 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
136 })
137
138 it('Should fail without a category', function (done) {
139 const data = {
140 name: 'my super name',
141 description: 'my super description',
142 tags: [ 'tag1', 'tag2' ]
143 }
144 const attach = {
145 'videofile': pathUtils.join(__dirname, '..', 'fixtures', 'video_short.webm')
146 }
147 requestsUtils.makePostUploadRequest(server.url, path, server.accessToken, data, attach, done)
148 })
149
150 it('Should fail with a bad category', function (done) {
151 const data = {
152 name: 'my super name',
153 category: 125,
127 description: 'my super description', 154 description: 'my super description',
128 tags: [ 'tag1', 'tag2' ] 155 tags: [ 'tag1', 'tag2' ]
129 } 156 }
@@ -136,6 +163,7 @@ describe('Test videos API validator', function () {
136 it('Should fail without description', function (done) { 163 it('Should fail without description', function (done) {
137 const data = { 164 const data = {
138 name: 'my super name', 165 name: 'my super name',
166 category: 5,
139 tags: [ 'tag1', 'tag2' ] 167 tags: [ 'tag1', 'tag2' ]
140 } 168 }
141 const attach = { 169 const attach = {
@@ -147,6 +175,7 @@ describe('Test videos API validator', function () {
147 it('Should fail with a long description', function (done) { 175 it('Should fail with a long description', function (done) {
148 const data = { 176 const data = {
149 name: 'my super name', 177 name: 'my super name',
178 category: 5,
150 description: 'my super description which is very very very very very very very very very very very very very very' + 179 description: 'my super description which is very very very very very very very very very very very very very very' +
151 'very very very very very very very very very very very very very very very very very very very very very' + 180 'very very very very very very very very very very very very very very very very very very very very very' +
152 'very very very very very very very very very very very very very very very long', 181 '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 () {
161 it('Should fail without tags', function (done) { 190 it('Should fail without tags', function (done) {
162 const data = { 191 const data = {
163 name: 'my super name', 192 name: 'my super name',
193 category: 5,
164 description: 'my super description' 194 description: 'my super description'
165 } 195 }
166 const attach = { 196 const attach = {
@@ -172,6 +202,7 @@ describe('Test videos API validator', function () {
172 it('Should fail with too many tags', function (done) { 202 it('Should fail with too many tags', function (done) {
173 const data = { 203 const data = {
174 name: 'my super name', 204 name: 'my super name',
205 category: 5,
175 description: 'my super description', 206 description: 'my super description',
176 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] 207 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
177 } 208 }
@@ -184,6 +215,7 @@ describe('Test videos API validator', function () {
184 it('Should fail with not enough tags', function (done) { 215 it('Should fail with not enough tags', function (done) {
185 const data = { 216 const data = {
186 name: 'my super name', 217 name: 'my super name',
218 category: 5,
187 description: 'my super description', 219 description: 'my super description',
188 tags: [ ] 220 tags: [ ]
189 } 221 }
@@ -196,6 +228,7 @@ describe('Test videos API validator', function () {
196 it('Should fail with a tag length too low', function (done) { 228 it('Should fail with a tag length too low', function (done) {
197 const data = { 229 const data = {
198 name: 'my super name', 230 name: 'my super name',
231 category: 5,
199 description: 'my super description', 232 description: 'my super description',
200 tags: [ 'tag1', 't' ] 233 tags: [ 'tag1', 't' ]
201 } 234 }
@@ -208,6 +241,7 @@ describe('Test videos API validator', function () {
208 it('Should fail with a tag length too big', function (done) { 241 it('Should fail with a tag length too big', function (done) {
209 const data = { 242 const data = {
210 name: 'my super name', 243 name: 'my super name',
244 category: 5,
211 description: 'my super description', 245 description: 'my super description',
212 tags: [ 'mysupertagtoolong', 'tag1' ] 246 tags: [ 'mysupertagtoolong', 'tag1' ]
213 } 247 }
@@ -220,6 +254,7 @@ describe('Test videos API validator', function () {
220 it('Should fail with malformed tags', function (done) { 254 it('Should fail with malformed tags', function (done) {
221 const data = { 255 const data = {
222 name: 'my super name', 256 name: 'my super name',
257 category: 5,
223 description: 'my super description', 258 description: 'my super description',
224 tags: [ 'my tag' ] 259 tags: [ 'my tag' ]
225 } 260 }
@@ -232,6 +267,7 @@ describe('Test videos API validator', function () {
232 it('Should fail without an input file', function (done) { 267 it('Should fail without an input file', function (done) {
233 const data = { 268 const data = {
234 name: 'my super name', 269 name: 'my super name',
270 category: 5,
235 description: 'my super description', 271 description: 'my super description',
236 tags: [ 'tag1', 'tag2' ] 272 tags: [ 'tag1', 'tag2' ]
237 } 273 }
@@ -242,6 +278,7 @@ describe('Test videos API validator', function () {
242 it('Should fail without an incorrect input file', function (done) { 278 it('Should fail without an incorrect input file', function (done) {
243 const data = { 279 const data = {
244 name: 'my super name', 280 name: 'my super name',
281 category: 5,
245 description: 'my super description', 282 description: 'my super description',
246 tags: [ 'tag1', 'tag2' ] 283 tags: [ 'tag1', 'tag2' ]
247 } 284 }
@@ -254,6 +291,7 @@ describe('Test videos API validator', function () {
254 it('Should fail with a too big duration', function (done) { 291 it('Should fail with a too big duration', function (done) {
255 const data = { 292 const data = {
256 name: 'my super name', 293 name: 'my super name',
294 category: 5,
257 description: 'my super description', 295 description: 'my super description',
258 tags: [ 'tag1', 'tag2' ] 296 tags: [ 'tag1', 'tag2' ]
259 } 297 }
@@ -266,6 +304,7 @@ describe('Test videos API validator', function () {
266 it('Should succeed with the correct parameters', function (done) { 304 it('Should succeed with the correct parameters', function (done) {
267 const data = { 305 const data = {
268 name: 'my super name', 306 name: 'my super name',
307 category: 5,
269 description: 'my super description', 308 description: 'my super description',
270 tags: [ 'tag1', 'tag2' ] 309 tags: [ 'tag1', 'tag2' ]
271 } 310 }
@@ -302,6 +341,7 @@ describe('Test videos API validator', function () {
302 341
303 it('Should fail without a valid uuid', function (done) { 342 it('Should fail without a valid uuid', function (done) {
304 const data = { 343 const data = {
344 category: 5,
305 description: 'my super description', 345 description: 'my super description',
306 tags: [ 'tag1', 'tag2' ] 346 tags: [ 'tag1', 'tag2' ]
307 } 347 }
@@ -310,6 +350,7 @@ describe('Test videos API validator', function () {
310 350
311 it('Should fail with an unknown id', function (done) { 351 it('Should fail with an unknown id', function (done) {
312 const data = { 352 const data = {
353 category: 5,
313 description: 'my super description', 354 description: 'my super description',
314 tags: [ 'tag1', 'tag2' ] 355 tags: [ 'tag1', 'tag2' ]
315 } 356 }
@@ -319,6 +360,17 @@ describe('Test videos API validator', function () {
319 it('Should fail with a long name', function (done) { 360 it('Should fail with a long name', function (done) {
320 const data = { 361 const data = {
321 name: 'My very very very very very very very very very very very very very very very very long name', 362 name: 'My very very very very very very very very very very very very very very very very long name',
363 category: 5,
364 description: 'my super description',
365 tags: [ 'tag1', 'tag2' ]
366 }
367 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
368 })
369
370 it('Should fail with a bad category', function (done) {
371 const data = {
372 name: 'my super name',
373 category: 128,
322 description: 'my super description', 374 description: 'my super description',
323 tags: [ 'tag1', 'tag2' ] 375 tags: [ 'tag1', 'tag2' ]
324 } 376 }
@@ -328,6 +380,7 @@ describe('Test videos API validator', function () {
328 it('Should fail with a long description', function (done) { 380 it('Should fail with a long description', function (done) {
329 const data = { 381 const data = {
330 name: 'my super name', 382 name: 'my super name',
383 category: 5,
331 description: 'my super description which is very very very very very very very very very very very very very very' + 384 description: 'my super description which is very very very very very very very very very very very very very very' +
332 'very very very very very very very very very very very very very very very very very very very very very' + 385 'very very very very very very very very very very very very very very very very very very very very very' +
333 'very very very very very very very very very very very very very very very long', 386 '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 () {
339 it('Should fail with too many tags', function (done) { 392 it('Should fail with too many tags', function (done) {
340 const data = { 393 const data = {
341 name: 'my super name', 394 name: 'my super name',
395 category: 5,
342 description: 'my super description', 396 description: 'my super description',
343 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] 397 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
344 } 398 }
@@ -348,6 +402,7 @@ describe('Test videos API validator', function () {
348 it('Should fail with not enough tags', function (done) { 402 it('Should fail with not enough tags', function (done) {
349 const data = { 403 const data = {
350 name: 'my super name', 404 name: 'my super name',
405 category: 5,
351 description: 'my super description', 406 description: 'my super description',
352 tags: [ ] 407 tags: [ ]
353 } 408 }
@@ -357,6 +412,7 @@ describe('Test videos API validator', function () {
357 it('Should fail with a tag length too low', function (done) { 412 it('Should fail with a tag length too low', function (done) {
358 const data = { 413 const data = {
359 name: 'my super name', 414 name: 'my super name',
415 category: 5,
360 description: 'my super description', 416 description: 'my super description',
361 tags: [ 'tag1', 't' ] 417 tags: [ 'tag1', 't' ]
362 } 418 }
@@ -366,6 +422,7 @@ describe('Test videos API validator', function () {
366 it('Should fail with a tag length too big', function (done) { 422 it('Should fail with a tag length too big', function (done) {
367 const data = { 423 const data = {
368 name: 'my super name', 424 name: 'my super name',
425 category: 5,
369 description: 'my super description', 426 description: 'my super description',
370 tags: [ 'mysupertagtoolong', 'tag1' ] 427 tags: [ 'mysupertagtoolong', 'tag1' ]
371 } 428 }
@@ -375,6 +432,7 @@ describe('Test videos API validator', function () {
375 it('Should fail with malformed tags', function (done) { 432 it('Should fail with malformed tags', function (done) {
376 const data = { 433 const data = {
377 name: 'my super name', 434 name: 'my super name',
435 category: 5,
378 description: 'my super description', 436 description: 'my super description',
379 tags: [ 'my tag' ] 437 tags: [ 'my tag' ]
380 } 438 }
diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js
index 15ca1a37c..584c38c24 100644
--- a/server/tests/api/friends-advanced.js
+++ b/server/tests/api/friends-advanced.js
@@ -32,12 +32,13 @@ describe('Test advanced friends', function () {
32 32
33 function uploadVideo (podNumber, callback) { 33 function uploadVideo (podNumber, callback) {
34 const name = 'my super video' 34 const name = 'my super video'
35 const category = 5
35 const description = 'my super description' 36 const description = 'my super description'
36 const tags = [ 'tag1', 'tag2' ] 37 const tags = [ 'tag1', 'tag2' ]
37 const fixture = 'video_short.webm' 38 const fixture = 'video_short.webm'
38 const server = servers[podNumber - 1] 39 const server = servers[podNumber - 1]
39 40
40 return videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) 41 return videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
41 } 42 }
42 43
43 function getVideos (podNumber, callback) { 44 function getVideos (podNumber, callback) {
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js
index 552f10c6f..eccc9ecef 100644
--- a/server/tests/api/multiple-pods.js
+++ b/server/tests/api/multiple-pods.js
@@ -81,10 +81,11 @@ describe('Test multiple pods', function () {
81 series([ 81 series([
82 function (next) { 82 function (next) {
83 const name = 'my super name for pod 1' 83 const name = 'my super name for pod 1'
84 const category = 5
84 const description = 'my super description for pod 1' 85 const description = 'my super description for pod 1'
85 const tags = [ 'tag1p1', 'tag2p1' ] 86 const tags = [ 'tag1p1', 'tag2p1' ]
86 const file = 'video_short1.webm' 87 const file = 'video_short1.webm'
87 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) 88 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
88 }, 89 },
89 function (next) { 90 function (next) {
90 setTimeout(next, 11000) 91 setTimeout(next, 11000)
@@ -104,6 +105,8 @@ describe('Test multiple pods', function () {
104 expect(videos.length).to.equal(1) 105 expect(videos.length).to.equal(1)
105 const video = videos[0] 106 const video = videos[0]
106 expect(video.name).to.equal('my super name for pod 1') 107 expect(video.name).to.equal('my super name for pod 1')
108 expect(video.category).to.equal(5)
109 expect(video.categoryLabel).to.equal('Sports')
107 expect(video.description).to.equal('my super description for pod 1') 110 expect(video.description).to.equal('my super description for pod 1')
108 expect(video.podHost).to.equal('localhost:9001') 111 expect(video.podHost).to.equal('localhost:9001')
109 expect(video.magnetUri).to.exist 112 expect(video.magnetUri).to.exist
@@ -144,10 +147,11 @@ describe('Test multiple pods', function () {
144 series([ 147 series([
145 function (next) { 148 function (next) {
146 const name = 'my super name for pod 2' 149 const name = 'my super name for pod 2'
150 const category = 4
147 const description = 'my super description for pod 2' 151 const description = 'my super description for pod 2'
148 const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] 152 const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ]
149 const file = 'video_short2.webm' 153 const file = 'video_short2.webm'
150 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) 154 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
151 }, 155 },
152 function (next) { 156 function (next) {
153 setTimeout(next, 11000) 157 setTimeout(next, 11000)
@@ -167,6 +171,8 @@ describe('Test multiple pods', function () {
167 expect(videos.length).to.equal(2) 171 expect(videos.length).to.equal(2)
168 const video = videos[1] 172 const video = videos[1]
169 expect(video.name).to.equal('my super name for pod 2') 173 expect(video.name).to.equal('my super name for pod 2')
174 expect(video.category).to.equal(4)
175 expect(video.categoryLabel).to.equal('Art')
170 expect(video.description).to.equal('my super description for pod 2') 176 expect(video.description).to.equal('my super description for pod 2')
171 expect(video.podHost).to.equal('localhost:9002') 177 expect(video.podHost).to.equal('localhost:9002')
172 expect(video.magnetUri).to.exist 178 expect(video.magnetUri).to.exist
@@ -207,17 +213,19 @@ describe('Test multiple pods', function () {
207 series([ 213 series([
208 function (next) { 214 function (next) {
209 const name = 'my super name for pod 3' 215 const name = 'my super name for pod 3'
216 const category = 6
210 const description = 'my super description for pod 3' 217 const description = 'my super description for pod 3'
211 const tags = [ 'tag1p3' ] 218 const tags = [ 'tag1p3' ]
212 const file = 'video_short3.webm' 219 const file = 'video_short3.webm'
213 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) 220 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
214 }, 221 },
215 function (next) { 222 function (next) {
216 const name = 'my super name for pod 3-2' 223 const name = 'my super name for pod 3-2'
224 const category = 7
217 const description = 'my super description for pod 3-2' 225 const description = 'my super description for pod 3-2'
218 const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] 226 const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ]
219 const file = 'video_short.webm' 227 const file = 'video_short.webm'
220 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) 228 videosUtils.uploadVideo(servers[2].url, servers[2].accessToken, name, category, description, tags, file, next)
221 }, 229 },
222 function (next) { 230 function (next) {
223 setTimeout(next, 22000) 231 setTimeout(next, 22000)
@@ -247,6 +255,8 @@ describe('Test multiple pods', function () {
247 } 255 }
248 256
249 expect(video1.name).to.equal('my super name for pod 3') 257 expect(video1.name).to.equal('my super name for pod 3')
258 expect(video1.category).to.equal(6)
259 expect(video1.categoryLabel).to.equal('Travels')
250 expect(video1.description).to.equal('my super description for pod 3') 260 expect(video1.description).to.equal('my super description for pod 3')
251 expect(video1.podHost).to.equal('localhost:9003') 261 expect(video1.podHost).to.equal('localhost:9003')
252 expect(video1.magnetUri).to.exist 262 expect(video1.magnetUri).to.exist
@@ -257,6 +267,8 @@ describe('Test multiple pods', function () {
257 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true 267 expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true
258 268
259 expect(video2.name).to.equal('my super name for pod 3-2') 269 expect(video2.name).to.equal('my super name for pod 3-2')
270 expect(video2.category).to.equal(7)
271 expect(video2.categoryLabel).to.equal('Gaming')
260 expect(video2.description).to.equal('my super description for pod 3-2') 272 expect(video2.description).to.equal('my super description for pod 3-2')
261 expect(video2.podHost).to.equal('localhost:9003') 273 expect(video2.podHost).to.equal('localhost:9003')
262 expect(video2.magnetUri).to.exist 274 expect(video2.magnetUri).to.exist
@@ -603,10 +615,11 @@ describe('Test multiple pods', function () {
603 this.timeout(15000) 615 this.timeout(15000)
604 616
605 const name = 'my super video updated' 617 const name = 'my super video updated'
618 const category = 10
606 const description = 'my super description updated' 619 const description = 'my super description updated'
607 const tags = [ 'tagup1', 'tagup2' ] 620 const tags = [ 'tagup1', 'tagup2' ]
608 621
609 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, description, tags, function (err) { 622 videosUtils.updateVideo(servers[2].url, servers[2].accessToken, toRemove[0].id, name, category, description, tags, function (err) {
610 if (err) throw err 623 if (err) throw err
611 624
612 setTimeout(done, 11000) 625 setTimeout(done, 11000)
@@ -629,6 +642,8 @@ describe('Test multiple pods', function () {
629 }) 642 })
630 643
631 expect(!!videoUpdated).to.be.true 644 expect(!!videoUpdated).to.be.true
645 expect(videoUpdated.category).to.equal(10)
646 expect(videoUpdated.categoryLabel).to.equal('Entertainment')
632 expect(videoUpdated.description).to.equal('my super description updated') 647 expect(videoUpdated.description).to.equal('my super description updated')
633 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) 648 expect(videoUpdated.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
634 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true 649 expect(miscsUtils.dateIsValid(videoUpdated.updatedAt, 20000)).to.be.true
diff --git a/server/tests/api/requests.js b/server/tests/api/requests.js
index 215c2a8f3..b4b8393e3 100644
--- a/server/tests/api/requests.js
+++ b/server/tests/api/requests.js
@@ -18,11 +18,12 @@ describe('Test requests stats', function () {
18 18
19 function uploadVideo (server, callback) { 19 function uploadVideo (server, callback) {
20 const name = 'my super video' 20 const name = 'my super video'
21 const category = 5
21 const description = 'my super description' 22 const description = 'my super description'
22 const tags = [ 'tag1', 'tag2' ] 23 const tags = [ 'tag1', 'tag2' ]
23 const fixture = 'video_short.webm' 24 const fixture = 'video_short.webm'
24 25
25 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) 26 videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, fixture, callback)
26 } 27 }
27 28
28 function getRequestsStats (server, callback) { 29 function getRequestsStats (server, callback) {
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 96e4aff9e..d583592d8 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -44,6 +44,19 @@ describe('Test a single pod', function () {
44 ], done) 44 ], done)
45 }) 45 })
46 46
47 it('Should list video categories', function (done) {
48 videosUtils.getVideoCategories(server.url, function (err, res) {
49 if (err) throw err
50
51 const categories = res.body
52 expect(Object.keys(categories)).to.have.length.above(10)
53
54 expect(categories[11]).to.equal('News')
55
56 done()
57 })
58 })
59
47 it('Should not have videos', function (done) { 60 it('Should not have videos', function (done) {
48 videosUtils.getVideosList(server.url, function (err, res) { 61 videosUtils.getVideosList(server.url, function (err, res) {
49 if (err) throw err 62 if (err) throw err
@@ -60,9 +73,10 @@ describe('Test a single pod', function () {
60 this.timeout(5000) 73 this.timeout(5000)
61 const name = 'my super name' 74 const name = 'my super name'
62 const description = 'my super description' 75 const description = 'my super description'
76 const category = 2
63 const tags = [ 'tag1', 'tag2', 'tag3' ] 77 const tags = [ 'tag1', 'tag2', 'tag3' ]
64 const file = 'video_short.webm' 78 const file = 'video_short.webm'
65 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) 79 videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, file, done)
66 }) 80 })
67 81
68 it('Should seed the uploaded video', function (done) { 82 it('Should seed the uploaded video', function (done) {
@@ -78,6 +92,8 @@ describe('Test a single pod', function () {
78 92
79 const video = res.body.data[0] 93 const video = res.body.data[0]
80 expect(video.name).to.equal('my super name') 94 expect(video.name).to.equal('my super name')
95 expect(video.category).to.equal(2)
96 expect(video.categoryLabel).to.equal('Films')
81 expect(video.description).to.equal('my super description') 97 expect(video.description).to.equal('my super description')
82 expect(video.podHost).to.equal('localhost:9001') 98 expect(video.podHost).to.equal('localhost:9001')
83 expect(video.magnetUri).to.exist 99 expect(video.magnetUri).to.exist
@@ -113,6 +129,8 @@ describe('Test a single pod', function () {
113 129
114 const video = res.body 130 const video = res.body
115 expect(video.name).to.equal('my super name') 131 expect(video.name).to.equal('my super name')
132 expect(video.category).to.equal(2)
133 expect(video.categoryLabel).to.equal('Films')
116 expect(video.description).to.equal('my super description') 134 expect(video.description).to.equal('my super description')
117 expect(video.podHost).to.equal('localhost:9001') 135 expect(video.podHost).to.equal('localhost:9001')
118 expect(video.magnetUri).to.exist 136 expect(video.magnetUri).to.exist
@@ -152,6 +170,8 @@ describe('Test a single pod', function () {
152 170
153 const video = res.body.data[0] 171 const video = res.body.data[0]
154 expect(video.name).to.equal('my super name') 172 expect(video.name).to.equal('my super name')
173 expect(video.category).to.equal(2)
174 expect(video.categoryLabel).to.equal('Films')
155 expect(video.description).to.equal('my super description') 175 expect(video.description).to.equal('my super description')
156 expect(video.podHost).to.equal('localhost:9001') 176 expect(video.podHost).to.equal('localhost:9001')
157 expect(video.author).to.equal('root') 177 expect(video.author).to.equal('root')
@@ -207,6 +227,8 @@ describe('Test a single pod', function () {
207 227
208 const video = res.body.data[0] 228 const video = res.body.data[0]
209 expect(video.name).to.equal('my super name') 229 expect(video.name).to.equal('my super name')
230 expect(video.category).to.equal(2)
231 expect(video.categoryLabel).to.equal('Films')
210 expect(video.description).to.equal('my super description') 232 expect(video.description).to.equal('my super description')
211 expect(video.podHost).to.equal('localhost:9001') 233 expect(video.podHost).to.equal('localhost:9001')
212 expect(video.author).to.equal('root') 234 expect(video.author).to.equal('root')
@@ -301,9 +323,10 @@ describe('Test a single pod', function () {
301 each(videos, function (video, callbackEach) { 323 each(videos, function (video, callbackEach) {
302 const name = video + ' name' 324 const name = video + ' name'
303 const description = video + ' description' 325 const description = video + ' description'
326 const category = 2
304 const tags = [ 'tag1', 'tag2', 'tag3' ] 327 const tags = [ 'tag1', 'tag2', 'tag3' ]
305 328
306 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) 329 videosUtils.uploadVideo(server.url, server.accessToken, name, category, description, tags, video, callbackEach)
307 }, done) 330 }, done)
308 }) 331 })
309 332
@@ -468,7 +491,7 @@ describe('Test a single pod', function () {
468 // }) 491 // })
469 // }) 492 // })
470 493
471 it('Should search the good magnetUri video', function (done) { 494 it('Should search the right magnetUri video', function (done) {
472 const video = videosListBase[0] 495 const video = videosListBase[0]
473 videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { 496 videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
474 if (err) throw err 497 if (err) throw err
@@ -521,10 +544,11 @@ describe('Test a single pod', function () {
521 544
522 it('Should update a video', function (done) { 545 it('Should update a video', function (done) {
523 const name = 'my super video updated' 546 const name = 'my super video updated'
547 const category = 4
524 const description = 'my super description updated' 548 const description = 'my super description updated'
525 const tags = [ 'tagup1', 'tagup2' ] 549 const tags = [ 'tagup1', 'tagup2' ]
526 550
527 videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done) 551 videosUtils.updateVideo(server.url, server.accessToken, videoId, name, category, description, tags, done)
528 }) 552 })
529 553
530 it('Should have the video updated', function (done) { 554 it('Should have the video updated', function (done) {
@@ -536,6 +560,8 @@ describe('Test a single pod', function () {
536 const video = res.body 560 const video = res.body
537 561
538 expect(video.name).to.equal('my super video updated') 562 expect(video.name).to.equal('my super video updated')
563 expect(video.category).to.equal(4)
564 expect(video.categoryLabel).to.equal('Art')
539 expect(video.description).to.equal('my super description updated') 565 expect(video.description).to.equal('my super description updated')
540 expect(video.podHost).to.equal('localhost:9001') 566 expect(video.podHost).to.equal('localhost:9001')
541 expect(video.author).to.equal('root') 567 expect(video.author).to.equal('root')
@@ -562,7 +588,7 @@ describe('Test a single pod', function () {
562 it('Should update only the tags of a video', function (done) { 588 it('Should update only the tags of a video', function (done) {
563 const tags = [ 'tag1', 'tag2', 'supertag' ] 589 const tags = [ 'tag1', 'tag2', 'supertag' ]
564 590
565 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) { 591 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, null, tags, function (err) {
566 if (err) throw err 592 if (err) throw err
567 593
568 videosUtils.getVideo(server.url, videoId, function (err, res) { 594 videosUtils.getVideo(server.url, videoId, function (err, res) {
@@ -571,6 +597,8 @@ describe('Test a single pod', function () {
571 const video = res.body 597 const video = res.body
572 598
573 expect(video.name).to.equal('my super video updated') 599 expect(video.name).to.equal('my super video updated')
600 expect(video.category).to.equal(4)
601 expect(video.categoryLabel).to.equal('Art')
574 expect(video.description).to.equal('my super description updated') 602 expect(video.description).to.equal('my super description updated')
575 expect(video.podHost).to.equal('localhost:9001') 603 expect(video.podHost).to.equal('localhost:9001')
576 expect(video.author).to.equal('root') 604 expect(video.author).to.equal('root')
@@ -587,7 +615,7 @@ describe('Test a single pod', function () {
587 it('Should update only the description of a video', function (done) { 615 it('Should update only the description of a video', function (done) {
588 const description = 'hello everybody' 616 const description = 'hello everybody'
589 617
590 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) { 618 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, description, null, function (err) {
591 if (err) throw err 619 if (err) throw err
592 620
593 videosUtils.getVideo(server.url, videoId, function (err, res) { 621 videosUtils.getVideo(server.url, videoId, function (err, res) {
@@ -596,6 +624,8 @@ describe('Test a single pod', function () {
596 const video = res.body 624 const video = res.body
597 625
598 expect(video.name).to.equal('my super video updated') 626 expect(video.name).to.equal('my super video updated')
627 expect(video.category).to.equal(4)
628 expect(video.categoryLabel).to.equal('Art')
599 expect(video.description).to.equal('hello everybody') 629 expect(video.description).to.equal('hello everybody')
600 expect(video.podHost).to.equal('localhost:9001') 630 expect(video.podHost).to.equal('localhost:9001')
601 expect(video.author).to.equal('root') 631 expect(video.author).to.equal('root')
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index f9568b874..0f062c11f 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -87,9 +87,10 @@ describe('Test users', function () {
87 87
88 const name = 'my super name' 88 const name = 'my super name'
89 const description = 'my super description' 89 const description = 'my super description'
90 const category = 5
90 const tags = [ 'tag1', 'tag2' ] 91 const tags = [ 'tag1', 'tag2' ]
91 const video = 'video_short.webm' 92 const video = 'video_short.webm'
92 videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done) 93 videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 401, done)
93 }) 94 })
94 95
95 it('Should not be able to make friends', function (done) { 96 it('Should not be able to make friends', function (done) {
@@ -113,10 +114,11 @@ describe('Test users', function () {
113 114
114 it('Should upload the video with the correct token', function (done) { 115 it('Should upload the video with the correct token', function (done) {
115 const name = 'my super name' 116 const name = 'my super name'
117 const category = 5
116 const description = 'my super description' 118 const description = 'my super description'
117 const tags = [ 'tag1', 'tag2' ] 119 const tags = [ 'tag1', 'tag2' ]
118 const video = 'video_short.webm' 120 const video = 'video_short.webm'
119 videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) { 121 videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, function (err, res) {
120 if (err) throw err 122 if (err) throw err
121 123
122 videosUtils.getVideosList(server.url, function (err, res) { 124 videosUtils.getVideosList(server.url, function (err, res) {
@@ -133,10 +135,11 @@ describe('Test users', function () {
133 135
134 it('Should upload the video again with the correct token', function (done) { 136 it('Should upload the video again with the correct token', function (done) {
135 const name = 'my super name 2' 137 const name = 'my super name 2'
138 const category = 5
136 const description = 'my super description 2' 139 const description = 'my super description 2'
137 const tags = [ 'tag1' ] 140 const tags = [ 'tag1' ]
138 const video = 'video_short.webm' 141 const video = 'video_short.webm'
139 videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) 142 videosUtils.uploadVideo(server.url, accessToken, name, category, description, tags, video, 204, done)
140 }) 143 })
141 144
142 it('Should retrieve a video rating', function (done) { 145 it('Should retrieve a video rating', function (done) {
@@ -228,10 +231,11 @@ describe('Test users', function () {
228 this.timeout(5000) 231 this.timeout(5000)
229 232
230 const name = 'my super name' 233 const name = 'my super name'
234 const category = 5
231 const description = 'my super description' 235 const description = 'my super description'
232 const tags = [ 'tag1', 'tag2', 'tag3' ] 236 const tags = [ 'tag1', 'tag2', 'tag3' ]
233 const file = 'video_short.webm' 237 const file = 'video_short.webm'
234 videosUtils.uploadVideo(server.url, accessTokenUser, name, description, tags, file, done) 238 videosUtils.uploadVideo(server.url, accessTokenUser, name, category, description, tags, file, done)
235 }) 239 })
236 240
237 it('Should list all the users', function (done) { 241 it('Should list all the users', function (done) {
diff --git a/server/tests/api/video-abuse.js b/server/tests/api/video-abuse.js
index 0c4341860..871054788 100644
--- a/server/tests/api/video-abuse.js
+++ b/server/tests/api/video-abuse.js
@@ -46,17 +46,19 @@ describe('Test video abuses', function () {
46 // Upload some videos on each pods 46 // Upload some videos on each pods
47 function (next) { 47 function (next) {
48 const name = 'my super name for pod 1' 48 const name = 'my super name for pod 1'
49 const category = 5
49 const description = 'my super description for pod 1' 50 const description = 'my super description for pod 1'
50 const tags = [ 'tag' ] 51 const tags = [ 'tag' ]
51 const file = 'video_short2.webm' 52 const file = 'video_short2.webm'
52 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) 53 videosUtils.uploadVideo(servers[0].url, servers[0].accessToken, name, category, description, tags, file, next)
53 }, 54 },
54 function (next) { 55 function (next) {
55 const name = 'my super name for pod 2' 56 const name = 'my super name for pod 2'
57 const category = 5
56 const description = 'my super description for pod 2' 58 const description = 'my super description for pod 2'
57 const tags = [ 'tag' ] 59 const tags = [ 'tag' ]
58 const file = 'video_short2.webm' 60 const file = 'video_short2.webm'
59 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) 61 videosUtils.uploadVideo(servers[1].url, servers[1].accessToken, name, category, description, tags, file, next)
60 }, 62 },
61 // Wait videos propagation 63 // Wait videos propagation
62 function (next) { 64 function (next) {
diff --git a/server/tests/real-world/real-world.js b/server/tests/real-world/real-world.js
index 239b790ae..f17c83f85 100644
--- a/server/tests/real-world/real-world.js
+++ b/server/tests/real-world/real-world.js
@@ -201,13 +201,14 @@ function upload (servers, numServer, callback) {
201 if (!callback) callback = function () {} 201 if (!callback) callback = function () {}
202 202
203 const name = Date.now() + ' name' 203 const name = Date.now() + ' name'
204 const category = 4
204 const description = Date.now() + ' description' 205 const description = Date.now() + ' description'
205 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ] 206 const tags = [ Date.now().toString().substring(0, 5) + 't1', Date.now().toString().substring(0, 5) + 't2' ]
206 const file = 'video_short1.webm' 207 const file = 'video_short1.webm'
207 208
208 console.log('Uploading video to server ' + numServer) 209 console.log('Uploading video to server ' + numServer)
209 210
210 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, description, tags, file, callback) 211 videosUtils.uploadVideo(servers[numServer].url, servers[numServer].accessToken, name, category, description, tags, file, callback)
211} 212}
212 213
213function update (servers, numServer, callback) { 214function update (servers, numServer, callback) {
diff --git a/server/tests/real-world/tools/upload.js b/server/tests/real-world/tools/upload.js
index ba08028cf..49076ee2a 100644
--- a/server/tests/real-world/tools/upload.js
+++ b/server/tests/real-world/tools/upload.js
@@ -9,6 +9,7 @@ program
9 .option('-u, --url <url>', 'Server url') 9 .option('-u, --url <url>', 'Server url')
10 .option('-a, --access-token <token>', 'Access token') 10 .option('-a, --access-token <token>', 'Access token')
11 .option('-n, --name <name>', 'Video name') 11 .option('-n, --name <name>', 'Video name')
12 .option('-d, --category <category number>', 'Category number')
12 .option('-d, --description <description>', 'Video description') 13 .option('-d, --description <description>', 'Video description')
13 .option('-t, --tags <tags>', 'Video tags', list) 14 .option('-t, --tags <tags>', 'Video tags', list)
14 .option('-f, --file <file>', 'Video absolute file path') 15 .option('-f, --file <file>', 'Video absolute file path')
@@ -18,6 +19,7 @@ if (
18 !program.url || 19 !program.url ||
19 !program.accessToken || 20 !program.accessToken ||
20 !program.name || 21 !program.name ||
22 !program.category ||
21 !program.description || 23 !program.description ||
22 !program.tags || 24 !program.tags ||
23 !Array.isArray(program.tags) || 25 !Array.isArray(program.tags) ||
@@ -34,6 +36,7 @@ fs.access(program.file, fs.F_OK, function (err) {
34 program.url, 36 program.url,
35 program.accessToken, 37 program.accessToken,
36 program.name, 38 program.name,
39 program.category,
37 program.description, 40 program.description,
38 program.tags, 41 program.tags,
39 program.file 42 program.file
@@ -46,10 +49,10 @@ function list (val) {
46 return val.split(',') 49 return val.split(',')
47} 50}
48 51
49function upload (url, accessToken, name, description, tags, file) { 52function upload (url, accessToken, name, category, description, tags, file) {
50 console.log('Uploading %s video...', program.name) 53 console.log('Uploading %s video...', program.name)
51 54
52 utils.uploadVideo(url, accessToken, name, description, tags, file, function (err) { 55 utils.uploadVideo(url, accessToken, name, category, description, tags, file, function (err) {
53 if (err) throw err 56 if (err) throw err
54 57
55 console.log('Video uploaded.') 58 console.log('Video uploaded.')
diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js
index 177426076..0aa6ec5a8 100644
--- a/server/tests/utils/videos.js
+++ b/server/tests/utils/videos.js
@@ -5,6 +5,7 @@ const pathUtils = require('path')
5const request = require('supertest') 5const request = require('supertest')
6 6
7const videosUtils = { 7const videosUtils = {
8 getVideoCategories,
8 getAllVideosListBy, 9 getAllVideosListBy,
9 getVideo, 10 getVideo,
10 getVideosList, 11 getVideosList,
@@ -22,6 +23,17 @@ const videosUtils = {
22 23
23// ---------------------- Export functions -------------------- 24// ---------------------- Export functions --------------------
24 25
26function getVideoCategories (url, end) {
27 const path = '/api/v1/videos/categories'
28
29 request(url)
30 .get(path)
31 .set('Accept', 'application/json')
32 .expect(200)
33 .expect('Content-Type', /json/)
34 .end(end)
35}
36
25function getAllVideosListBy (url, end) { 37function getAllVideosListBy (url, end) {
26 const path = '/api/v1/videos' 38 const path = '/api/v1/videos'
27 39
@@ -181,7 +193,7 @@ function testVideoImage (url, videoName, imagePath, callback) {
181 } 193 }
182} 194}
183 195
184function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) { 196function uploadVideo (url, accessToken, name, category, description, tags, fixture, specialStatus, end) {
185 if (!end) { 197 if (!end) {
186 end = specialStatus 198 end = specialStatus
187 specialStatus = 204 199 specialStatus = 204
@@ -194,6 +206,7 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
194 .set('Accept', 'application/json') 206 .set('Accept', 'application/json')
195 .set('Authorization', 'Bearer ' + accessToken) 207 .set('Authorization', 'Bearer ' + accessToken)
196 .field('name', name) 208 .field('name', name)
209 .field('category', category)
197 .field('description', description) 210 .field('description', description)
198 211
199 for (let i = 0; i < tags.length; i++) { 212 for (let i = 0; i < tags.length; i++) {
@@ -212,7 +225,7 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia
212 .end(end) 225 .end(end)
213} 226}
214 227
215function updateVideo (url, accessToken, id, name, description, tags, specialStatus, end) { 228function updateVideo (url, accessToken, id, name, category, description, tags, specialStatus, end) {
216 if (!end) { 229 if (!end) {
217 end = specialStatus 230 end = specialStatus
218 specialStatus = 204 231 specialStatus = 204
@@ -226,6 +239,7 @@ function updateVideo (url, accessToken, id, name, description, tags, specialStat
226 .set('Authorization', 'Bearer ' + accessToken) 239 .set('Authorization', 'Bearer ' + accessToken)
227 240
228 if (name) req.field('name', name) 241 if (name) req.field('name', name)
242 if (category) req.field('category', category)
229 if (description) req.field('description', description) 243 if (description) req.field('description', description)
230 244
231 if (tags) { 245 if (tags) {