aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-03-08 21:35:43 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-03-08 21:35:43 +0100
commitd38b82810638b9f664c9016fac2684454c273a77 (patch)
tree9465c367e5033675309efca4d66790c6fdd5230d /server/tests/api
parent8f9064432122cba0f518a24ac4378357dadec589 (diff)
downloadPeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.gz
PeerTube-d38b82810638b9f664c9016fac2684454c273a77.tar.zst
PeerTube-d38b82810638b9f664c9016fac2684454c273a77.zip
Add like/dislike system for videos
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/users.js76
-rw-r--r--server/tests/api/check-params/videos.js42
-rw-r--r--server/tests/api/multiple-pods.js89
-rw-r--r--server/tests/api/single-pod.js34
-rw-r--r--server/tests/api/users.js29
5 files changed, 258 insertions, 12 deletions
diff --git a/server/tests/api/check-params/users.js b/server/tests/api/check-params/users.js
index 6edb54660..11e2bada4 100644
--- a/server/tests/api/check-params/users.js
+++ b/server/tests/api/check-params/users.js
@@ -9,11 +9,13 @@ const loginUtils = require('../../utils/login')
9const requestsUtils = require('../../utils/requests') 9const requestsUtils = require('../../utils/requests')
10const serversUtils = require('../../utils/servers') 10const serversUtils = require('../../utils/servers')
11const usersUtils = require('../../utils/users') 11const usersUtils = require('../../utils/users')
12const videosUtils = require('../../utils/videos')
12 13
13describe('Test users API validators', function () { 14describe('Test users API validators', function () {
14 const path = '/api/v1/users/' 15 const path = '/api/v1/users/'
15 let userId = null 16 let userId = null
16 let rootId = null 17 let rootId = null
18 let videoId = null
17 let server = null 19 let server = null
18 let userAccessToken = null 20 let userAccessToken = null
19 21
@@ -48,6 +50,23 @@ describe('Test users API validators', function () {
48 usersUtils.createUser(server.url, server.accessToken, username, password, next) 50 usersUtils.createUser(server.url, server.accessToken, username, password, next)
49 }, 51 },
50 function (next) { 52 function (next) {
53 const name = 'my super name for pod'
54 const description = 'my super description for pod'
55 const tags = [ 'tag' ]
56 const file = 'video_short2.webm'
57 videosUtils.uploadVideo(server.url, server.accessToken, name, description, tags, file, next)
58 },
59 function (next) {
60 videosUtils.getVideosList(server.url, function (err, res) {
61 if (err) throw err
62
63 const videos = res.body.data
64 videoId = videos[0].id
65
66 next()
67 })
68 },
69 function (next) {
51 const user = { 70 const user = {
52 username: 'user1', 71 username: 'user1',
53 password: 'my super password' 72 password: 'my super password'
@@ -289,6 +308,63 @@ describe('Test users API validators', function () {
289 }) 308 })
290 }) 309 })
291 310
311 describe('When getting my video rating', function () {
312 it('Should fail with a non authenticated user', function (done) {
313 request(server.url)
314 .get(path + 'me/videos/' + videoId + '/rating')
315 .set('Authorization', 'Bearer faketoken')
316 .set('Accept', 'application/json')
317 .expect(401, done)
318 })
319
320 it('Should fail with an incorrect video uuid', function (done) {
321 request(server.url)
322 .get(path + 'me/videos/blabla/rating')
323 .set('Authorization', 'Bearer ' + userAccessToken)
324 .set('Accept', 'application/json')
325 .expect(400, done)
326 })
327
328 it('Should fail with an unknown video', function (done) {
329 request(server.url)
330 .get(path + 'me/videos/4da6fde3-88f7-4d16-b119-108df5630b06/rating')
331 .set('Authorization', 'Bearer ' + userAccessToken)
332 .set('Accept', 'application/json')
333 .expect(404, done)
334 })
335
336 it('Should success with the correct parameters', function (done) {
337 request(server.url)
338 .get(path + 'me/videos/' + videoId + '/rating')
339 .set('Authorization', 'Bearer ' + userAccessToken)
340 .set('Accept', 'application/json')
341 .expect(200, done)
342 })
343 })
344
345 describe('When removing an user', function () {
346 it('Should fail with an incorrect id', function (done) {
347 request(server.url)
348 .delete(path + 'bla-bla')
349 .set('Authorization', 'Bearer ' + server.accessToken)
350 .expect(400, done)
351 })
352
353 it('Should fail with the root user', function (done) {
354 request(server.url)
355 .delete(path + rootId)
356 .set('Authorization', 'Bearer ' + server.accessToken)
357 .expect(400, done)
358 })
359
360 it('Should return 404 with a non existing id', function (done) {
361 request(server.url)
362 .delete(path + '45')
363 .set('Authorization', 'Bearer ' + server.accessToken)
364 .expect(404, done)
365 })
366 })
367
292 describe('When removing an user', function () { 368 describe('When removing an user', function () {
293 it('Should fail with an incorrect id', function (done) { 369 it('Should fail with an incorrect id', function (done) {
294 request(server.url) 370 request(server.url)
diff --git a/server/tests/api/check-params/videos.js b/server/tests/api/check-params/videos.js
index f8549a95b..0f5f40b8e 100644
--- a/server/tests/api/check-params/videos.js
+++ b/server/tests/api/check-params/videos.js
@@ -420,6 +420,48 @@ describe('Test videos API validator', function () {
420 it('Should succeed with the correct parameters') 420 it('Should succeed with the correct parameters')
421 }) 421 })
422 422
423 describe('When rating a video', function () {
424 let videoId
425
426 before(function (done) {
427 videosUtils.getVideosList(server.url, function (err, res) {
428 if (err) throw err
429
430 videoId = res.body.data[0].id
431
432 return done()
433 })
434 })
435
436 it('Should fail without a valid uuid', function (done) {
437 const data = {
438 rating: 'like'
439 }
440 requestsUtils.makePutBodyRequest(server.url, path + 'blabla/rate', server.accessToken, data, done)
441 })
442
443 it('Should fail with an unknown id', function (done) {
444 const data = {
445 rating: 'like'
446 }
447 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', server.accessToken, data, done, 404)
448 })
449
450 it('Should fail with a wrong rating', function (done) {
451 const data = {
452 rating: 'likes'
453 }
454 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done)
455 })
456
457 it('Should succeed with the correct parameters', function (done) {
458 const data = {
459 rating: 'like'
460 }
461 requestsUtils.makePutBodyRequest(server.url, path + videoId + '/rate', server.accessToken, data, done, 204)
462 })
463 })
464
423 describe('When removing a video', function () { 465 describe('When removing a video', function () {
424 it('Should have 404 with nothing', function (done) { 466 it('Should have 404 with nothing', function (done) {
425 request(server.url) 467 request(server.url)
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js
index e02b6180b..552f10c6f 100644
--- a/server/tests/api/multiple-pods.js
+++ b/server/tests/api/multiple-pods.js
@@ -4,6 +4,7 @@
4 4
5const chai = require('chai') 5const chai = require('chai')
6const each = require('async/each') 6const each = require('async/each')
7const eachSeries = require('async/eachSeries')
7const expect = chai.expect 8const expect = chai.expect
8const parallel = require('async/parallel') 9const parallel = require('async/parallel')
9const series = require('async/series') 10const series = require('async/series')
@@ -378,7 +379,7 @@ describe('Test multiple pods', function () {
378 }) 379 })
379 }) 380 })
380 381
381 describe('Should update video views', function () { 382 describe('Should update video views, likes and dislikes', function () {
382 let localVideosPod3 = [] 383 let localVideosPod3 = []
383 let remoteVideosPod1 = [] 384 let remoteVideosPod1 = []
384 let remoteVideosPod2 = [] 385 let remoteVideosPod2 = []
@@ -419,7 +420,7 @@ describe('Test multiple pods', function () {
419 ], done) 420 ], done)
420 }) 421 })
421 422
422 it('Should views multiple videos on owned servers', function (done) { 423 it('Should view multiple videos on owned servers', function (done) {
423 this.timeout(30000) 424 this.timeout(30000)
424 425
425 parallel([ 426 parallel([
@@ -440,18 +441,18 @@ describe('Test multiple pods', function () {
440 }, 441 },
441 442
442 function (callback) { 443 function (callback) {
443 setTimeout(done, 22000) 444 setTimeout(callback, 22000)
444 } 445 }
445 ], function (err) { 446 ], function (err) {
446 if (err) throw err 447 if (err) throw err
447 448
448 each(servers, function (server, callback) { 449 eachSeries(servers, function (server, callback) {
449 videosUtils.getVideosList(server.url, function (err, res) { 450 videosUtils.getVideosList(server.url, function (err, res) {
450 if (err) throw err 451 if (err) throw err
451 452
452 const videos = res.body.data 453 const videos = res.body.data
453 expect(videos.find(video => video.views === 3)).to.be.exist 454 expect(videos.find(video => video.views === 3)).to.exist
454 expect(videos.find(video => video.views === 1)).to.be.exist 455 expect(videos.find(video => video.views === 1)).to.exist
455 456
456 callback() 457 callback()
457 }) 458 })
@@ -459,7 +460,7 @@ describe('Test multiple pods', function () {
459 }) 460 })
460 }) 461 })
461 462
462 it('Should views multiple videos on each servers', function (done) { 463 it('Should view multiple videos on each servers', function (done) {
463 this.timeout(30000) 464 this.timeout(30000)
464 465
465 parallel([ 466 parallel([
@@ -504,17 +505,17 @@ describe('Test multiple pods', function () {
504 }, 505 },
505 506
506 function (callback) { 507 function (callback) {
507 setTimeout(done, 22000) 508 setTimeout(callback, 22000)
508 } 509 }
509 ], function (err) { 510 ], function (err) {
510 if (err) throw err 511 if (err) throw err
511 512
512 let baseVideos = null 513 let baseVideos = null
513 each(servers, function (server, callback) { 514 eachSeries(servers, function (server, callback) {
514 videosUtils.getVideosList(server.url, function (err, res) { 515 videosUtils.getVideosList(server.url, function (err, res) {
515 if (err) throw err 516 if (err) throw err
516 517
517 const videos = res.body 518 const videos = res.body.data
518 519
519 // Initialize base videos for future comparisons 520 // Initialize base videos for future comparisons
520 if (baseVideos === null) { 521 if (baseVideos === null) {
@@ -522,10 +523,74 @@ describe('Test multiple pods', function () {
522 return callback() 523 return callback()
523 } 524 }
524 525
525 for (let i = 0; i < baseVideos.length; i++) { 526 baseVideos.forEach(baseVideo => {
526 expect(baseVideos[i].views).to.equal(videos[i].views) 527 const sameVideo = videos.find(video => video.name === baseVideo.name)
528 expect(baseVideo.views).to.equal(sameVideo.views)
529 })
530
531 callback()
532 })
533 }, done)
534 })
535 })
536
537 it('Should like and dislikes videos on different services', function (done) {
538 this.timeout(30000)
539
540 parallel([
541 function (callback) {
542 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
543 },
544
545 function (callback) {
546 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'dislike', callback)
547 },
548
549 function (callback) {
550 videosUtils.rateVideo(servers[0].url, servers[0].accessToken, remoteVideosPod1[0], 'like', callback)
551 },
552
553 function (callback) {
554 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'like', callback)
555 },
556
557 function (callback) {
558 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, localVideosPod3[1], 'dislike', callback)
559 },
560
561 function (callback) {
562 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[1], 'dislike', callback)
563 },
564
565 function (callback) {
566 videosUtils.rateVideo(servers[2].url, servers[2].accessToken, remoteVideosPod3[0], 'like', callback)
567 },
568
569 function (callback) {
570 setTimeout(callback, 22000)
571 }
572 ], function (err) {
573 if (err) throw err
574
575 let baseVideos = null
576 eachSeries(servers, function (server, callback) {
577 videosUtils.getVideosList(server.url, function (err, res) {
578 if (err) throw err
579
580 const videos = res.body.data
581
582 // Initialize base videos for future comparisons
583 if (baseVideos === null) {
584 baseVideos = videos
585 return callback()
527 } 586 }
528 587
588 baseVideos.forEach(baseVideo => {
589 const sameVideo = videos.find(video => video.name === baseVideo.name)
590 expect(baseVideo.likes).to.equal(sameVideo.likes)
591 expect(baseVideo.dislikes).to.equal(sameVideo.dislikes)
592 })
593
529 callback() 594 callback()
530 }) 595 })
531 }, done) 596 }, done)
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 87d0e9a71..96e4aff9e 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -609,6 +609,40 @@ describe('Test a single pod', function () {
609 }) 609 })
610 }) 610 })
611 611
612 it('Should like a video', function (done) {
613 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) {
614 if (err) throw err
615
616 videosUtils.getVideo(server.url, videoId, function (err, res) {
617 if (err) throw err
618
619 const video = res.body
620
621 expect(video.likes).to.equal(1)
622 expect(video.dislikes).to.equal(0)
623
624 done()
625 })
626 })
627 })
628
629 it('Should dislike the same video', function (done) {
630 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) {
631 if (err) throw err
632
633 videosUtils.getVideo(server.url, videoId, function (err, res) {
634 if (err) throw err
635
636 const video = res.body
637
638 expect(video.likes).to.equal(0)
639 expect(video.dislikes).to.equal(1)
640
641 done()
642 })
643 })
644 })
645
612 after(function (done) { 646 after(function (done) {
613 process.kill(-server.app.pid) 647 process.kill(-server.app.pid)
614 648
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index bd95e78c2..f9568b874 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -10,6 +10,7 @@ const loginUtils = require('../utils/login')
10const podsUtils = require('../utils/pods') 10const podsUtils = require('../utils/pods')
11const serversUtils = require('../utils/servers') 11const serversUtils = require('../utils/servers')
12const usersUtils = require('../utils/users') 12const usersUtils = require('../utils/users')
13const requestsUtils = require('../utils/requests')
13const videosUtils = require('../utils/videos') 14const videosUtils = require('../utils/videos')
14 15
15describe('Test users', function () { 16describe('Test users', function () {
@@ -138,6 +139,23 @@ describe('Test users', function () {
138 videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done) 139 videosUtils.uploadVideo(server.url, accessToken, name, description, tags, video, 204, done)
139 }) 140 })
140 141
142 it('Should retrieve a video rating', function (done) {
143 videosUtils.rateVideo(server.url, accessToken, videoId, 'like', function (err) {
144 if (err) throw err
145
146 usersUtils.getUserVideoRating(server.url, accessToken, videoId, function (err, res) {
147 if (err) throw err
148
149 const rating = res.body
150
151 expect(rating.videoId).to.equal(videoId)
152 expect(rating.rating).to.equal('like')
153
154 done()
155 })
156 })
157 })
158
141 it('Should not be able to remove the video with an incorrect token', function (done) { 159 it('Should not be able to remove the video with an incorrect token', function (done) {
142 videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done) 160 videosUtils.removeVideo(server.url, 'bad_token', videoId, 401, done)
143 }) 161 })
@@ -150,10 +168,21 @@ describe('Test users', function () {
150 168
151 it('Should logout (revoke token)') 169 it('Should logout (revoke token)')
152 170
171 it('Should not be able to get the user informations')
172
153 it('Should not be able to upload a video') 173 it('Should not be able to upload a video')
154 174
155 it('Should not be able to remove a video') 175 it('Should not be able to remove a video')
156 176
177 it('Should not be able to rate a video', function (done) {
178 const path = '/api/v1/videos/'
179 const data = {
180 rating: 'likes'
181 }
182
183 requestsUtils.makePutBodyRequest(server.url, path + videoId, 'wrong token', data, done, 401)
184 })
185
157 it('Should be able to login again') 186 it('Should be able to login again')
158 187
159 it('Should have an expired access token') 188 it('Should have an expired access token')