aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-12-29 19:07:05 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-12-29 19:07:05 +0100
commit7b1f49de22c40ae121ddb3c399b2540ba56fd414 (patch)
tree269e5dc7c2ebe4147319f1ee8e8b7f3c74549149 /server/tests/api
parent4ff0d86208dafbdd07beb6286fd93c795db8a95f (diff)
downloadPeerTube-7b1f49de22c40ae121ddb3c399b2540ba56fd414.tar.gz
PeerTube-7b1f49de22c40ae121ddb3c399b2540ba56fd414.tar.zst
PeerTube-7b1f49de22c40ae121ddb3c399b2540ba56fd414.zip
Server: add ability to update a video
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params.js101
-rw-r--r--server/tests/api/single-pod.js76
2 files changed, 177 insertions, 0 deletions
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js
index 9aecc3720..e8f2aa821 100644
--- a/server/tests/api/check-params.js
+++ b/server/tests/api/check-params.js
@@ -10,6 +10,7 @@ const loginUtils = require('../utils/login')
10const requestsUtils = require('../utils/requests') 10const requestsUtils = require('../utils/requests')
11const serversUtils = require('../utils/servers') 11const serversUtils = require('../utils/servers')
12const usersUtils = require('../utils/users') 12const usersUtils = require('../utils/users')
13const videosUtils = require('../utils/videos')
13 14
14describe('Test parameters validator', function () { 15describe('Test parameters validator', function () {
15 let server = null 16 let server = null
@@ -439,6 +440,106 @@ describe('Test parameters validator', function () {
439 }) 440 })
440 }) 441 })
441 442
443 describe('When updating a video', function () {
444 let videoId
445
446 before(function (done) {
447 videosUtils.getVideosList(server.url, function (err, res) {
448 if (err) throw err
449
450 videoId = res.body.data[0].id
451
452 return done()
453 })
454 })
455
456 it('Should fail with nothing', function (done) {
457 const data = {}
458 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
459 })
460
461 it('Should fail without a valid uuid', function (done) {
462 const data = {
463 description: 'my super description',
464 tags: [ 'tag1', 'tag2' ]
465 }
466 requestsUtils.makePutBodyRequest(server.url, path + 'blabla', server.accessToken, data, done)
467 })
468
469 it('Should fail with an unknown id', function (done) {
470 const data = {
471 description: 'my super description',
472 tags: [ 'tag1', 'tag2' ]
473 }
474 requestsUtils.makePutBodyRequest(server.url, path + '4da6fde3-88f7-4d16-b119-108df5630b06', server.accessToken, data, done)
475 })
476
477 it('Should fail with a long name', function (done) {
478 const data = {
479 name: 'My very very very very very very very very very very very very very very very very long name',
480 description: 'my super description',
481 tags: [ 'tag1', 'tag2' ]
482 }
483 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
484 })
485
486 it('Should fail with a long description', function (done) {
487 const data = {
488 name: 'my super name',
489 description: 'my super description which is very very very very very very very very very very very very very very' +
490 'very very very very very very very very very very very very very very very very very very very very very' +
491 'very very very very very very very very very very very very very very very long',
492 tags: [ 'tag1', 'tag2' ]
493 }
494 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
495 })
496
497 it('Should fail with too many tags', function (done) {
498 const data = {
499 name: 'my super name',
500 description: 'my super description',
501 tags: [ 'tag1', 'tag2', 'tag3', 'tag4' ]
502 }
503 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
504 })
505
506 it('Should fail with not enough tags', function (done) {
507 const data = {
508 name: 'my super name',
509 description: 'my super description',
510 tags: [ ]
511 }
512 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
513 })
514
515 it('Should fail with a tag length too low', function (done) {
516 const data = {
517 name: 'my super name',
518 description: 'my super description',
519 tags: [ 'tag1', 't' ]
520 }
521 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
522 })
523
524 it('Should fail with a tag length too big', function (done) {
525 const data = {
526 name: 'my super name',
527 description: 'my super description',
528 tags: [ 'mysupertagtoolong', 'tag1' ]
529 }
530 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
531 })
532
533 it('Should fail with malformed tags', function (done) {
534 const data = {
535 name: 'my super name',
536 description: 'my super description',
537 tags: [ 'my tag' ]
538 }
539 requestsUtils.makePutBodyRequest(server.url, path + videoId, server.accessToken, data, done)
540 })
541 })
542
442 describe('When getting a video', function () { 543 describe('When getting a video', function () {
443 it('Should return the list of the videos with nothing', function (done) { 544 it('Should return the list of the videos with nothing', function (done) {
444 request(server.url) 545 request(server.url)
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 66b762f82..57146900d 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -495,10 +495,86 @@ describe('Test a single pod', function () {
495 expect(videos[2].name === 'video_short2.webm name') 495 expect(videos[2].name === 'video_short2.webm name')
496 expect(videos[3].name === 'video_short3.webm name') 496 expect(videos[3].name === 'video_short3.webm name')
497 497
498 videoId = videos[3].id
499
498 done() 500 done()
499 }) 501 })
500 }) 502 })
501 503
504 it('Should update a video', function (done) {
505 const name = 'my super video updated'
506 const description = 'my super description updated'
507 const tags = [ 'tagup1', 'tagup2' ]
508
509 videosUtils.updateVideo(server.url, server.accessToken, videoId, name, description, tags, done)
510 })
511
512 it('Should have the video updated', function (done) {
513 videosUtils.getVideo(server.url, videoId, function (err, res) {
514 if (err) throw err
515
516 const video = res.body
517
518 expect(video.name).to.equal('my super video updated')
519 expect(video.description).to.equal('my super description updated')
520 expect(video.podHost).to.equal('localhost:9001')
521 expect(video.author).to.equal('root')
522 expect(video.isLocal).to.be.true
523 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
524 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
525
526 done()
527 })
528 })
529
530 it('Should update only the tags of a video', function (done) {
531 const tags = [ 'tag1', 'tag2', 'supertag' ]
532
533 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, null, tags, function (err) {
534 if (err) throw err
535
536 videosUtils.getVideo(server.url, videoId, function (err, res) {
537 if (err) throw err
538
539 const video = res.body
540
541 expect(video.name).to.equal('my super video updated')
542 expect(video.description).to.equal('my super description updated')
543 expect(video.podHost).to.equal('localhost:9001')
544 expect(video.author).to.equal('root')
545 expect(video.isLocal).to.be.true
546 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
547 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
548
549 done()
550 })
551 })
552 })
553
554 it('Should update only the description of a video', function (done) {
555 const description = 'hello everybody'
556
557 videosUtils.updateVideo(server.url, server.accessToken, videoId, null, description, null, function (err) {
558 if (err) throw err
559
560 videosUtils.getVideo(server.url, videoId, function (err, res) {
561 if (err) throw err
562
563 const video = res.body
564
565 expect(video.name).to.equal('my super video updated')
566 expect(video.description).to.equal('hello everybody')
567 expect(video.podHost).to.equal('localhost:9001')
568 expect(video.author).to.equal('root')
569 expect(video.isLocal).to.be.true
570 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
571 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
572
573 done()
574 })
575 })
576 })
577
502 after(function (done) { 578 after(function (done) {
503 process.kill(-server.app.pid) 579 process.kill(-server.app.pid)
504 580