From 6e07c3de88791a0b342e0cc319590048117f9c2d Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Wed, 22 Mar 2017 21:15:55 +0100 Subject: Add video category support --- server/tests/api/check-params/users.js | 3 +- server/tests/api/check-params/video-abuses.js | 3 +- server/tests/api/check-params/videos.js | 58 +++++++++++++++++++++++++++ server/tests/api/friends-advanced.js | 3 +- server/tests/api/multiple-pods.js | 25 +++++++++--- server/tests/api/requests.js | 3 +- server/tests/api/single-pod.js | 42 ++++++++++++++++--- server/tests/api/users.js | 12 ++++-- server/tests/api/video-abuse.js | 6 ++- 9 files changed, 134 insertions(+), 21 deletions(-) (limited to 'server/tests/api') 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 () { }, function (next) { const name = 'my super name for pod' + const category = 5 const description = 'my super description for pod' const tags = [ 'tag' ] 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) { 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 () { // Upload some videos on each pods function (next) { const name = 'my super name for pod' + const category = 2 const description = 'my super description for pod' const tags = [ 'tag' ] 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) { 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 () { it('Should fail without name', function (done) { const data = { + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -124,6 +125,32 @@ describe('Test videos API validator', function () { it('Should fail with a long name', function (done) { const data = { 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', tags: [ 'tag1', 'tag2' ] } @@ -136,6 +163,7 @@ describe('Test videos API validator', function () { it('Should fail without description', function (done) { const data = { name: 'my super name', + category: 5, tags: [ 'tag1', 'tag2' ] } const attach = { @@ -147,6 +175,7 @@ describe('Test videos API validator', function () { it('Should fail with a long description', function (done) { const data = { 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' + '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', @@ -161,6 +190,7 @@ describe('Test videos API validator', function () { it('Should fail without tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description' } const attach = { @@ -172,6 +202,7 @@ describe('Test videos API validator', function () { it('Should fail with too many tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] } @@ -184,6 +215,7 @@ describe('Test videos API validator', function () { it('Should fail with not enough tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ ] } @@ -196,6 +228,7 @@ describe('Test videos API validator', function () { it('Should fail with a tag length too low', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 't' ] } @@ -208,6 +241,7 @@ describe('Test videos API validator', function () { it('Should fail with a tag length too big', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'mysupertagtoolong', 'tag1' ] } @@ -220,6 +254,7 @@ describe('Test videos API validator', function () { it('Should fail with malformed tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'my tag' ] } @@ -232,6 +267,7 @@ describe('Test videos API validator', function () { it('Should fail without an input file', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -242,6 +278,7 @@ describe('Test videos API validator', function () { it('Should fail without an incorrect input file', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -254,6 +291,7 @@ describe('Test videos API validator', function () { it('Should fail with a too big duration', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -266,6 +304,7 @@ describe('Test videos API validator', function () { it('Should succeed with the correct parameters', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -302,6 +341,7 @@ describe('Test videos API validator', function () { it('Should fail without a valid uuid', function (done) { const data = { + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -310,6 +350,7 @@ describe('Test videos API validator', function () { it('Should fail with an unknown id', function (done) { const data = { + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2' ] } @@ -319,6 +360,17 @@ describe('Test videos API validator', function () { it('Should fail with a long name', function (done) { const data = { 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', tags: [ 'tag1', 'tag2' ] } @@ -328,6 +380,7 @@ describe('Test videos API validator', function () { it('Should fail with a long description', function (done) { const data = { 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' + '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', @@ -339,6 +392,7 @@ describe('Test videos API validator', function () { it('Should fail with too many tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] } @@ -348,6 +402,7 @@ describe('Test videos API validator', function () { it('Should fail with not enough tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ ] } @@ -357,6 +412,7 @@ describe('Test videos API validator', function () { it('Should fail with a tag length too low', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'tag1', 't' ] } @@ -366,6 +422,7 @@ describe('Test videos API validator', function () { it('Should fail with a tag length too big', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'mysupertagtoolong', 'tag1' ] } @@ -375,6 +432,7 @@ describe('Test videos API validator', function () { it('Should fail with malformed tags', function (done) { const data = { name: 'my super name', + category: 5, description: 'my super description', tags: [ 'my tag' ] } 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 () { function uploadVideo (podNumber, callback) { const name = 'my super video' + const category = 5 const description = 'my super description' const tags = [ 'tag1', 'tag2' ] const fixture = 'video_short.webm' 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) { 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 () { series([ function (next) { const name = 'my super name for pod 1' + const category = 5 const description = 'my super description for pod 1' const tags = [ 'tag1p1', 'tag2p1' ] 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) { setTimeout(next, 11000) @@ -104,6 +105,8 @@ describe('Test multiple pods', function () { expect(videos.length).to.equal(1) const video = videos[0] 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.podHost).to.equal('localhost:9001') expect(video.magnetUri).to.exist @@ -144,10 +147,11 @@ describe('Test multiple pods', function () { series([ function (next) { const name = 'my super name for pod 2' + const category = 4 const description = 'my super description for pod 2' const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] 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) { setTimeout(next, 11000) @@ -167,6 +171,8 @@ describe('Test multiple pods', function () { expect(videos.length).to.equal(2) const video = videos[1] 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.podHost).to.equal('localhost:9002') expect(video.magnetUri).to.exist @@ -207,17 +213,19 @@ describe('Test multiple pods', function () { series([ function (next) { const name = 'my super name for pod 3' + const category = 6 const description = 'my super description for pod 3' const tags = [ 'tag1p3' ] 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) { const name = 'my super name for pod 3-2' + const category = 7 const description = 'my super description for pod 3-2' const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] 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) { 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.category).to.equal(6) + expect(video1.categoryLabel).to.equal('Travels') expect(video1.description).to.equal('my super description for pod 3') expect(video1.podHost).to.equal('localhost:9003') expect(video1.magnetUri).to.exist @@ -257,6 +267,8 @@ describe('Test multiple pods', function () { expect(miscsUtils.dateIsValid(video1.updatedAt)).to.be.true 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.podHost).to.equal('localhost:9003') expect(video2.magnetUri).to.exist @@ -603,10 +615,11 @@ describe('Test multiple pods', function () { this.timeout(15000) const name = 'my super video updated' + const category = 10 const description = 'my super description updated' 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 setTimeout(done, 11000) @@ -629,6 +642,8 @@ describe('Test multiple pods', function () { }) 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.tags).to.deep.equal([ 'tagup1', 'tagup2' ]) 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 () { function uploadVideo (server, callback) { const name = 'my super video' + const category = 5 const description = 'my super description' const tags = [ 'tag1', 'tag2' ] 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) { 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 () { ], 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) { videosUtils.getVideosList(server.url, function (err, res) { if (err) throw err @@ -60,9 +73,10 @@ describe('Test a single pod', function () { this.timeout(5000) const name = 'my super name' const description = 'my super description' + const category = 2 const tags = [ 'tag1', 'tag2', 'tag3' ] 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) { @@ -78,6 +92,8 @@ describe('Test a single pod', function () { const video = res.body.data[0] 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.podHost).to.equal('localhost:9001') expect(video.magnetUri).to.exist @@ -113,6 +129,8 @@ describe('Test a single pod', function () { const video = res.body 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.podHost).to.equal('localhost:9001') expect(video.magnetUri).to.exist @@ -152,6 +170,8 @@ describe('Test a single pod', function () { const video = res.body.data[0] 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.podHost).to.equal('localhost:9001') expect(video.author).to.equal('root') @@ -207,6 +227,8 @@ describe('Test a single pod', function () { const video = res.body.data[0] 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.podHost).to.equal('localhost:9001') expect(video.author).to.equal('root') @@ -301,9 +323,10 @@ describe('Test a single pod', function () { each(videos, function (video, callbackEach) { const name = video + ' name' const description = video + ' description' + const category = 2 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) }) @@ -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] videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) { if (err) throw err @@ -521,10 +544,11 @@ describe('Test a single pod', function () { it('Should update a video', function (done) { const name = 'my super video updated' + const category = 4 const description = 'my super description updated' 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) { @@ -536,6 +560,8 @@ describe('Test a single pod', function () { const video = res.body 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.podHost).to.equal('localhost:9001') 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) { 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 videosUtils.getVideo(server.url, videoId, function (err, res) { @@ -571,6 +597,8 @@ describe('Test a single pod', function () { const video = res.body 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.podHost).to.equal('localhost:9001') 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) { 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 videosUtils.getVideo(server.url, videoId, function (err, res) { @@ -596,6 +624,8 @@ describe('Test a single pod', function () { const video = res.body 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.podHost).to.equal('localhost:9001') 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 () { const name = 'my super name' const description = 'my super description' + const category = 5 const tags = [ 'tag1', 'tag2' ] 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) { @@ -113,10 +114,11 @@ describe('Test users', function () { it('Should upload the video with the correct token', function (done) { const name = 'my super name' + const category = 5 const description = 'my super description' const tags = [ 'tag1', 'tag2' ] 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 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) { const name = 'my super name 2' + const category = 5 const description = 'my super description 2' const tags = [ 'tag1' ] 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) { @@ -228,10 +231,11 @@ describe('Test users', function () { this.timeout(5000) const name = 'my super name' + const category = 5 const description = 'my super description' const tags = [ 'tag1', 'tag2', 'tag3' ] 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) { 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 () { // Upload some videos on each pods function (next) { const name = 'my super name for pod 1' + const category = 5 const description = 'my super description for pod 1' const tags = [ 'tag' ] 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) { const name = 'my super name for pod 2' + const category = 5 const description = 'my super description for pod 2' const tags = [ 'tag' ] 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 function (next) { -- cgit v1.2.3