]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
3 const chai
= require('chai')
4 const each
= require('async/each')
5 const expect
= chai
.expect
6 const fs
= require('fs')
7 const keyBy
= require('lodash/keyBy')
8 const pathUtils
= require('path')
9 const series
= require('async/series')
11 const loginUtils
= require('../utils/login')
12 const miscsUtils
= require('../utils/miscs')
13 const serversUtils
= require('../utils/servers')
14 const videosUtils
= require('../utils/videos')
15 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
16 webtorrent
.silent
= true
18 describe('Test a single pod', function () {
21 let videosListBase
= null
23 before(function (done
) {
28 serversUtils
.flushTests(next
)
31 serversUtils
.runServer(1, function (server1
) {
37 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
39 server
.accessToken
= token
44 webtorrent
.create({ host: 'client', port: '1' }, next
)
49 it('Should not have videos', function (done
) {
50 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
53 expect(res
.body
.total
).to
.equal(0)
54 expect(res
.body
.data
).to
.be
.an('array')
55 expect(res
.body
.data
.length
).to
.equal(0)
61 it('Should upload the video', function (done
) {
63 const name
= 'my super name'
64 const description
= 'my super description'
65 const tags
= [ 'tag1', 'tag2', 'tag3' ]
66 const file
= 'video_short.webm'
67 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, file
, done
)
70 it('Should seed the uploaded video', function (done
) {
71 // Yes, this could be long
74 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
77 expect(res
.body
.total
).to
.equal(1)
78 expect(res
.body
.data
).to
.be
.an('array')
79 expect(res
.body
.data
.length
).to
.equal(1)
81 const video
= res
.body
.data
[0]
82 expect(video
.name
).to
.equal('my super name')
83 expect(video
.description
).to
.equal('my super description')
84 expect(video
.podUrl
).to
.equal('localhost:9001')
85 expect(video
.magnetUri
).to
.exist
86 expect(video
.author
).to
.equal('root')
87 expect(video
.isLocal
).to
.be
.true
88 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
89 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
91 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
93 expect(test
).to
.equal(true)
97 webtorrent
.add(video
.magnetUri
, function (torrent
) {
98 expect(torrent
.files
).to
.exist
99 expect(torrent
.files
.length
).to
.equal(1)
100 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
102 // We remove it because we'll add it again
103 webtorrent
.remove(video
.magnetUri
, done
)
109 it('Should get the video', function (done
) {
110 // Yes, this could be long
113 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
116 const video
= res
.body
117 expect(video
.name
).to
.equal('my super name')
118 expect(video
.description
).to
.equal('my super description')
119 expect(video
.podUrl
).to
.equal('localhost:9001')
120 expect(video
.magnetUri
).to
.exist
121 expect(video
.author
).to
.equal('root')
122 expect(video
.isLocal
).to
.be
.true
123 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
124 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
126 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
128 expect(test
).to
.equal(true)
130 webtorrent
.add(video
.magnetUri
, function (torrent
) {
131 expect(torrent
.files
).to
.exist
132 expect(torrent
.files
.length
).to
.equal(1)
133 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
141 it('Should search the video by name by default', function (done
) {
142 videosUtils
.searchVideo(server
.url
, 'my', function (err
, res
) {
145 expect(res
.body
.total
).to
.equal(1)
146 expect(res
.body
.data
).to
.be
.an('array')
147 expect(res
.body
.data
.length
).to
.equal(1)
149 const video
= res
.body
.data
[0]
150 expect(video
.name
).to
.equal('my super name')
151 expect(video
.description
).to
.equal('my super description')
152 expect(video
.podUrl
).to
.equal('localhost:9001')
153 expect(video
.author
).to
.equal('root')
154 expect(video
.isLocal
).to
.be
.true
155 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
156 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
158 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
160 expect(test
).to
.equal(true)
167 it('Should search the video by podUrl', function (done
) {
168 videosUtils
.searchVideo(server
.url
, '9001', 'podUrl', function (err
, res
) {
171 expect(res
.body
.total
).to
.equal(1)
172 expect(res
.body
.data
).to
.be
.an('array')
173 expect(res
.body
.data
.length
).to
.equal(1)
175 const video
= res
.body
.data
[0]
176 expect(video
.name
).to
.equal('my super name')
177 expect(video
.description
).to
.equal('my super description')
178 expect(video
.podUrl
).to
.equal('localhost:9001')
179 expect(video
.author
).to
.equal('root')
180 expect(video
.isLocal
).to
.be
.true
181 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
182 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
184 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
186 expect(test
).to
.equal(true)
193 it('Should search the video by tag', function (done
) {
194 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
197 expect(res
.body
.total
).to
.equal(1)
198 expect(res
.body
.data
).to
.be
.an('array')
199 expect(res
.body
.data
.length
).to
.equal(1)
201 const video
= res
.body
.data
[0]
202 expect(video
.name
).to
.equal('my super name')
203 expect(video
.description
).to
.equal('my super description')
204 expect(video
.podUrl
).to
.equal('localhost:9001')
205 expect(video
.author
).to
.equal('root')
206 expect(video
.isLocal
).to
.be
.true
207 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
208 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
210 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
212 expect(test
).to
.equal(true)
219 it('Should not find a search by name by default', function (done
) {
220 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
223 expect(res
.body
.total
).to
.equal(0)
224 expect(res
.body
.data
).to
.be
.an('array')
225 expect(res
.body
.data
.length
).to
.equal(0)
231 it('Should not find a search by author', function (done
) {
232 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
235 expect(res
.body
.total
).to
.equal(0)
236 expect(res
.body
.data
).to
.be
.an('array')
237 expect(res
.body
.data
.length
).to
.equal(0)
243 it('Should not find a search by tag', function (done
) {
244 videosUtils
.searchVideo(server
.url
, 'tag', 'tags', function (err
, res
) {
247 expect(res
.body
.total
).to
.equal(0)
248 expect(res
.body
.data
).to
.be
.an('array')
249 expect(res
.body
.data
.length
).to
.equal(0)
255 it('Should remove the video', function (done
) {
256 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
259 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
262 expect(files
.length
).to
.equal(0)
268 it('Should not have videos', function (done
) {
269 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
272 expect(res
.body
.total
).to
.equal(0)
273 expect(res
.body
.data
).to
.be
.an('array')
274 expect(res
.body
.data
.length
).to
.equal(0)
280 it('Should upload 6 videos', function (done
) {
283 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
284 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
286 each(videos
, function (video
, callbackEach
) {
287 const name
= video
+ ' name'
288 const description
= video
+ ' description'
289 const tags
= [ 'tag1', 'tag2', 'tag3' ]
291 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
295 it('Should have the correct durations', function (done
) {
296 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
299 expect(res
.body
.total
).to
.equal(6)
300 const videos
= res
.body
.data
301 expect(videos
).to
.be
.an('array')
302 expect(videos
.length
).to
.equal(6)
304 const videosByName
= keyBy(videos
, 'name')
305 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
306 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
307 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
308 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
309 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
310 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
316 it('Should have the correct thumbnails', function (done
) {
317 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
320 const videos
= res
.body
.data
322 videosListBase
= videos
324 each(videos
, function (video
, callbackEach
) {
326 const videoName
= video
.name
.replace(' name', '')
328 videosUtils
.testVideoImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
331 expect(test
).to
.equal(true)
338 it('Should list only the two first videos', function (done
) {
339 videosUtils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
342 const videos
= res
.body
.data
343 expect(res
.body
.total
).to
.equal(6)
344 expect(videos
.length
).to
.equal(2)
345 expect(videos
[0].name
=== videosListBase
[0].name
)
346 expect(videos
[1].name
=== videosListBase
[1].name
)
352 it('Should list only the next three videos', function (done
) {
353 videosUtils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
356 const videos
= res
.body
.data
357 expect(res
.body
.total
).to
.equal(6)
358 expect(videos
.length
).to
.equal(3)
359 expect(videos
[0].name
=== videosListBase
[2].name
)
360 expect(videos
[1].name
=== videosListBase
[3].name
)
361 expect(videos
[2].name
=== videosListBase
[4].name
)
367 it('Should list the last video', function (done
) {
368 videosUtils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
371 const videos
= res
.body
.data
372 expect(res
.body
.total
).to
.equal(6)
373 expect(videos
.length
).to
.equal(1)
374 expect(videos
[0].name
=== videosListBase
[5].name
)
380 it('Should search the first video', function (done
) {
381 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, function (err
, res
) {
384 const videos
= res
.body
.data
385 expect(res
.body
.total
).to
.equal(4)
386 expect(videos
.length
).to
.equal(1)
387 expect(videos
[0].name
=== 'video_short.webm name')
393 it('Should search the last two videos', function (done
) {
394 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, function (err
, res
) {
397 const videos
= res
.body
.data
398 expect(res
.body
.total
).to
.equal(4)
399 expect(videos
.length
).to
.equal(2)
400 expect(videos
[0].name
=== 'video_short2.webm name')
401 expect(videos
[1].name
=== 'video_short3.webm name')
407 it('Should search all the webm videos', function (done
) {
408 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
411 const videos
= res
.body
.data
412 expect(res
.body
.total
).to
.equal(4)
413 expect(videos
.length
).to
.equal(4)
419 it('Should search all the root author videos', function (done
) {
420 videosUtils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
423 const videos
= res
.body
.data
424 expect(res
.body
.total
).to
.equal(6)
425 expect(videos
.length
).to
.equal(6)
431 it('Should search all the 9001 port videos', function (done
) {
432 videosUtils
.searchVideoWithPagination(server
.url
, '9001', 'podUrl', 0, 15, function (err
, res
) {
435 const videos
= res
.body
.data
436 expect(res
.body
.total
).to
.equal(6)
437 expect(videos
.length
).to
.equal(6)
443 it('Should search all the localhost videos', function (done
) {
444 videosUtils
.searchVideoWithPagination(server
.url
, 'localhost', 'podUrl', 0, 15, function (err
, res
) {
447 const videos
= res
.body
.data
448 expect(res
.body
.total
).to
.equal(6)
449 expect(videos
.length
).to
.equal(6)
455 it('Should search the good magnetUri video', function (done
) {
456 const video
= videosListBase
[0]
457 videosUtils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
460 const videos
= res
.body
.data
461 expect(res
.body
.total
).to
.equal(1)
462 expect(videos
.length
).to
.equal(1)
463 expect(videos
[0].name
).to
.equal(video
.name
)
469 it('Should list and sort by name in descending order', function (done
) {
470 videosUtils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
473 const videos
= res
.body
.data
474 expect(res
.body
.total
).to
.equal(6)
475 expect(videos
.length
).to
.equal(6)
476 expect(videos
[5].name
=== 'video_short.mp4 name')
477 expect(videos
[4].name
=== 'video_short.ogv name')
478 expect(videos
[3].name
=== 'video_short.webm name')
479 expect(videos
[2].name
=== 'video_short1.webm name')
480 expect(videos
[1].name
=== 'video_short2.webm name')
481 expect(videos
[0].name
=== 'video_short3.webm name')
487 it('Should search and sort by name in ascending order', function (done
) {
488 videosUtils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
491 const videos
= res
.body
.data
492 expect(res
.body
.total
).to
.equal(4)
493 expect(videos
.length
).to
.equal(4)
495 expect(videos
[0].name
=== 'video_short.webm name')
496 expect(videos
[1].name
=== 'video_short1.webm name')
497 expect(videos
[2].name
=== 'video_short2.webm name')
498 expect(videos
[3].name
=== 'video_short3.webm name')
504 after(function (done
) {
505 process
.kill(-server
.app
.pid
)
506 process
.kill(-webtorrent
.app
.pid
)
508 // Keep the logs if the test failed
510 serversUtils
.flushTests(done
)