From be587647f98a4b83ca06a61fe55c7ac5d60927c6 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 6 Jun 2016 14:15:03 +0200 Subject: Add tags support to server --- server/tests/api/checkParams.js | 104 ++++++++++++++++++++++++++++++++---- server/tests/api/friendsAdvanced.js | 3 +- server/tests/api/multiplePods.js | 28 ++++++++-- server/tests/api/singlePod.js | 16 +++++- server/tests/api/users.js | 19 +++++-- server/tests/api/utils.js | 25 +++++---- 6 files changed, 166 insertions(+), 29 deletions(-) (limited to 'server/tests/api') diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js index e02fd0da5..95a7738f8 100644 --- a/server/tests/api/checkParams.js +++ b/server/tests/api/checkParams.js @@ -23,7 +23,14 @@ describe('Test parameters validator', function () { Object.keys(fields).forEach(function (field) { const value = fields[field] - req.field(field, value) + + if (Array.isArray(value)) { + for (let i = 0; i < value.length; i++) { + req.field(field + '[' + i + ']', value[i]) + } + } else { + req.field(field, value) + } }) Object.keys(attaches).forEach(function (attach) { @@ -198,7 +205,8 @@ describe('Test parameters validator', function () { it('Should fail without name', function (done) { const data = { - description: 'my super description' + description: 'my super description', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') @@ -209,7 +217,8 @@ describe('Test parameters validator', function () { it('Should fail with a long name', function (done) { const data = { name: 'My very very very very very very very very very very very very very very very very long name', - description: 'my super description' + description: 'my super description', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') @@ -219,7 +228,8 @@ describe('Test parameters validator', function () { it('Should fail without description', function (done) { const data = { - name: 'my super name' + name: 'my super name', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') @@ -232,7 +242,8 @@ describe('Test parameters validator', function () { name: 'my super name', 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' + 'very very very very very very very very very very very very very very very long', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') @@ -240,11 +251,83 @@ describe('Test parameters validator', function () { makePostRequest(path, server.accessToken, data, attach, done) }) - it('Should fail without an input file', function (done) { + it('Should fail without tags', function (done) { const data = { name: 'my super name', description: 'my super description' } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + makePostRequest(path, server.accessToken, data, attach, done) + }) + + it('Should fail with too many tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + makePostRequest(path, server.accessToken, data, attach, done) + }) + + it('Should fail with not enough tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + makePostRequest(path, server.accessToken, data, attach, done) + }) + + it('Should fail with a tag length too low', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 't' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + makePostRequest(path, server.accessToken, data, attach, done) + }) + + it('Should fail with a tag length too big', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'mysupertagtoolong', 'tag1' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + makePostRequest(path, server.accessToken, data, attach, done) + }) + + it('Should fail with malformed tags', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'my tag' ] + } + const attach = { + 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') + } + makePostRequest(path, server.accessToken, data, attach, done) + }) + + it('Should fail without an input file', function (done) { + const data = { + name: 'my super name', + description: 'my super description', + tags: [ 'tag1', 'tag2' ] + } const attach = {} makePostRequest(path, server.accessToken, data, attach, done) }) @@ -252,7 +335,8 @@ describe('Test parameters validator', function () { it('Should fail without an incorrect input file', function (done) { const data = { name: 'my super name', - description: 'my super description' + description: 'my super description', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short_fake.webm') @@ -263,7 +347,8 @@ describe('Test parameters validator', function () { it('Should fail with a too big duration', function (done) { const data = { name: 'my super name', - description: 'my super description' + description: 'my super description', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_too_long.webm') @@ -274,7 +359,8 @@ describe('Test parameters validator', function () { it('Should succeed with the correct parameters', function (done) { const data = { name: 'my super name', - description: 'my super description' + description: 'my super description', + tags: [ 'tag1', 'tag2' ] } const attach = { 'videofile': pathUtils.join(__dirname, 'fixtures', 'video_short.webm') diff --git a/server/tests/api/friendsAdvanced.js b/server/tests/api/friendsAdvanced.js index 7b895b6b5..86620254e 100644 --- a/server/tests/api/friendsAdvanced.js +++ b/server/tests/api/friendsAdvanced.js @@ -27,10 +27,11 @@ describe('Test advanced friends', function () { function uploadVideo (podNumber, callback) { const name = 'my super video' const description = 'my super description' + const tags = [ 'tag1', 'tag2' ] const fixture = 'video_short.webm' const server = servers[podNumber - 1] - return utils.uploadVideo(server.url, server.accessToken, name, description, fixture, callback) + return utils.uploadVideo(server.url, server.accessToken, name, description, tags, fixture, callback) } function getVideos (podNumber, callback) { diff --git a/server/tests/api/multiplePods.js b/server/tests/api/multiplePods.js index dac6dd410..40326c260 100644 --- a/server/tests/api/multiplePods.js +++ b/server/tests/api/multiplePods.js @@ -75,7 +75,11 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.uploadVideo(servers[0].url, servers[0].accessToken, 'my super name for pod 1', 'my super description for pod 1', 'video_short1.webm', next) + const name = 'my super name for pod 1' + const description = 'my super description for pod 1' + const tags = [ 'tag1p1', 'tag2p1' ] + const file = 'video_short1.webm' + utils.uploadVideo(servers[0].url, servers[0].accessToken, name, description, tags, file, next) }, function (next) { setTimeout(next, 11000) @@ -99,6 +103,7 @@ describe('Test multiple pods', function () { expect(video.podUrl).to.equal('localhost:9001') expect(video.magnetUri).to.exist expect(video.duration).to.equal(10) + expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) expect(utils.dateIsValid(video.createdDate)).to.be.true if (server.url !== 'http://localhost:9001') { @@ -131,7 +136,11 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.uploadVideo(servers[1].url, servers[1].accessToken, 'my super name for pod 2', 'my super description for pod 2', 'video_short2.webm', next) + const name = 'my super name for pod 2' + const description = 'my super description for pod 2' + const tags = [ 'tag1p2', 'tag2p2', 'tag3p2' ] + const file = 'video_short2.webm' + utils.uploadVideo(servers[1].url, servers[1].accessToken, name, description, tags, file, next) }, function (next) { setTimeout(next, 11000) @@ -155,6 +164,7 @@ describe('Test multiple pods', function () { expect(video.podUrl).to.equal('localhost:9002') expect(video.magnetUri).to.exist expect(video.duration).to.equal(5) + expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) expect(utils.dateIsValid(video.createdDate)).to.be.true if (server.url !== 'http://localhost:9002') { @@ -187,10 +197,18 @@ describe('Test multiple pods', function () { async.series([ function (next) { - utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3', 'my super description for pod 3', 'video_short3.webm', next) + const name = 'my super name for pod 3' + const description = 'my super description for pod 3' + const tags = [ 'tag1p3' ] + const file = 'video_short3.webm' + utils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) }, function (next) { - utils.uploadVideo(servers[2].url, servers[2].accessToken, 'my super name for pod 3-2', 'my super description for pod 3-2', 'video_short.webm', next) + const name = 'my super name for pod 3-2' + const description = 'my super description for pod 3-2' + const tags = [ 'tag2p3', 'tag3p3', 'tag4p3' ] + const file = 'video_short.webm' + utils.uploadVideo(servers[2].url, servers[2].accessToken, name, description, tags, file, next) }, function (next) { setTimeout(next, 22000) @@ -224,6 +242,7 @@ describe('Test multiple pods', function () { expect(video1.podUrl).to.equal('localhost:9003') expect(video1.magnetUri).to.exist expect(video1.duration).to.equal(5) + expect(video1.tags).to.deep.equal([ 'tag1p3' ]) expect(utils.dateIsValid(video1.createdDate)).to.be.true expect(video2.name).to.equal('my super name for pod 3-2') @@ -231,6 +250,7 @@ describe('Test multiple pods', function () { expect(video2.podUrl).to.equal('localhost:9003') expect(video2.magnetUri).to.exist expect(video2.duration).to.equal(5) + expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) expect(utils.dateIsValid(video2.createdDate)).to.be.true if (server.url !== 'http://localhost:9003') { diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js index 296dd0aa4..ef882b080 100644 --- a/server/tests/api/singlePod.js +++ b/server/tests/api/singlePod.js @@ -57,7 +57,11 @@ describe('Test a single pod', function () { it('Should upload the video', function (done) { this.timeout(5000) - utils.uploadVideo(server.url, server.accessToken, 'my super name', 'my super description', 'video_short.webm', done) + const name = 'my super name' + const description = 'my super description' + const tags = [ 'tag1', 'tag2', 'tag3' ] + const file = 'video_short.webm' + utils.uploadVideo(server.url, server.accessToken, name, description, tags, file, done) }) it('Should seed the uploaded video', function (done) { @@ -78,6 +82,7 @@ describe('Test a single pod', function () { expect(video.magnetUri).to.exist expect(video.author).to.equal('root') expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(utils.dateIsValid(video.createdDate)).to.be.true utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { @@ -112,6 +117,7 @@ describe('Test a single pod', function () { expect(video.magnetUri).to.exist expect(video.author).to.equal('root') expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(utils.dateIsValid(video.createdDate)).to.be.true utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { @@ -143,6 +149,7 @@ describe('Test a single pod', function () { expect(video.podUrl).to.equal('localhost:9001') expect(video.author).to.equal('root') expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(utils.dateIsValid(video.createdDate)).to.be.true utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { @@ -168,6 +175,7 @@ describe('Test a single pod', function () { expect(video.podUrl).to.equal('localhost:9001') expect(video.author).to.equal('root') expect(video.isLocal).to.be.true + expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) expect(utils.dateIsValid(video.createdDate)).to.be.true utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) { @@ -235,7 +243,11 @@ describe('Test a single pod', function () { 'video_short1.webm', 'video_short2.webm', 'video_short3.webm' ] async.each(videos, function (video, callbackEach) { - utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach) + const name = video + ' name' + const description = video + ' description' + const tags = [ 'tag1', 'tag2', 'tag3' ] + + utils.uploadVideo(server.url, server.accessToken, name, description, tags, video, callbackEach) }, done) }) diff --git a/server/tests/api/users.js b/server/tests/api/users.js index 9ab5083a0..7ab426d85 100644 --- a/server/tests/api/users.js +++ b/server/tests/api/users.js @@ -79,7 +79,12 @@ describe('Test users', function () { it('Should not be able to upload a video', function (done) { accessToken = 'mysupertoken' - utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 401, done) + + const name = 'my super name' + const description = 'my super description' + const tags = [ 'tag1', 'tag2' ] + const video = 'video_short.webm' + utils.uploadVideo(server.url, accessToken, name, description, tags, video, 401, done) }) it('Should not be able to make friends', function (done) { @@ -102,7 +107,11 @@ describe('Test users', function () { }) it('Should upload the video with the correct token', function (done) { - utils.uploadVideo(server.url, accessToken, 'my super name', 'my super description', 'video_short.webm', 204, function (err, res) { + const name = 'my super name' + const description = 'my super description' + const tags = [ 'tag1', 'tag2' ] + const video = 'video_short.webm' + utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, function (err, res) { if (err) throw err utils.getVideosList(server.url, function (err, res) { @@ -118,7 +127,11 @@ describe('Test users', function () { }) it('Should upload the video again with the correct token', function (done) { - utils.uploadVideo(server.url, accessToken, 'my super name 2', 'my super description 2', 'video_short.webm', 204, done) + const name = 'my super name 2' + const description = 'my super description 2' + const tags = [ 'tag1' ] + const video = 'video_short.webm' + utils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) }) it('Should not be able to remove the video with an incorrect token', function (done) { diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index c6430c930..e0068eada 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js @@ -349,7 +349,7 @@ function testImage (url, videoName, imagePath, callback) { }) } -function uploadVideo (url, accessToken, name, description, fixture, specialStatus, end) { +function uploadVideo (url, accessToken, name, description, tags, fixture, specialStatus, end) { if (!end) { end = specialStatus specialStatus = 204 @@ -357,15 +357,20 @@ function uploadVideo (url, accessToken, name, description, fixture, specialStatu const path = '/api/v1/videos' - request(url) - .post(path) - .set('Accept', 'application/json') - .set('Authorization', 'Bearer ' + accessToken) - .field('name', name) - .field('description', description) - .attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture)) - .expect(specialStatus) - .end(end) + const req = request(url) + .post(path) + .set('Accept', 'application/json') + .set('Authorization', 'Bearer ' + accessToken) + .field('name', name) + .field('description', description) + + for (let i = 0; i < tags.length; i++) { + req.field('tags[' + i + ']', tags[i]) + } + + req.attach('videofile', pathUtils.join(__dirname, 'fixtures', fixture)) + .expect(specialStatus) + .end(end) } // --------------------------------------------------------------------------- -- cgit v1.2.3