aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/singlePod.js99
-rw-r--r--server/tests/api/utils.js25
2 files changed, 109 insertions, 15 deletions
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index 884a83032..296dd0aa4 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -129,7 +129,7 @@ describe('Test a single pod', function () {
129 }) 129 })
130 }) 130 })
131 131
132 it('Should search the video', function (done) { 132 it('Should search the video by name by default', function (done) {
133 utils.searchVideo(server.url, 'my', function (err, res) { 133 utils.searchVideo(server.url, 'my', function (err, res) {
134 if (err) throw err 134 if (err) throw err
135 135
@@ -154,7 +154,32 @@ describe('Test a single pod', function () {
154 }) 154 })
155 }) 155 })
156 156
157 it('Should not find a search', function (done) { 157 it('Should search the video by podUrl', function (done) {
158 utils.searchVideo(server.url, '9001', 'podUrl', function (err, res) {
159 if (err) throw err
160
161 expect(res.body.total).to.equal(1)
162 expect(res.body.data).to.be.an('array')
163 expect(res.body.data.length).to.equal(1)
164
165 const video = res.body.data[0]
166 expect(video.name).to.equal('my super name')
167 expect(video.description).to.equal('my super description')
168 expect(video.podUrl).to.equal('localhost:9001')
169 expect(video.author).to.equal('root')
170 expect(video.isLocal).to.be.true
171 expect(utils.dateIsValid(video.createdDate)).to.be.true
172
173 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
174 if (err) throw err
175 expect(test).to.equal(true)
176
177 done()
178 })
179 })
180 })
181
182 it('Should not find a search by name by default', function (done) {
158 utils.searchVideo(server.url, 'hello', function (err, res) { 183 utils.searchVideo(server.url, 'hello', function (err, res) {
159 if (err) throw err 184 if (err) throw err
160 185
@@ -166,6 +191,18 @@ describe('Test a single pod', function () {
166 }) 191 })
167 }) 192 })
168 193
194 it('Should not find a search by author', function (done) {
195 utils.searchVideo(server.url, 'hello', 'author', function (err, res) {
196 if (err) throw err
197
198 expect(res.body.total).to.equal(0)
199 expect(res.body.data).to.be.an('array')
200 expect(res.body.data.length).to.equal(0)
201
202 done()
203 })
204 })
205
169 it('Should remove the video', function (done) { 206 it('Should remove the video', function (done) {
170 utils.removeVideo(server.url, server.accessToken, videoId, function (err) { 207 utils.removeVideo(server.url, server.accessToken, videoId, function (err) {
171 if (err) throw err 208 if (err) throw err
@@ -288,7 +325,7 @@ describe('Test a single pod', function () {
288 }) 325 })
289 326
290 it('Should search the first video', function (done) { 327 it('Should search the first video', function (done) {
291 utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) { 328 utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) {
292 if (err) throw err 329 if (err) throw err
293 330
294 const videos = res.body.data 331 const videos = res.body.data
@@ -301,7 +338,7 @@ describe('Test a single pod', function () {
301 }) 338 })
302 339
303 it('Should search the last two videos', function (done) { 340 it('Should search the last two videos', function (done) {
304 utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) { 341 utils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) {
305 if (err) throw err 342 if (err) throw err
306 343
307 const videos = res.body.data 344 const videos = res.body.data
@@ -314,8 +351,8 @@ describe('Test a single pod', function () {
314 }) 351 })
315 }) 352 })
316 353
317 it('Should search all the videos', function (done) { 354 it('Should search all the webm videos', function (done) {
318 utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) { 355 utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
319 if (err) throw err 356 if (err) throw err
320 357
321 const videos = res.body.data 358 const videos = res.body.data
@@ -326,6 +363,56 @@ describe('Test a single pod', function () {
326 }) 363 })
327 }) 364 })
328 365
366 it('Should search all the root author videos', function (done) {
367 utils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
368 if (err) throw err
369
370 const videos = res.body.data
371 expect(res.body.total).to.equal(6)
372 expect(videos.length).to.equal(6)
373
374 done()
375 })
376 })
377
378 it('Should search all the 9001 port videos', function (done) {
379 utils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) {
380 if (err) throw err
381
382 const videos = res.body.data
383 expect(res.body.total).to.equal(6)
384 expect(videos.length).to.equal(6)
385
386 done()
387 })
388 })
389
390 it('Should search all the localhost videos', function (done) {
391 utils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) {
392 if (err) throw err
393
394 const videos = res.body.data
395 expect(res.body.total).to.equal(6)
396 expect(videos.length).to.equal(6)
397
398 done()
399 })
400 })
401
402 it('Should search the good magnetUri video', function (done) {
403 const video = videosListBase[0]
404 utils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
405 if (err) throw err
406
407 const videos = res.body.data
408 expect(res.body.total).to.equal(1)
409 expect(videos.length).to.equal(1)
410 expect(videos[0].name).to.equal(video.name)
411
412 done()
413 })
414 })
415
329 it('Should list and sort by name in descending order', function (done) { 416 it('Should list and sort by name in descending order', function (done) {
330 utils.getVideosListSort(server.url, '-name', function (err, res) { 417 utils.getVideosListSort(server.url, '-name', function (err, res) {
331 if (err) throw err 418 if (err) throw err
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js
index 218b46157..c6430c930 100644
--- a/server/tests/api/utils.js
+++ b/server/tests/api/utils.js
@@ -291,24 +291,31 @@ function runServer (number, callback) {
291 }) 291 })
292} 292}
293 293
294function searchVideo (url, search, end) { 294function searchVideo (url, search, field, end) {
295 const path = '/api/v1/videos' 295 if (!end) {
296 end = field
297 field = null
298 }
296 299
297 request(url) 300 const path = '/api/v1/videos'
298 .get(path + '/search/' + search) 301 const req = request(url)
299 .set('Accept', 'application/json') 302 .get(path + '/search/' + search)
300 .expect(200) 303 .set('Accept', 'application/json')
301 .expect('Content-Type', /json/) 304
302 .end(end) 305 if (field) req.query({ field: field })
306 req.expect(200)
307 .expect('Content-Type', /json/)
308 .end(end)
303} 309}
304 310
305function searchVideoWithPagination (url, search, start, count, end) { 311function searchVideoWithPagination (url, search, field, start, count, end) {
306 const path = '/api/v1/videos' 312 const path = '/api/v1/videos'
307 313
308 request(url) 314 request(url)
309 .get(path + '/search/' + search) 315 .get(path + '/search/' + search)
310 .query({ start: start }) 316 .query({ start: start })
311 .query({ count: count }) 317 .query({ count: count })
318 .query({ field: field })
312 .set('Accept', 'application/json') 319 .set('Accept', 'application/json')
313 .expect(200) 320 .expect(200)
314 .expect('Content-Type', /json/) 321 .expect('Content-Type', /json/)