]>
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 not have videos', function (done
) {
61 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
64 expect(res
.body
.total
).to
.equal(0)
65 expect(res
.body
.data
).to
.be
.an('array')
66 expect(res
.body
.data
.length
).to
.equal(0)
72 it('Should upload the video', function (done
) {
73 const videoAttributes
= {
74 name: 'my super name',
76 tags: [ 'tag1', 'tag2', 'tag3' ]
78 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, done
)
81 it('Should seed the uploaded video', function (done
) {
82 // Yes, this could be long
85 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
88 expect(res
.body
.total
).to
.equal(1)
89 expect(res
.body
.data
).to
.be
.an('array')
90 expect(res
.body
.data
.length
).to
.equal(1)
92 const video
= res
.body
.data
[0]
93 expect(video
.name
).to
.equal('my super name')
94 expect(video
.category
).to
.equal(2)
95 expect(video
.categoryLabel
).to
.equal('Films')
96 expect(video
.description
).to
.equal('my super description')
97 expect(video
.podHost
).to
.equal('localhost:9001')
98 expect(video
.magnetUri
).to
.exist
99 expect(video
.author
).to
.equal('root')
100 expect(video
.isLocal
).to
.be
.true
101 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
102 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
103 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
105 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
107 expect(test
).to
.equal(true)
111 webtorrent
.add(video
.magnetUri
, function (torrent
) {
112 expect(torrent
.files
).to
.exist
113 expect(torrent
.files
.length
).to
.equal(1)
114 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
122 it('Should get the video', function (done
) {
123 // Yes, this could be long
126 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
129 const video
= res
.body
130 expect(video
.name
).to
.equal('my super name')
131 expect(video
.category
).to
.equal(2)
132 expect(video
.categoryLabel
).to
.equal('Films')
133 expect(video
.description
).to
.equal('my super description')
134 expect(video
.podHost
).to
.equal('localhost:9001')
135 expect(video
.magnetUri
).to
.exist
136 expect(video
.author
).to
.equal('root')
137 expect(video
.isLocal
).to
.be
.true
138 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
139 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
140 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
142 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
144 expect(test
).to
.equal(true)
151 it('Should have the views updated', function (done
) {
152 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
155 const video
= res
.body
156 expect(video
.views
).to
.equal(1)
162 it('Should search the video by name by default', function (done
) {
163 videosUtils
.searchVideo(server
.url
, 'my', function (err
, res
) {
166 expect(res
.body
.total
).to
.equal(1)
167 expect(res
.body
.data
).to
.be
.an('array')
168 expect(res
.body
.data
.length
).to
.equal(1)
170 const video
= res
.body
.data
[0]
171 expect(video
.name
).to
.equal('my super name')
172 expect(video
.category
).to
.equal(2)
173 expect(video
.categoryLabel
).to
.equal('Films')
174 expect(video
.description
).to
.equal('my super description')
175 expect(video
.podHost
).to
.equal('localhost:9001')
176 expect(video
.author
).to
.equal('root')
177 expect(video
.isLocal
).to
.be
.true
178 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
179 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
180 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
182 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
184 expect(test
).to
.equal(true)
191 // Not implemented yet
192 // it('Should search the video by podHost', function (done) {
193 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
194 // if (err) throw err
196 // expect(res.body.total).to.equal(1)
197 // expect(res.body.data).to.be.an('array')
198 // expect(res.body.data.length).to.equal(1)
200 // const video = res.body.data[0]
201 // expect(video.name).to.equal('my super name')
202 // expect(video.description).to.equal('my super description')
203 // expect(video.podHost).to.equal('localhost:9001')
204 // expect(video.author).to.equal('root')
205 // expect(video.isLocal).to.be.true
206 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
207 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
208 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
210 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
211 // if (err) throw err
212 // expect(test).to.equal(true)
219 it('Should search the video by tag', function (done
) {
220 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
223 expect(res
.body
.total
).to
.equal(1)
224 expect(res
.body
.data
).to
.be
.an('array')
225 expect(res
.body
.data
.length
).to
.equal(1)
227 const video
= res
.body
.data
[0]
228 expect(video
.name
).to
.equal('my super name')
229 expect(video
.category
).to
.equal(2)
230 expect(video
.categoryLabel
).to
.equal('Films')
231 expect(video
.description
).to
.equal('my super description')
232 expect(video
.podHost
).to
.equal('localhost:9001')
233 expect(video
.author
).to
.equal('root')
234 expect(video
.isLocal
).to
.be
.true
235 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
236 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
237 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
239 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
241 expect(test
).to
.equal(true)
248 it('Should not find a search by name by default', function (done
) {
249 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
252 expect(res
.body
.total
).to
.equal(0)
253 expect(res
.body
.data
).to
.be
.an('array')
254 expect(res
.body
.data
.length
).to
.equal(0)
260 it('Should not find a search by author', function (done
) {
261 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
264 expect(res
.body
.total
).to
.equal(0)
265 expect(res
.body
.data
).to
.be
.an('array')
266 expect(res
.body
.data
.length
).to
.equal(0)
272 it('Should not find a search by tag', function (done
) {
273 videosUtils
.searchVideo(server
.url
, 'hello', 'tags', function (err
, res
) {
276 expect(res
.body
.total
).to
.equal(0)
277 expect(res
.body
.data
).to
.be
.an('array')
278 expect(res
.body
.data
.length
).to
.equal(0)
284 it('Should remove the video', function (done
) {
285 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
288 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/videos/'), function (err
, files
) {
291 expect(files
.length
).to
.equal(0)
293 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/thumbnails/'), function (err
, files
) {
296 expect(files
.length
).to
.equal(0)
304 it('Should not have videos', function (done
) {
305 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
308 expect(res
.body
.total
).to
.equal(0)
309 expect(res
.body
.data
).to
.be
.an('array')
310 expect(res
.body
.data
.length
).to
.equal(0)
316 it('Should upload 6 videos', function (done
) {
319 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
320 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
322 each(videos
, function (video
, callbackEach
) {
323 const videoAttributes
= {
324 name: video
+ ' name',
325 description: video
+ ' description',
327 tags: [ 'tag1', 'tag2', 'tag3' ],
331 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, callbackEach
)
335 it('Should have the correct durations', function (done
) {
336 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
339 expect(res
.body
.total
).to
.equal(6)
340 const videos
= res
.body
.data
341 expect(videos
).to
.be
.an('array')
342 expect(videos
.length
).to
.equal(6)
344 const videosByName
= keyBy(videos
, 'name')
345 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
346 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
347 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
348 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
349 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
350 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
356 it('Should have the correct thumbnails', function (done
) {
357 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
360 const videos
= res
.body
.data
362 videosListBase
= videos
364 each(videos
, function (video
, callbackEach
) {
366 const videoName
= video
.name
.replace(' name', '')
368 videosUtils
.testVideoImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
371 expect(test
).to
.equal(true)
378 it('Should list only the two first videos', function (done
) {
379 videosUtils
.getVideosListPagination(server
.url
, 0, 2, 'name', function (err
, res
) {
382 const videos
= res
.body
.data
383 expect(res
.body
.total
).to
.equal(6)
384 expect(videos
.length
).to
.equal(2)
385 expect(videos
[0].name
).to
.equal(videosListBase
[0].name
)
386 expect(videos
[1].name
).to
.equal(videosListBase
[1].name
)
392 it('Should list only the next three videos', function (done
) {
393 videosUtils
.getVideosListPagination(server
.url
, 2, 3, 'name', function (err
, res
) {
396 const videos
= res
.body
.data
397 expect(res
.body
.total
).to
.equal(6)
398 expect(videos
.length
).to
.equal(3)
399 expect(videos
[0].name
).to
.equal(videosListBase
[2].name
)
400 expect(videos
[1].name
).to
.equal(videosListBase
[3].name
)
401 expect(videos
[2].name
).to
.equal(videosListBase
[4].name
)
407 it('Should list the last video', function (done
) {
408 videosUtils
.getVideosListPagination(server
.url
, 5, 6, 'name', function (err
, res
) {
411 const videos
= res
.body
.data
412 expect(res
.body
.total
).to
.equal(6)
413 expect(videos
.length
).to
.equal(1)
414 expect(videos
[0].name
).to
.equal(videosListBase
[5].name
)
420 it('Should search the first video', function (done
) {
421 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, 'name', function (err
, res
) {
424 const videos
= res
.body
.data
425 expect(res
.body
.total
).to
.equal(4)
426 expect(videos
.length
).to
.equal(1)
427 expect(videos
[0].name
).to
.equal('video_short1.webm name')
433 it('Should search the last two videos', function (done
) {
434 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, 'name', function (err
, res
) {
437 const videos
= res
.body
.data
438 expect(res
.body
.total
).to
.equal(4)
439 expect(videos
.length
).to
.equal(2)
440 expect(videos
[0].name
).to
.equal('video_short3.webm name')
441 expect(videos
[1].name
).to
.equal('video_short.webm name')
447 it('Should search all the webm videos', function (done
) {
448 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
451 const videos
= res
.body
.data
452 expect(res
.body
.total
).to
.equal(4)
453 expect(videos
.length
).to
.equal(4)
459 it('Should search all the root author videos', function (done
) {
460 videosUtils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
463 const videos
= res
.body
.data
464 expect(res
.body
.total
).to
.equal(6)
465 expect(videos
.length
).to
.equal(6)
471 // Not implemented yet
472 // it('Should search all the 9001 port videos', function (done) {
473 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
474 // if (err) throw err
476 // const videos = res.body.data
477 // expect(res.body.total).to.equal(6)
478 // expect(videos.length).to.equal(6)
484 // it('Should search all the localhost videos', function (done) {
485 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
486 // if (err) throw err
488 // const videos = res.body.data
489 // expect(res.body.total).to.equal(6)
490 // expect(videos.length).to.equal(6)
496 it('Should search the right magnetUri video', function (done
) {
497 const video
= videosListBase
[0]
498 videosUtils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
501 const videos
= res
.body
.data
502 expect(res
.body
.total
).to
.equal(1)
503 expect(videos
.length
).to
.equal(1)
504 expect(videos
[0].name
).to
.equal(video
.name
)
510 it('Should list and sort by name in descending order', function (done
) {
511 videosUtils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
514 const videos
= res
.body
.data
515 expect(res
.body
.total
).to
.equal(6)
516 expect(videos
.length
).to
.equal(6)
517 expect(videos
[0].name
).to
.equal('video_short.webm name')
518 expect(videos
[1].name
).to
.equal('video_short.ogv name')
519 expect(videos
[2].name
).to
.equal('video_short.mp4 name')
520 expect(videos
[3].name
).to
.equal('video_short3.webm name')
521 expect(videos
[4].name
).to
.equal('video_short2.webm name')
522 expect(videos
[5].name
).to
.equal('video_short1.webm name')
528 it('Should search and sort by name in ascending order', function (done
) {
529 videosUtils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
532 const videos
= res
.body
.data
533 expect(res
.body
.total
).to
.equal(4)
534 expect(videos
.length
).to
.equal(4)
536 expect(videos
[0].name
).to
.equal('video_short1.webm name')
537 expect(videos
[1].name
).to
.equal('video_short2.webm name')
538 expect(videos
[2].name
).to
.equal('video_short3.webm name')
539 expect(videos
[3].name
).to
.equal('video_short.webm name')
541 videoId
= videos
[2].id
547 it('Should update a video', function (done
) {
549 name: 'my super video updated',
551 description: 'my super description updated',
552 tags: [ 'tagup1', 'tagup2' ]
554 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, done
)
557 it('Should have the video updated', function (done
) {
560 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
563 const video
= res
.body
565 expect(video
.name
).to
.equal('my super video updated')
566 expect(video
.category
).to
.equal(4)
567 expect(video
.categoryLabel
).to
.equal('Art')
568 expect(video
.description
).to
.equal('my super description updated')
569 expect(video
.podHost
).to
.equal('localhost:9001')
570 expect(video
.author
).to
.equal('root')
571 expect(video
.isLocal
).to
.be
.true
572 expect(video
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
573 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
574 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
576 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video
.thumbnailPath
, function (err
, test
) {
578 expect(test
).to
.equal(true)
580 webtorrent
.add(video
.magnetUri
, function (torrent
) {
581 expect(torrent
.files
).to
.exist
582 expect(torrent
.files
.length
).to
.equal(1)
583 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
591 it('Should update only the tags of a video', function (done
) {
593 tags: [ 'tag1', 'tag2', 'supertag' ]
596 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, function (err
) {
599 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
602 const video
= res
.body
604 expect(video
.name
).to
.equal('my super video updated')
605 expect(video
.category
).to
.equal(4)
606 expect(video
.categoryLabel
).to
.equal('Art')
607 expect(video
.description
).to
.equal('my super description updated')
608 expect(video
.podHost
).to
.equal('localhost:9001')
609 expect(video
.author
).to
.equal('root')
610 expect(video
.isLocal
).to
.be
.true
611 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
612 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
613 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
620 it('Should update only the description of a video', function (done
) {
622 description: 'hello everybody'
625 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, function (err
) {
628 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
631 const video
= res
.body
633 expect(video
.name
).to
.equal('my super video updated')
634 expect(video
.category
).to
.equal(4)
635 expect(video
.categoryLabel
).to
.equal('Art')
636 expect(video
.description
).to
.equal('hello everybody')
637 expect(video
.podHost
).to
.equal('localhost:9001')
638 expect(video
.author
).to
.equal('root')
639 expect(video
.isLocal
).to
.be
.true
640 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
641 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
642 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
649 it('Should like a video', function (done
) {
650 videosUtils
.rateVideo(server
.url
, server
.accessToken
, videoId
, 'like', function (err
) {
653 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
656 const video
= res
.body
658 expect(video
.likes
).to
.equal(1)
659 expect(video
.dislikes
).to
.equal(0)
666 it('Should dislike the same video', function (done
) {
667 videosUtils
.rateVideo(server
.url
, server
.accessToken
, videoId
, 'dislike', function (err
) {
670 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
673 const video
= res
.body
675 expect(video
.likes
).to
.equal(0)
676 expect(video
.dislikes
).to
.equal(1)
683 after(function (done
) {
684 process
.kill(-server
.app
.pid
)
686 // Keep the logs if the test failed
688 serversUtils
.flushTests(done
)