]>
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 not have videos', function (done
) {
48 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
51 expect(res
.body
.total
).to
.equal(0)
52 expect(res
.body
.data
).to
.be
.an('array')
53 expect(res
.body
.data
.length
).to
.equal(0)
59 it('Should upload the video', function (done
) {
61 const name
= 'my super name'
62 const description
= 'my super description'
63 const tags
= [ 'tag1', 'tag2', 'tag3' ]
64 const file
= 'video_short.webm'
65 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, file
, done
)
68 it('Should seed the uploaded video', function (done
) {
69 // Yes, this could be long
72 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
75 expect(res
.body
.total
).to
.equal(1)
76 expect(res
.body
.data
).to
.be
.an('array')
77 expect(res
.body
.data
.length
).to
.equal(1)
79 const video
= res
.body
.data
[0]
80 expect(video
.name
).to
.equal('my super name')
81 expect(video
.description
).to
.equal('my super description')
82 expect(video
.podHost
).to
.equal('localhost:9001')
83 expect(video
.magnetUri
).to
.exist
84 expect(video
.author
).to
.equal('root')
85 expect(video
.isLocal
).to
.be
.true
86 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
87 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
88 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
90 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
92 expect(test
).to
.equal(true)
96 webtorrent
.add(video
.magnetUri
, function (torrent
) {
97 expect(torrent
.files
).to
.exist
98 expect(torrent
.files
.length
).to
.equal(1)
99 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
107 it('Should get the video', function (done
) {
108 // Yes, this could be long
111 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
114 const video
= res
.body
115 expect(video
.name
).to
.equal('my super name')
116 expect(video
.description
).to
.equal('my super description')
117 expect(video
.podHost
).to
.equal('localhost:9001')
118 expect(video
.magnetUri
).to
.exist
119 expect(video
.author
).to
.equal('root')
120 expect(video
.isLocal
).to
.be
.true
121 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
122 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
123 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
125 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
127 expect(test
).to
.equal(true)
134 it('Should have the views updated', function (done
) {
135 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
138 const video
= res
.body
139 expect(video
.views
).to
.equal(1)
145 it('Should search the video by name by default', function (done
) {
146 videosUtils
.searchVideo(server
.url
, 'my', function (err
, res
) {
149 expect(res
.body
.total
).to
.equal(1)
150 expect(res
.body
.data
).to
.be
.an('array')
151 expect(res
.body
.data
.length
).to
.equal(1)
153 const video
= res
.body
.data
[0]
154 expect(video
.name
).to
.equal('my super name')
155 expect(video
.description
).to
.equal('my super description')
156 expect(video
.podHost
).to
.equal('localhost:9001')
157 expect(video
.author
).to
.equal('root')
158 expect(video
.isLocal
).to
.be
.true
159 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
160 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
161 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
163 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
165 expect(test
).to
.equal(true)
172 // Not implemented yet
173 // it('Should search the video by podHost', function (done) {
174 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
175 // if (err) throw err
177 // expect(res.body.total).to.equal(1)
178 // expect(res.body.data).to.be.an('array')
179 // expect(res.body.data.length).to.equal(1)
181 // const video = res.body.data[0]
182 // expect(video.name).to.equal('my super name')
183 // expect(video.description).to.equal('my super description')
184 // expect(video.podHost).to.equal('localhost:9001')
185 // expect(video.author).to.equal('root')
186 // expect(video.isLocal).to.be.true
187 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
188 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
189 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
191 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
192 // if (err) throw err
193 // expect(test).to.equal(true)
200 it('Should search the video by tag', function (done
) {
201 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
204 expect(res
.body
.total
).to
.equal(1)
205 expect(res
.body
.data
).to
.be
.an('array')
206 expect(res
.body
.data
.length
).to
.equal(1)
208 const video
= res
.body
.data
[0]
209 expect(video
.name
).to
.equal('my super name')
210 expect(video
.description
).to
.equal('my super description')
211 expect(video
.podHost
).to
.equal('localhost:9001')
212 expect(video
.author
).to
.equal('root')
213 expect(video
.isLocal
).to
.be
.true
214 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
215 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
216 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
218 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
220 expect(test
).to
.equal(true)
227 it('Should not find a search by name by default', function (done
) {
228 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
231 expect(res
.body
.total
).to
.equal(0)
232 expect(res
.body
.data
).to
.be
.an('array')
233 expect(res
.body
.data
.length
).to
.equal(0)
239 it('Should not find a search by author', function (done
) {
240 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
243 expect(res
.body
.total
).to
.equal(0)
244 expect(res
.body
.data
).to
.be
.an('array')
245 expect(res
.body
.data
.length
).to
.equal(0)
251 it('Should not find a search by tag', function (done
) {
252 videosUtils
.searchVideo(server
.url
, 'hello', 'tags', function (err
, res
) {
255 expect(res
.body
.total
).to
.equal(0)
256 expect(res
.body
.data
).to
.be
.an('array')
257 expect(res
.body
.data
.length
).to
.equal(0)
263 it('Should remove the video', function (done
) {
264 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
267 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/videos/'), function (err
, files
) {
270 expect(files
.length
).to
.equal(0)
272 fs
.readdir(pathUtils
.join(__dirname
, '..', '..', '..', 'test1/thumbnails/'), function (err
, files
) {
275 expect(files
.length
).to
.equal(0)
283 it('Should not have videos', function (done
) {
284 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
287 expect(res
.body
.total
).to
.equal(0)
288 expect(res
.body
.data
).to
.be
.an('array')
289 expect(res
.body
.data
.length
).to
.equal(0)
295 it('Should upload 6 videos', function (done
) {
298 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
299 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
301 each(videos
, function (video
, callbackEach
) {
302 const name
= video
+ ' name'
303 const description
= video
+ ' description'
304 const tags
= [ 'tag1', 'tag2', 'tag3' ]
306 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
310 it('Should have the correct durations', function (done
) {
311 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
314 expect(res
.body
.total
).to
.equal(6)
315 const videos
= res
.body
.data
316 expect(videos
).to
.be
.an('array')
317 expect(videos
.length
).to
.equal(6)
319 const videosByName
= keyBy(videos
, 'name')
320 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
321 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
322 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
323 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
324 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
325 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
331 it('Should have the correct thumbnails', function (done
) {
332 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
335 const videos
= res
.body
.data
337 videosListBase
= videos
339 each(videos
, function (video
, callbackEach
) {
341 const videoName
= video
.name
.replace(' name', '')
343 videosUtils
.testVideoImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
346 expect(test
).to
.equal(true)
353 it('Should list only the two first videos', function (done
) {
354 videosUtils
.getVideosListPagination(server
.url
, 0, 2, 'name', function (err
, res
) {
357 const videos
= res
.body
.data
358 expect(res
.body
.total
).to
.equal(6)
359 expect(videos
.length
).to
.equal(2)
360 expect(videos
[0].name
).to
.equal(videosListBase
[0].name
)
361 expect(videos
[1].name
).to
.equal(videosListBase
[1].name
)
367 it('Should list only the next three videos', function (done
) {
368 videosUtils
.getVideosListPagination(server
.url
, 2, 3, 'name', function (err
, res
) {
371 const videos
= res
.body
.data
372 expect(res
.body
.total
).to
.equal(6)
373 expect(videos
.length
).to
.equal(3)
374 expect(videos
[0].name
).to
.equal(videosListBase
[2].name
)
375 expect(videos
[1].name
).to
.equal(videosListBase
[3].name
)
376 expect(videos
[2].name
).to
.equal(videosListBase
[4].name
)
382 it('Should list the last video', function (done
) {
383 videosUtils
.getVideosListPagination(server
.url
, 5, 6, 'name', function (err
, res
) {
386 const videos
= res
.body
.data
387 expect(res
.body
.total
).to
.equal(6)
388 expect(videos
.length
).to
.equal(1)
389 expect(videos
[0].name
).to
.equal(videosListBase
[5].name
)
395 it('Should search the first video', function (done
) {
396 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, 'name', function (err
, res
) {
399 const videos
= res
.body
.data
400 expect(res
.body
.total
).to
.equal(4)
401 expect(videos
.length
).to
.equal(1)
402 expect(videos
[0].name
).to
.equal('video_short1.webm name')
408 it('Should search the last two videos', function (done
) {
409 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, 'name', function (err
, res
) {
412 const videos
= res
.body
.data
413 expect(res
.body
.total
).to
.equal(4)
414 expect(videos
.length
).to
.equal(2)
415 expect(videos
[0].name
).to
.equal('video_short3.webm name')
416 expect(videos
[1].name
).to
.equal('video_short.webm name')
422 it('Should search all the webm videos', function (done
) {
423 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
426 const videos
= res
.body
.data
427 expect(res
.body
.total
).to
.equal(4)
428 expect(videos
.length
).to
.equal(4)
434 it('Should search all the root author videos', function (done
) {
435 videosUtils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
438 const videos
= res
.body
.data
439 expect(res
.body
.total
).to
.equal(6)
440 expect(videos
.length
).to
.equal(6)
446 // Not implemented yet
447 // it('Should search all the 9001 port videos', function (done) {
448 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
449 // if (err) throw err
451 // const videos = res.body.data
452 // expect(res.body.total).to.equal(6)
453 // expect(videos.length).to.equal(6)
459 // it('Should search all the localhost videos', function (done) {
460 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
461 // if (err) throw err
463 // const videos = res.body.data
464 // expect(res.body.total).to.equal(6)
465 // expect(videos.length).to.equal(6)
471 it('Should search the good magnetUri video', function (done
) {
472 const video
= videosListBase
[0]
473 videosUtils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
476 const videos
= res
.body
.data
477 expect(res
.body
.total
).to
.equal(1)
478 expect(videos
.length
).to
.equal(1)
479 expect(videos
[0].name
).to
.equal(video
.name
)
485 it('Should list and sort by name in descending order', function (done
) {
486 videosUtils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
489 const videos
= res
.body
.data
490 expect(res
.body
.total
).to
.equal(6)
491 expect(videos
.length
).to
.equal(6)
492 expect(videos
[0].name
).to
.equal('video_short.webm name')
493 expect(videos
[1].name
).to
.equal('video_short.ogv name')
494 expect(videos
[2].name
).to
.equal('video_short.mp4 name')
495 expect(videos
[3].name
).to
.equal('video_short3.webm name')
496 expect(videos
[4].name
).to
.equal('video_short2.webm name')
497 expect(videos
[5].name
).to
.equal('video_short1.webm name')
503 it('Should search and sort by name in ascending order', function (done
) {
504 videosUtils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
507 const videos
= res
.body
.data
508 expect(res
.body
.total
).to
.equal(4)
509 expect(videos
.length
).to
.equal(4)
511 expect(videos
[0].name
).to
.equal('video_short1.webm name')
512 expect(videos
[1].name
).to
.equal('video_short2.webm name')
513 expect(videos
[2].name
).to
.equal('video_short3.webm name')
514 expect(videos
[3].name
).to
.equal('video_short.webm name')
516 videoId
= videos
[2].id
522 it('Should update a video', function (done
) {
523 const name
= 'my super video updated'
524 const description
= 'my super description updated'
525 const tags
= [ 'tagup1', 'tagup2' ]
527 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, name
, description
, tags
, done
)
530 it('Should have the video updated', function (done
) {
533 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
536 const video
= res
.body
538 expect(video
.name
).to
.equal('my super video updated')
539 expect(video
.description
).to
.equal('my super description updated')
540 expect(video
.podHost
).to
.equal('localhost:9001')
541 expect(video
.author
).to
.equal('root')
542 expect(video
.isLocal
).to
.be
.true
543 expect(video
.tags
).to
.deep
.equal([ 'tagup1', 'tagup2' ])
544 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
545 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
547 videosUtils
.testVideoImage(server
.url
, 'video_short3.webm', video
.thumbnailPath
, function (err
, test
) {
549 expect(test
).to
.equal(true)
551 webtorrent
.add(video
.magnetUri
, function (torrent
) {
552 expect(torrent
.files
).to
.exist
553 expect(torrent
.files
.length
).to
.equal(1)
554 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
562 it('Should update only the tags of a video', function (done
) {
563 const tags
= [ 'tag1', 'tag2', 'supertag' ]
565 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, null, null, tags
, function (err
) {
568 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
571 const video
= res
.body
573 expect(video
.name
).to
.equal('my super video updated')
574 expect(video
.description
).to
.equal('my super description updated')
575 expect(video
.podHost
).to
.equal('localhost:9001')
576 expect(video
.author
).to
.equal('root')
577 expect(video
.isLocal
).to
.be
.true
578 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
579 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
580 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
587 it('Should update only the description of a video', function (done
) {
588 const description
= 'hello everybody'
590 videosUtils
.updateVideo(server
.url
, server
.accessToken
, videoId
, null, description
, null, function (err
) {
593 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
596 const video
= res
.body
598 expect(video
.name
).to
.equal('my super video updated')
599 expect(video
.description
).to
.equal('hello everybody')
600 expect(video
.podHost
).to
.equal('localhost:9001')
601 expect(video
.author
).to
.equal('root')
602 expect(video
.isLocal
).to
.be
.true
603 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'supertag' ])
604 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
605 expect(miscsUtils
.dateIsValid(video
.updatedAt
)).to
.be
.true
612 after(function (done
) {
613 process
.kill(-server
.app
.pid
)
615 // Keep the logs if the test failed
617 serversUtils
.flushTests(done
)