]>
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 webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
12 webtorrent
.silent
= true
14 const utils
= require('./utils')
16 describe('Test a single pod', function () {
19 let videosListBase
= null
21 before(function (done
) {
26 utils
.flushTests(next
)
29 utils
.runServer(1, function (server1
) {
35 utils
.loginAndGetAccessToken(server
, function (err
, token
) {
37 server
.accessToken
= token
42 webtorrent
.create({ host: 'client', port: '1' }, next
)
47 it('Should not have videos', function (done
) {
48 utils
.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 utils
.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 utils
.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
.podUrl
).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(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
89 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
91 expect(test
).to
.equal(true)
95 webtorrent
.add(video
.magnetUri
, function (torrent
) {
96 expect(torrent
.files
).to
.exist
97 expect(torrent
.files
.length
).to
.equal(1)
98 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
100 // We remove it because we'll add it again
101 webtorrent
.remove(video
.magnetUri
, done
)
107 it('Should get the video', function (done
) {
108 // Yes, this could be long
111 utils
.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
.podUrl
).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(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
124 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
126 expect(test
).to
.equal(true)
128 webtorrent
.add(video
.magnetUri
, function (torrent
) {
129 expect(torrent
.files
).to
.exist
130 expect(torrent
.files
.length
).to
.equal(1)
131 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
139 it('Should search the video by name by default', function (done
) {
140 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
143 expect(res
.body
.total
).to
.equal(1)
144 expect(res
.body
.data
).to
.be
.an('array')
145 expect(res
.body
.data
.length
).to
.equal(1)
147 const video
= res
.body
.data
[0]
148 expect(video
.name
).to
.equal('my super name')
149 expect(video
.description
).to
.equal('my super description')
150 expect(video
.podUrl
).to
.equal('localhost:9001')
151 expect(video
.author
).to
.equal('root')
152 expect(video
.isLocal
).to
.be
.true
153 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
154 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
156 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
158 expect(test
).to
.equal(true)
165 it('Should search the video by podUrl', function (done
) {
166 utils
.searchVideo(server
.url
, '9001', 'podUrl', function (err
, res
) {
169 expect(res
.body
.total
).to
.equal(1)
170 expect(res
.body
.data
).to
.be
.an('array')
171 expect(res
.body
.data
.length
).to
.equal(1)
173 const video
= res
.body
.data
[0]
174 expect(video
.name
).to
.equal('my super name')
175 expect(video
.description
).to
.equal('my super description')
176 expect(video
.podUrl
).to
.equal('localhost:9001')
177 expect(video
.author
).to
.equal('root')
178 expect(video
.isLocal
).to
.be
.true
179 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
180 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
182 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
184 expect(test
).to
.equal(true)
191 it('Should search the video by tag', function (done
) {
192 utils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
195 expect(res
.body
.total
).to
.equal(1)
196 expect(res
.body
.data
).to
.be
.an('array')
197 expect(res
.body
.data
.length
).to
.equal(1)
199 const video
= res
.body
.data
[0]
200 expect(video
.name
).to
.equal('my super name')
201 expect(video
.description
).to
.equal('my super description')
202 expect(video
.podUrl
).to
.equal('localhost:9001')
203 expect(video
.author
).to
.equal('root')
204 expect(video
.isLocal
).to
.be
.true
205 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
206 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
208 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
210 expect(test
).to
.equal(true)
217 it('Should not find a search by name by default', function (done
) {
218 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
221 expect(res
.body
.total
).to
.equal(0)
222 expect(res
.body
.data
).to
.be
.an('array')
223 expect(res
.body
.data
.length
).to
.equal(0)
229 it('Should not find a search by author', function (done
) {
230 utils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
233 expect(res
.body
.total
).to
.equal(0)
234 expect(res
.body
.data
).to
.be
.an('array')
235 expect(res
.body
.data
.length
).to
.equal(0)
241 it('Should not find a search by tag', function (done
) {
242 utils
.searchVideo(server
.url
, 'tag', 'tags', function (err
, res
) {
245 expect(res
.body
.total
).to
.equal(0)
246 expect(res
.body
.data
).to
.be
.an('array')
247 expect(res
.body
.data
.length
).to
.equal(0)
253 it('Should remove the video', function (done
) {
254 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
257 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
260 expect(files
.length
).to
.equal(0)
266 it('Should not have videos', function (done
) {
267 utils
.getVideosList(server
.url
, function (err
, res
) {
270 expect(res
.body
.total
).to
.equal(0)
271 expect(res
.body
.data
).to
.be
.an('array')
272 expect(res
.body
.data
.length
).to
.equal(0)
278 it('Should upload 6 videos', function (done
) {
281 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
282 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
284 each(videos
, function (video
, callbackEach
) {
285 const name
= video
+ ' name'
286 const description
= video
+ ' description'
287 const tags
= [ 'tag1', 'tag2', 'tag3' ]
289 utils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
293 it('Should have the correct durations', function (done
) {
294 utils
.getVideosList(server
.url
, function (err
, res
) {
297 expect(res
.body
.total
).to
.equal(6)
298 const videos
= res
.body
.data
299 expect(videos
).to
.be
.an('array')
300 expect(videos
.length
).to
.equal(6)
302 const videosByName
= keyBy(videos
, 'name')
303 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
304 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
305 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
306 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
307 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
308 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
314 it('Should have the correct thumbnails', function (done
) {
315 utils
.getVideosList(server
.url
, function (err
, res
) {
318 const videos
= res
.body
.data
320 videosListBase
= videos
322 each(videos
, function (video
, callbackEach
) {
324 const videoName
= video
.name
.replace(' name', '')
326 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
329 expect(test
).to
.equal(true)
336 it('Should list only the two first videos', function (done
) {
337 utils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
340 const videos
= res
.body
.data
341 expect(res
.body
.total
).to
.equal(6)
342 expect(videos
.length
).to
.equal(2)
343 expect(videos
[0].name
=== videosListBase
[0].name
)
344 expect(videos
[1].name
=== videosListBase
[1].name
)
350 it('Should list only the next three videos', function (done
) {
351 utils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
354 const videos
= res
.body
.data
355 expect(res
.body
.total
).to
.equal(6)
356 expect(videos
.length
).to
.equal(3)
357 expect(videos
[0].name
=== videosListBase
[2].name
)
358 expect(videos
[1].name
=== videosListBase
[3].name
)
359 expect(videos
[2].name
=== videosListBase
[4].name
)
365 it('Should list the last video', function (done
) {
366 utils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
369 const videos
= res
.body
.data
370 expect(res
.body
.total
).to
.equal(6)
371 expect(videos
.length
).to
.equal(1)
372 expect(videos
[0].name
=== videosListBase
[5].name
)
378 it('Should search the first video', function (done
) {
379 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, function (err
, res
) {
382 const videos
= res
.body
.data
383 expect(res
.body
.total
).to
.equal(4)
384 expect(videos
.length
).to
.equal(1)
385 expect(videos
[0].name
=== 'video_short.webm name')
391 it('Should search the last two videos', function (done
) {
392 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, function (err
, res
) {
395 const videos
= res
.body
.data
396 expect(res
.body
.total
).to
.equal(4)
397 expect(videos
.length
).to
.equal(2)
398 expect(videos
[0].name
=== 'video_short2.webm name')
399 expect(videos
[1].name
=== 'video_short3.webm name')
405 it('Should search all the webm videos', function (done
) {
406 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
409 const videos
= res
.body
.data
410 expect(res
.body
.total
).to
.equal(4)
411 expect(videos
.length
).to
.equal(4)
417 it('Should search all the root author videos', function (done
) {
418 utils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
421 const videos
= res
.body
.data
422 expect(res
.body
.total
).to
.equal(6)
423 expect(videos
.length
).to
.equal(6)
429 it('Should search all the 9001 port videos', function (done
) {
430 utils
.searchVideoWithPagination(server
.url
, '9001', 'podUrl', 0, 15, function (err
, res
) {
433 const videos
= res
.body
.data
434 expect(res
.body
.total
).to
.equal(6)
435 expect(videos
.length
).to
.equal(6)
441 it('Should search all the localhost videos', function (done
) {
442 utils
.searchVideoWithPagination(server
.url
, 'localhost', 'podUrl', 0, 15, function (err
, res
) {
445 const videos
= res
.body
.data
446 expect(res
.body
.total
).to
.equal(6)
447 expect(videos
.length
).to
.equal(6)
453 it('Should search the good magnetUri video', function (done
) {
454 const video
= videosListBase
[0]
455 utils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
458 const videos
= res
.body
.data
459 expect(res
.body
.total
).to
.equal(1)
460 expect(videos
.length
).to
.equal(1)
461 expect(videos
[0].name
).to
.equal(video
.name
)
467 it('Should list and sort by name in descending order', function (done
) {
468 utils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
471 const videos
= res
.body
.data
472 expect(res
.body
.total
).to
.equal(6)
473 expect(videos
.length
).to
.equal(6)
474 expect(videos
[5].name
=== 'video_short.mp4 name')
475 expect(videos
[4].name
=== 'video_short.ogv name')
476 expect(videos
[3].name
=== 'video_short.webm name')
477 expect(videos
[2].name
=== 'video_short1.webm name')
478 expect(videos
[1].name
=== 'video_short2.webm name')
479 expect(videos
[0].name
=== 'video_short3.webm name')
485 it('Should search and sort by name in ascending order', function (done
) {
486 utils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
489 const videos
= res
.body
.data
490 expect(res
.body
.total
).to
.equal(4)
491 expect(videos
.length
).to
.equal(4)
493 expect(videos
[0].name
=== 'video_short.webm name')
494 expect(videos
[1].name
=== 'video_short1.webm name')
495 expect(videos
[2].name
=== 'video_short2.webm name')
496 expect(videos
[3].name
=== 'video_short3.webm name')
502 after(function (done
) {
503 process
.kill(-server
.app
.pid
)
504 process
.kill(-webtorrent
.app
.pid
)
506 // Keep the logs if the test failed
508 utils
.flushTests(done
)