]>
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 list video languages', function (done
) {
74 videosUtils
.getVideoLanguages(server
.url
, function (err
, res
) {
77 const languages
= res
.body
78 expect(Object
.keys(languages
)).to
.have
.length
.above(5)
80 expect(languages
[3]).to
.equal('Mandarin')
86 it('Should not have videos', function (done
) {
87 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
90 expect(res
.body
.total
).to
.equal(0)
91 expect(res
.body
.data
).to
.be
.an('array')
92 expect(res
.body
.data
.length
).to
.equal(0)
98 it('Should upload the video', function (done
) {
99 const videoAttributes
= {
100 name: 'my super name',
104 tags: [ 'tag1', 'tag2', 'tag3' ]
106 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, done
)
109 it('Should seed the uploaded video', function (done
) {
110 // Yes, this could be long
113 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
116 expect(res
.body
.total
).to
.equal(1)
117 expect(res
.body
.data
).to
.be
.an('array')
118 expect(res
.body
.data
.length
).to
.equal(1)
120 const video
= res
.body
.data
[0]
121 expect(video
.name
).to
.equal('my super name')
122 expect(video
.category
).to
.equal(2)
123 expect(video
.categoryLabel
).to
.equal('Films')
124 expect(video
.licence
).to
.equal(6)
125 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
126 expect(video
.language
).to
.equal(3)
127 expect(video
.languageLabel
).to
.equal('Mandarin')
128 expect(video
.nsfw
).to
.be
.truthy
129 expect(video
.description
).to
.equal('my super description')
130 expect(video
.podHost
).to
.equal('localhost:9001')
131 expect(video
.magnetUri
).to
.exist
132 expect(video
.author
).to
.equal('root')
133 expect(video
.isLocal
).to
.be
.true
134 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
135 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
136 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
138 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
140 expect(test
).to
.equal(true)
144 webtorrent
.add(video
.magnetUri
, function (torrent
) {
145 expect(torrent
.files
).to
.exist
146 expect(torrent
.files
.length
).to
.equal(1)
147 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
155 it('Should get the video', function (done
) {
156 // Yes, this could be long
159 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
162 const video
= res
.body
163 expect(video
.name
).to
.equal('my super name')
164 expect(video
.category
).to
.equal(2)
165 expect(video
.categoryLabel
).to
.equal('Films')
166 expect(video
.licence
).to
.equal(6)
167 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
168 expect(video
.language
).to
.equal(3)
169 expect(video
.languageLabel
).to
.equal('Mandarin')
170 expect(video
.nsfw
).to
.be
.truthy
171 expect(video
.description
).to
.equal('my super description')
172 expect(video
.podHost
).to
.equal('localhost:9001')
173 expect(video
.magnetUri
).to
.exist
174 expect(video
.author
).to
.equal('root')
175 expect(video
.isLocal
).to
.be
.true
176 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
177 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
178 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
180 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
182 expect(test
).to
.equal(true)
184 // Wait the async views increment
185 setTimeout(done
, 500)
190 it('Should have the views updated', function (done
) {
191 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
194 const video
= res
.body
195 expect(video
.views
).to
.equal(1)
201 it('Should search the video by name by default', function (done
) {
202 videosUtils
.searchVideo(server
.url
, 'my', function (err
, res
) {
205 expect(res
.body
.total
).to
.equal(1)
206 expect(res
.body
.data
).to
.be
.an('array')
207 expect(res
.body
.data
.length
).to
.equal(1)
209 const video
= res
.body
.data
[0]
210 expect(video
.name
).to
.equal('my super name')
211 expect(video
.category
).to
.equal(2)
212 expect(video
.categoryLabel
).to
.equal('Films')
213 expect(video
.licence
).to
.equal(6)
214 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
215 expect(video
.language
).to
.equal(3)
216 expect(video
.languageLabel
).to
.equal('Mandarin')
217 expect(video
.nsfw
).to
.be
.truthy
218 expect(video
.description
).to
.equal('my super description')
219 expect(video
.podHost
).to
.equal('localhost:9001')
220 expect(video
.author
).to
.equal('root')
221 expect(video
.isLocal
).to
.be
.true
222 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
223 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
224 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
226 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
228 expect(test
).to
.equal(true)
235 // Not implemented yet
236 // it('Should search the video by podHost', function (done) {
237 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
238 // if (err) throw err
240 // expect(res.body.total).to.equal(1)
241 // expect(res.body.data).to.be.an('array')
242 // expect(res.body.data.length).to.equal(1)
244 // const video = res.body.data[0]
245 // expect(video.name).to.equal('my super name')
246 // expect(video.description).to.equal('my super description')
247 // expect(video.podHost).to.equal('localhost:9001')
248 // expect(video.author).to.equal('root')
249 // expect(video.isLocal).to.be.true
250 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
251 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
252 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
254 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
255 // if (err) throw err
256 // expect(test).to.equal(true)
263 it('Should search the video by tag', function (done
) {
264 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
267 expect(res
.body
.total
).to
.equal(1)
268 expect(res
.body
.data
).to
.be
.an('array')
269 expect(res
.body
.data
.length
).to
.equal(1)
271 const video
= res
.body
.data
[0]
272 expect(video
.name
).to
.equal('my super name')
273 expect(video
.category
).to
.equal(2)
274 expect(video
.categoryLabel
).to
.equal('Films')
275 expect(video
.licence
).to
.equal(6)
276 expect(video
.licenceLabel
).to
.equal('Attribution - Non Commercial - No Derivatives')
277 expect(video
.language
).to
.equal(3)
278 expect(video
.languageLabel
).to
.equal('Mandarin')
279 expect(video
.nsfw
).to
.be
.truthy
280 expect(video
.description
).to
.equal('my super description')
281 expect(video
.podHost
).to
.equal('localhost:9001')
282 expect(video
.author
).to
.equal('root')
283 expect(video
.isLocal
).to
.be
.true
284 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
285 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
286 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
288 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
290 expect(test
).to
.equal(true)
297 it('Should not find a search by name by default', function (done
) {
298 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
301 expect(res
.body
.total
).to
.equal(0)
302 expect(res
.body
.data
).to
.be
.an('array')
303 expect(res
.body
.data
.length
).to
.equal(0)
309 it('Should not find a search by author', function (done
) {
310 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
313 expect(res
.body
.total
).to
.equal(0)
314 expect(res
.body
.data
).to
.be
.an('array')
315 expect(res
.body
.data
.length
).to
.equal(0)
321 it('Should not find a search by tag', function (done
) {
322 videosUtils
.searchVideo(server
.url
, 'hello', 'tags', function (err
, res
) {
325 expect(res
.body
.total
).to
.equal(0)
326 expect(res
.body
.data
).to
.be
.an('array')
327 expect(res
.body
.data
.length
).to
.equal(0)
333 it('Should remove the video', function (done
) {
334 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
337 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/videos/'), function (err
, files
) {
340 expect(files
.length
).to
.equal(0)
342 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/thumbnails/'), function (err
, files
) {
345 expect(files
.length
).to
.equal(0)
353 it('Should not have videos', function (done
) {
354 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
357 expect(res
.body
.total
).to
.equal(0)
358 expect(res
.body
.data
).to
.be
.an('array')
359 expect(res
.body
.data
.length
).to
.equal(0)
365 it('Should upload 6 videos', function (done
) {
368 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
369 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
371 each(videos
, function (video
, callbackEach
) {
372 const videoAttributes
= {
373 name: video
+ ' name',
374 description: video
+ ' description',
379 tags: [ 'tag1', 'tag2', 'tag3' ],
383 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, videoAttributes
, callbackEach
)
387 it('Should have the correct durations', function (done
) {
388 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
391 expect(res
.body
.total
).to
.equal(6)
392 const videos
= res
.body
.data
393 expect(videos
).to
.be
.an('array')
394 expect(videos
.length
).to
.equal(6)
396 const videosByName
= keyBy(videos
, 'name')
397 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
398 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
399 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
400 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
401 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
402 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
408 it('Should have the correct thumbnails', function (done
) {
409 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
412 const videos
= res
.body
.data
414 videosListBase
= videos
416 each(videos
, function (video
, callbackEach
) {
418 const videoName
= video
.name
.replace(' name', '')
420 videosUtils
.testVideoImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
423 expect(test
).to
.equal(true)
430 it('Should list only the two first videos', function (done
) {
431 videosUtils
.getVideosListPagination(server
.url
, 0, 2, 'name', function (err
, res
) {
434 const videos
= res
.body
.data
435 expect(res
.body
.total
).to
.equal(6)
436 expect(videos
.length
).to
.equal(2)
437 expect(videos
[0].name
).to
.equal(videosListBase
[0].name
)
438 expect(videos
[1].name
).to
.equal(videosListBase
[1].name
)
444 it('Should list only the next three videos', function (done
) {
445 videosUtils
.getVideosListPagination(server
.url
, 2, 3, 'name', function (err
, res
) {
448 const videos
= res
.body
.data
449 expect(res
.body
.total
).to
.equal(6)
450 expect(videos
.length
).to
.equal(3)
451 expect(videos
[0].name
).to
.equal(videosListBase
[2].name
)
452 expect(videos
[1].name
).to
.equal(videosListBase
[3].name
)
453 expect(videos
[2].name
).to
.equal(videosListBase
[4].name
)
459 it('Should list the last video', function (done
) {
460 videosUtils
.getVideosListPagination(server
.url
, 5, 6, 'name', function (err
, res
) {
463 const videos
= res
.body
.data
464 expect(res
.body
.total
).to
.equal(6)
465 expect(videos
.length
).to
.equal(1)
466 expect(videos
[0].name
).to
.equal(videosListBase
[5].name
)
472 it('Should search the first video', function (done
) {
473 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, 'name', function (err
, res
) {
476 const videos
= res
.body
.data
477 expect(res
.body
.total
).to
.equal(4)
478 expect(videos
.length
).to
.equal(1)
479 expect(videos
[0].name
).to
.equal('video_short1.webm name')
485 it('Should search the last two videos', function (done
) {
486 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, 'name', function (err
, res
) {
489 const videos
= res
.body
.data
490 expect(res
.body
.total
).to
.equal(4)
491 expect(videos
.length
).to
.equal(2)
492 expect(videos
[0].name
).to
.equal('video_short3.webm name')
493 expect(videos
[1].name
).to
.equal('video_short.webm name')
499 it('Should search all the webm videos', function (done
) {
500 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
503 const videos
= res
.body
.data
504 expect(res
.body
.total
).to
.equal(4)
505 expect(videos
.length
).to
.equal(4)
511 it('Should search all the root author videos', function (done
) {
512 videosUtils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
515 const videos
= res
.body
.data
516 expect(res
.body
.total
).to
.equal(6)
517 expect(videos
.length
).to
.equal(6)
523 // Not implemented yet
524 // it('Should search all the 9001 port videos', function (done) {
525 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
526 // if (err) throw err
528 // const videos = res.body.data
529 // expect(res.body.total).to.equal(6)
530 // expect(videos.length).to.equal(6)
536 // it('Should search all the localhost videos', function (done) {
537 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
538 // if (err) throw err
540 // const videos = res.body.data
541 // expect(res.body.total).to.equal(6)
542 // expect(videos.length).to.equal(6)
548 it('Should search the right magnetUri video', function (done
) {
549 const video
= videosListBase
[0]
550 videosUtils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
553 const videos
= res
.body
.data
554 expect(res
.body
.total
).to
.equal(1)
555 expect(videos
.length
).to
.equal(1)
556 expect(videos
[0].name
).to
.equal(video
.name
)
562 it('Should list and sort by name in descending order', function (done
) {
563 videosUtils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
566 const videos
= res
.body
.data
567 expect(res
.body
.total
).to
.equal(6)
568 expect(videos
.length
).to
.equal(6)
569 expect(videos
[0].name
).to
.equal('video_short.webm name')
570 expect(videos
[1].name
).to
.equal('video_short.ogv name')
571 expect(videos
[2].name
).to
.equal('video_short.mp4 name')
572 expect(videos
[3].name
).to
.equal('video_short3.webm name')
573 expect(videos
[4].name
).to
.equal('video_short2.webm name')
574 expect(videos
[5].name
).to
.equal('video_short1.webm name')
580 it('Should search and sort by name in ascending order', function (done
) {
581 videosUtils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
584 const videos
= res
.body
.data
585 expect(res
.body
.total
).to
.equal(4)
586 expect(videos
.length
).to
.equal(4)
588 expect(videos
[0].name
).to
.equal('video_short1.webm name')
589 expect(videos
[1].name
).to
.equal('video_short2.webm name')
590 expect(videos
[2].name
).to
.equal('video_short3.webm name')
591 expect(videos
[3].name
).to
.equal('video_short.webm name')
593 videoId
= videos
[2].id
599 it('Should update a video', function (done
) {
601 name: 'my super video updated',
606 description: 'my super description updated',
607 tags: [ 'tagup1', 'tagup2' ]
609 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, done
)
612 it('Should have the video updated', function (done
) {
615 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
618 const video
= res
.body
620 expect(video
.name
).to
.equal('my super video updated')
621 expect(video
.category
).to
.equal(4)
622 expect(video
.categoryLabel
).to
.equal('Art')
623 expect(video
.licence
).to
.equal(2)
624 expect(video
.licenceLabel
).to
.equal('Attribution - Share Alike')
625 expect(video
.language
).to
.equal(5)
626 expect(video
.languageLabel
).to
.equal('Arabic')
627 expect(video
.nsfw
).to
.be
.truthy
628 expect(video
.description
).to
.equal('my super description updated')
629 expect(video
.podHost
).to
.equal('localhost:9001')
630 expect(video
.author
).to
.equal('root')
631 expect(video
.isLocal
).to
.be
.true
632 expect(video
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
633 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
634 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
636 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video
.thumbnailPath
, function (err
, test
) {
638 expect(test
).to
.equal(true)
640 webtorrent
.add(video
.magnetUri
, function (torrent
) {
641 expect(torrent
.files
).to
.exist
642 expect(torrent
.files
.length
).to
.equal(1)
643 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
651 it('Should update only the tags of a video', function (done
) {
653 tags: [ 'tag1', 'tag2', 'supertag' ]
656 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, function (err
) {
659 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
662 const video
= res
.body
664 expect(video
.name
).to
.equal('my super video updated')
665 expect(video
.category
).to
.equal(4)
666 expect(video
.categoryLabel
).to
.equal('Art')
667 expect(video
.licence
).to
.equal(2)
668 expect(video
.licenceLabel
).to
.equal('Attribution - Share Alike')
669 expect(video
.language
).to
.equal(5)
670 expect(video
.languageLabel
).to
.equal('Arabic')
671 expect(video
.nsfw
).to
.be
.truthy
672 expect(video
.description
).to
.equal('my super description updated')
673 expect(video
.podHost
).to
.equal('localhost:9001')
674 expect(video
.author
).to
.equal('root')
675 expect(video
.isLocal
).to
.be
.true
676 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
677 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
678 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
685 it('Should update only the description of a video', function (done
) {
687 description: 'hello everybody'
690 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, attributes
, function (err
) {
693 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
696 const video
= res
.body
698 expect(video
.name
).to
.equal('my super video updated')
699 expect(video
.category
).to
.equal(4)
700 expect(video
.categoryLabel
).to
.equal('Art')
701 expect(video
.licence
).to
.equal(2)
702 expect(video
.licenceLabel
).to
.equal('Attribution - Share Alike')
703 expect(video
.language
).to
.equal(5)
704 expect(video
.languageLabel
).to
.equal('Arabic')
705 expect(video
.nsfw
).to
.be
.truthy
706 expect(video
.description
).to
.equal('hello everybody')
707 expect(video
.podHost
).to
.equal('localhost:9001')
708 expect(video
.author
).to
.equal('root')
709 expect(video
.isLocal
).to
.be
.true
710 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
711 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
712 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
719 it('Should like a video', function (done
) {
720 videosUtils
.rateVideo(server
.url
, server
.accessToken
, videoId
, 'like', function (err
) {
723 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
726 const video
= res
.body
728 expect(video
.likes
).to
.equal(1)
729 expect(video
.dislikes
).to
.equal(0)
736 it('Should dislike the same video', function (done
) {
737 videosUtils
.rateVideo(server
.url
, server
.accessToken
, videoId
, 'dislike', function (err
) {
740 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
743 const video
= res
.body
745 expect(video
.likes
).to
.equal(0)
746 expect(video
.dislikes
).to
.equal(1)
753 after(function (done
) {
754 process
.kill(-server
.app
.pid
)
756 // Keep the logs if the test failed
758 serversUtils
.flushTests(done
)