From 8d199cb823e1e47de87fdf421964e260b0ba6eb7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Mon, 6 Jun 2016 14:54:52 +0200 Subject: [PATCH] Add tag search support to server --- server/initializers/constants.js | 2 +- server/models/videos.js | 2 +- server/tests/api/singlePod.js | 38 ++++++++++++++++++++++++++++++++ 3 files changed, 40 insertions(+), 2 deletions(-) diff --git a/server/initializers/constants.js b/server/initializers/constants.js index 97d22abdb..c6a6ac966 100644 --- a/server/initializers/constants.js +++ b/server/initializers/constants.js @@ -23,7 +23,7 @@ let REQUEST_RETRIES = 10 // Sortable columns per schema const SEARCHABLE_COLUMNS = { - VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author' ] + VIDEOS: [ 'name', 'magnetUri', 'podUrl', 'author', 'tags' ] } // Sortable columns per schema diff --git a/server/models/videos.js b/server/models/videos.js index f4658c371..d6b743c7c 100644 --- a/server/models/videos.js +++ b/server/models/videos.js @@ -128,7 +128,7 @@ function removeByIds (ids, callback) { function search (value, field, start, count, sort, callback) { const query = {} // Make an exact search with the magnet - if (field === 'magnetUri') { + if (field === 'magnetUri' || field === 'tags') { query[field] = value } else { query[field] = new RegExp(value) diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js index ef882b080..5fcf5557f 100644 --- a/server/tests/api/singlePod.js +++ b/server/tests/api/singlePod.js @@ -187,6 +187,32 @@ describe('Test a single pod', function () { }) }) + it('Should search the video by tag', function (done) { + utils.searchVideo(server.url, 'tag1', 'tags', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(1) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(1) + + const video = res.body.data[0] + expect(video.name).to.equal('my super name') + expect(video.description).to.equal('my super description') + 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) { + if (err) throw err + expect(test).to.equal(true) + + done() + }) + }) + }) + it('Should not find a search by name by default', function (done) { utils.searchVideo(server.url, 'hello', function (err, res) { if (err) throw err @@ -211,6 +237,18 @@ describe('Test a single pod', function () { }) }) + it('Should not find a search by tag', function (done) { + utils.searchVideo(server.url, 'tag', 'tags', function (err, res) { + if (err) throw err + + expect(res.body.total).to.equal(0) + expect(res.body.data).to.be.an('array') + expect(res.body.data.length).to.equal(0) + + done() + }) + }) + it('Should remove the video', function (done) { utils.removeVideo(server.url, server.accessToken, videoId, function (err) { if (err) throw err