]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/single-pod.js
1 /* eslint-disable no-unused-expressions */
5 const chai
= require('chai')
6 const each
= require('async/each')
7 const expect
= chai
.expect
8 const fs
= require('fs')
9 const keyBy
= require('lodash/keyBy')
10 const pathUtils
= require('path')
11 const series
= require('async/series')
12 const webtorrent
= new (require('webtorrent'))()
14 const loginUtils
= require('../utils/login')
15 const miscsUtils
= require('../utils/miscs')
16 const serversUtils
= require('../utils/servers')
17 const videosUtils
= require('../utils/videos')
19 describe('Test a single pod', function () {
22 let videosListBase
= null
24 before(function (done
) {
29 serversUtils
.flushTests(next
)
32 serversUtils
.runServer(1, function (server1
) {
38 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
40 server
.accessToken
= token
47 it('Should list video categories', function (done
) {
48 videosUtils
.getVideoCategories(server
.url
, function (err
, res
) {
51 const categories
= res
.body
52 expect(Object
.keys(categories
)).to
.have
.length
.above(10)
54 expect(categories
[11]).to
.equal('News')
60 it('Should list video licences', function (done
) {
61 videosUtils
.getVideoLicences(server
.url
, function (err
, res
) {
64 const licences
= res
.body
65 expect(Object
.keys(licences
)).to
.have
.length
.above(5)
67 expect(licences
[3]).to
.equal('Attribution - No Derivatives')
73 it('Should not have videos', function (done
) {
74 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
77 expect(res
.body
.total
).to
.equal(0)
78 expect(res
.body
.data
).to
.be
.an('array')
79 expect(res
.body
.data
.length
).to
.equal(0)
85 it('Should upload the video', function (done
) {
86 const videoAttributes
= {
87 name: 'my super name',
90 tags: [ 'tag1', 'tag2', 'tag3' ]
92 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, done
)
95 it('Should seed the uploaded video', function (done
) {
96 // Yes, this could be long
99 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
102 expect(res
.body
.total
).to
.equal(1)
103 expect(res
.body
.data
).to
.be
.an('array')
104 expect(res
.body
.data
.length
).to
.equal(1)
106 const video
= res
.body
.data
[0]
107 expect(video
.name
).to
.equal('my super name')
108 expect(video
.category
).to
.equal(2)
109 expect(video
.categoryLabel
).to
.equal('Films')
110 expect(video
.licence
).to
.equal(6)
111 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
112 expect(video
.description
).to
.equal('my super description')
113 expect(video
.podHost
).to
.equal('localhost:9001')
114 expect(video
.magnetUri
).to
.exist
115 expect(video
.author
).to
.equal('root')
116 expect(video
.isLocal
).to
.be
.true
117 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
118 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
119 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
121 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
123 expect(test
).to
.equal(true)
127 webtorrent
.add(video
.magnetUri
, function (torrent
) {
128 expect(torrent
.files
).to
.exist
129 expect(torrent
.files
.length
).to
.equal(1)
130 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
138 it('Should get the video', function (done
) {
139 // Yes, this could be long
142 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
145 const video
= res
.body
146 expect(video
.name
).to
.equal('my super name')
147 expect(video
.category
).to
.equal(2)
148 expect(video
.categoryLabel
).to
.equal('Films')
149 expect(video
.licence
).to
.equal(6)
150 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
151 expect(video
.description
).to
.equal('my super description')
152 expect(video
.podHost
).to
.equal('localhost:9001')
153 expect(video
.magnetUri
).to
.exist
154 expect(video
.author
).to
.equal('root')
155 expect(video
.isLocal
).to
.be
.true
156 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
157 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
158 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
160 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
162 expect(test
).to
.equal(true)
169 it('Should have the views updated', function (done
) {
170 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
173 const video
= res
.body
174 expect(video
.views
).to
.equal(1)
180 it('Should search the video by name by default', function (done
) {
181 videosUtils
.searchVideo(server
.url
, 'my', function (err
, res
) {
184 expect(res
.body
.total
).to
.equal(1)
185 expect(res
.body
.data
).to
.be
.an('array')
186 expect(res
.body
.data
.length
).to
.equal(1)
188 const video
= res
.body
.data
[0]
189 expect(video
.name
).to
.equal('my super name')
190 expect(video
.category
).to
.equal(2)
191 expect(video
.categoryLabel
).to
.equal('Films')
192 expect(video
.licence
).to
.equal(6)
193 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
194 expect(video
.description
).to
.equal('my super description')
195 expect(video
.podHost
).to
.equal('localhost:9001')
196 expect(video
.author
).to
.equal('root')
197 expect(video
.isLocal
).to
.be
.true
198 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
199 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
200 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
202 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
204 expect(test
).to
.equal(true)
211 // Not implemented yet
212 // it('Should search the video by podHost', function (done) {
213 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
214 // if (err) throw err
216 // expect(res.body.total).to.equal(1)
217 // expect(res.body.data).to.be.an('array')
218 // expect(res.body.data.length).to.equal(1)
220 // const video = res.body.data[0]
221 // expect(video.name).to.equal('my super name')
222 // expect(video.description).to.equal('my super description')
223 // expect(video.podHost).to.equal('localhost:9001')
224 // expect(video.author).to.equal('root')
225 // expect(video.isLocal).to.be.true
226 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
227 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
228 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
230 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
231 // if (err) throw err
232 // expect(test).to.equal(true)
239 it('Should search the video by tag', function (done
) {
240 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
243 expect(res
.body
.total
).to
.equal(1)
244 expect(res
.body
.data
).to
.be
.an('array')
245 expect(res
.body
.data
.length
).to
.equal(1)
247 const video
= res
.body
.data
[0]
248 expect(video
.name
).to
.equal('my super name')
249 expect(video
.category
).to
.equal(2)
250 expect(video
.categoryLabel
).to
.equal('Films')
251 expect(video
.licence
).to
.equal(6)
252 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
253 expect(video
.description
).to
.equal('my super description')
254 expect(video
.podHost
).to
.equal('localhost:9001')
255 expect(video
.author
).to
.equal('root')
256 expect(video
.isLocal
).to
.be
.true
257 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
258 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
259 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
261 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
263 expect(test
).to
.equal(true)
270 it('Should not find a search by name by default', function (done
) {
271 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
274 expect(res
.body
.total
).to
.equal(0)
275 expect(res
.body
.data
).to
.be
.an('array')
276 expect(res
.body
.data
.length
).to
.equal(0)
282 it('Should not find a search by author', function (done
) {
283 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
286 expect(res
.body
.total
).to
.equal(0)
287 expect(res
.body
.data
).to
.be
.an('array')
288 expect(res
.body
.data
.length
).to
.equal(0)
294 it('Should not find a search by tag', function (done
) {
295 videosUtils
.searchVideo(server
.url
, 'hello', 'tags', function (err
, res
) {
298 expect(res
.body
.total
).to
.equal(0)
299 expect(res
.body
.data
).to
.be
.an('array')
300 expect(res
.body
.data
.length
).to
.equal(0)
306 it('Should remove the video', function (done
) {
307 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
310 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/videos/'), function (err
, files
) {
313 expect(files
.length
).to
.equal(0)
315 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/thumbnails/'), function (err
, files
) {
318 expect(files
.length
).to
.equal(0)
326 it('Should not have videos', function (done
) {
327 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
330 expect(res
.body
.total
).to
.equal(0)
331 expect(res
.body
.data
).to
.be
.an('array')
332 expect(res
.body
.data
.length
).to
.equal(0)
338 it('Should upload 6 videos', function (done
) {
341 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
342 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
344 each(videos
, function (video
, callbackEach
) {
345 const videoAttributes
= {
346 name: video
+ ' name',
347 description: video
+ ' description',
350 tags: [ 'tag1', 'tag2', 'tag3' ],
354 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, callbackEach
)
358 it('Should have the correct durations', function (done
) {
359 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
362 expect(res
.body
.total
).to
.equal(6)
363 const videos
= res
.body
.data
364 expect(videos
).to
.be
.an('array')
365 expect(videos
.length
).to
.equal(6)
367 const videosByName
= keyBy(videos
, 'name')
368 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
369 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
370 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
371 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
372 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
373 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
379 it('Should have the correct thumbnails', function (done
) {
380 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
383 const videos
= res
.body
.data
385 videosListBase
= videos
387 each(videos
, function (video
, callbackEach
) {
389 const videoName
= video
.name
.replace(' name', '')
391 videosUtils
.testVideoImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
394 expect(test
).to
.equal(true)
401 it('Should list only the two first videos', function (done
) {
402 videosUtils
.getVideosListPagination(server
.url
, 0, 2, 'name', function (err
, res
) {
405 const videos
= res
.body
.data
406 expect(res
.body
.total
).to
.equal(6)
407 expect(videos
.length
).to
.equal(2)
408 expect(videos
[0].name
).to
.equal(videosListBase
[0].name
)
409 expect(videos
[1].name
).to
.equal(videosListBase
[1].name
)
415 it('Should list only the next three videos', function (done
) {
416 videosUtils
.getVideosListPagination(server
.url
, 2, 3, 'name', function (err
, res
) {
419 const videos
= res
.body
.data
420 expect(res
.body
.total
).to
.equal(6)
421 expect(videos
.length
).to
.equal(3)
422 expect(videos
[0].name
).to
.equal(videosListBase
[2].name
)
423 expect(videos
[1].name
).to
.equal(videosListBase
[3].name
)
424 expect(videos
[2].name
).to
.equal(videosListBase
[4].name
)
430 it('Should list the last video', function (done
) {
431 videosUtils
.getVideosListPagination(server
.url
, 5, 6, 'name', function (err
, res
) {
434 const videos
= res
.body
.data
435 expect(res
.body
.total
).to
.equal(6)
436 expect(videos
.length
).to
.equal(1)
437 expect(videos
[0].name
).to
.equal(videosListBase
[5].name
)
443 it('Should search the first video', function (done
) {
444 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, 'name', function (err
, res
) {
447 const videos
= res
.body
.data
448 expect(res
.body
.total
).to
.equal(4)
449 expect(videos
.length
).to
.equal(1)
450 expect(videos
[0].name
).to
.equal('video_short1.webm name')
456 it('Should search the last two videos', function (done
) {
457 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, 'name', function (err
, res
) {
460 const videos
= res
.body
.data
461 expect(res
.body
.total
).to
.equal(4)
462 expect(videos
.length
).to
.equal(2)
463 expect(videos
[0].name
).to
.equal('video_short3.webm name')
464 expect(videos
[1].name
).to
.equal('video_short.webm name')
470 it('Should search all the webm videos', function (done
) {
471 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
474 const videos
= res
.body
.data
475 expect(res
.body
.total
).to
.equal(4)
476 expect(videos
.length
).to
.equal(4)
482 it('Should search all the root author videos', function (done
) {
483 videosUtils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
486 const videos
= res
.body
.data
487 expect(res
.body
.total
).to
.equal(6)
488 expect(videos
.length
).to
.equal(6)
494 // Not implemented yet
495 // it('Should search all the 9001 port videos', function (done) {
496 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
497 // if (err) throw err
499 // const videos = res.body.data
500 // expect(res.body.total).to.equal(6)
501 // expect(videos.length).to.equal(6)
507 // it('Should search all the localhost videos', function (done) {
508 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
509 // if (err) throw err
511 // const videos = res.body.data
512 // expect(res.body.total).to.equal(6)
513 // expect(videos.length).to.equal(6)
519 it('Should search the right magnetUri video', function (done
) {
520 const video
= videosListBase
[0]
521 videosUtils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
524 const videos
= res
.body
.data
525 expect(res
.body
.total
).to
.equal(1)
526 expect(videos
.length
).to
.equal(1)
527 expect(videos
[0].name
).to
.equal(video
.name
)
533 it('Should list and sort by name in descending order', function (done
) {
534 videosUtils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
537 const videos
= res
.body
.data
538 expect(res
.body
.total
).to
.equal(6)
539 expect(videos
.length
).to
.equal(6)
540 expect(videos
[0].name
).to
.equal('video_short.webm name')
541 expect(videos
[1].name
).to
.equal('video_short.ogv name')
542 expect(videos
[2].name
).to
.equal('video_short.mp4 name')
543 expect(videos
[3].name
).to
.equal('video_short3.webm name')
544 expect(videos
[4].name
).to
.equal('video_short2.webm name')
545 expect(videos
[5].name
).to
.equal('video_short1.webm name')
551 it('Should search and sort by name in ascending order', function (done
) {
552 videosUtils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
555 const videos
= res
.body
.data
556 expect(res
.body
.total
).to
.equal(4)
557 expect(videos
.length
).to
.equal(4)
559 expect(videos
[0].name
).to
.equal('video_short1.webm name')
560 expect(videos
[1].name
).to
.equal('video_short2.webm name')
561 expect(videos
[2].name
).to
.equal('video_short3.webm name')
562 expect(videos
[3].name
).to
.equal('video_short.webm name')
564 videoId
= videos
[2].id
570 it('Should update a video', function (done
) {
572 name: 'my super video updated',
575 description: 'my super description updated',
576 tags: [ 'tagup1', 'tagup2' ]
578 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, done
)
581 it('Should have the video updated', function (done
) {
584 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
587 const video
= res
.body
589 expect(video
.name
).to
.equal('my super video updated')
590 expect(video
.category
).to
.equal(4)
591 expect(video
.categoryLabel
).to
.equal('Art')
592 expect(video
.licence
).to
.equal(2)
593 expect(video
.licenceLabel
).to
.equal('Attribution - Share Alike')
594 expect(video
.description
).to
.equal('my super description updated')
595 expect(video
.podHost
).to
.equal('localhost:9001')
596 expect(video
.author
).to
.equal('root')
597 expect(video
.isLocal
).to
.be
.true
598 expect(video
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
599 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
600 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
602 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video
.thumbnailPath
, function (err
, test
) {
604 expect(test
).to
.equal(true)
606 webtorrent
.add(video
.magnetUri
, function (torrent
) {
607 expect(torrent
.files
).to
.exist
608 expect(torrent
.files
.length
).to
.equal(1)
609 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
617 it('Should update only the tags of a video', function (done
) {
619 tags: [ 'tag1', 'tag2', 'supertag' ]
622 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, function (err
) {
625 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
628 const video
= res
.body
630 expect(video
.name
).to
.equal('my super video updated')
631 expect(video
.category
).to
.equal(4)
632 expect(video
.categoryLabel
).to
.equal('Art')
633 expect(video
.licence
).to
.equal(2)
634 expect(video
.licenceLabel
).to
.equal('Attribution - Share Alike')
635 expect(video
.description
).to
.equal('my super description updated')
636 expect(video
.podHost
).to
.equal('localhost:9001')
637 expect(video
.author
).to
.equal('root')
638 expect(video
.isLocal
).to
.be
.true
639 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
640 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
641 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
648 it('Should update only the description of a video', function (done
) {
650 description: 'hello everybody'
653 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, function (err
) {
656 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
659 const video
= res
.body
661 expect(video
.name
).to
.equal('my super video updated')
662 expect(video
.category
).to
.equal(4)
663 expect(video
.categoryLabel
).to
.equal('Art')
664 expect(video
.licence
).to
.equal(2)
665 expect(video
.licenceLabel
).to
.equal('Attribution - Share Alike')
666 expect(video
.description
).to
.equal('hello everybody')
667 expect(video
.podHost
).to
.equal('localhost:9001')
668 expect(video
.author
).to
.equal('root')
669 expect(video
.isLocal
).to
.be
.true
670 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
671 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
672 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
679 it('Should like a video', function (done
) {
680 videosUtils
.rateVideo(server
.url
, server
.accessToken
, videoId
, 'like', function (err
) {
683 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
686 const video
= res
.body
688 expect(video
.likes
).to
.equal(1)
689 expect(video
.dislikes
).to
.equal(0)
696 it('Should dislike the same video', function (done
) {
697 videosUtils
.rateVideo(server
.url
, server
.accessToken
, videoId
, 'dislike', function (err
) {
700 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
703 const video
= res
.body
705 expect(video
.likes
).to
.equal(0)
706 expect(video
.dislikes
).to
.equal(1)
713 after(function (done
) {
714 process
.kill(-server
.app
.pid
)
716 // Keep the logs if the test failed
718 serversUtils
.flushTests(done
)