]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
3 const async
= require('async')
4 const chai
= require('chai')
5 const expect
= chai
.expect
6 const fs
= require('fs')
7 const keyBy
= require('lodash/keyBy')
8 const pathUtils
= require('path')
10 const webtorrent
= require(pathUtils
.join(__dirname
, '../../lib/webtorrent'))
11 webtorrent
.silent
= true
13 const utils
= require('./utils')
15 describe('Test a single pod', function () {
18 let videosListBase
= null
20 before(function (done
) {
25 utils
.flushTests(next
)
28 utils
.runServer(1, function (server1
) {
34 utils
.loginAndGetAccessToken(server
, function (err
, token
) {
36 server
.accessToken
= token
41 webtorrent
.create({ host: 'client', port: '1' }, next
)
46 it('Should not have videos', function (done
) {
47 utils
.getVideosList(server
.url
, function (err
, res
) {
50 expect(res
.body
.total
).to
.equal(0)
51 expect(res
.body
.data
).to
.be
.an('array')
52 expect(res
.body
.data
.length
).to
.equal(0)
58 it('Should upload the video', function (done
) {
60 const name
= 'my super name'
61 const description
= 'my super description'
62 const tags
= [ 'tag1', 'tag2', 'tag3' ]
63 const file
= 'video_short.webm'
64 utils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, file
, done
)
67 it('Should seed the uploaded video', function (done
) {
68 // Yes, this could be long
71 utils
.getVideosList(server
.url
, function (err
, res
) {
74 expect(res
.body
.total
).to
.equal(1)
75 expect(res
.body
.data
).to
.be
.an('array')
76 expect(res
.body
.data
.length
).to
.equal(1)
78 const video
= res
.body
.data
[0]
79 expect(video
.name
).to
.equal('my super name')
80 expect(video
.description
).to
.equal('my super description')
81 expect(video
.podUrl
).to
.equal('localhost:9001')
82 expect(video
.magnetUri
).to
.exist
83 expect(video
.author
).to
.equal('root')
84 expect(video
.isLocal
).to
.be
.true
85 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
86 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
88 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
90 expect(test
).to
.equal(true)
94 webtorrent
.add(video
.magnetUri
, function (torrent
) {
95 expect(torrent
.files
).to
.exist
96 expect(torrent
.files
.length
).to
.equal(1)
97 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
99 // We remove it because we'll add it again
100 webtorrent
.remove(video
.magnetUri
, done
)
106 it('Should get the video', function (done
) {
107 // Yes, this could be long
110 utils
.getVideo(server
.url
, videoId
, function (err
, res
) {
113 const video
= res
.body
114 expect(video
.name
).to
.equal('my super name')
115 expect(video
.description
).to
.equal('my super description')
116 expect(video
.podUrl
).to
.equal('localhost:9001')
117 expect(video
.magnetUri
).to
.exist
118 expect(video
.author
).to
.equal('root')
119 expect(video
.isLocal
).to
.be
.true
120 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
121 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
123 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
125 expect(test
).to
.equal(true)
127 webtorrent
.add(video
.magnetUri
, function (torrent
) {
128 expect(torrent
.files
).to
.exist
129 expect(torrent
.files
.length
).to
.equal(1)
130 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
138 it('Should search the video by name by default', function (done
) {
139 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
142 expect(res
.body
.total
).to
.equal(1)
143 expect(res
.body
.data
).to
.be
.an('array')
144 expect(res
.body
.data
.length
).to
.equal(1)
146 const video
= res
.body
.data
[0]
147 expect(video
.name
).to
.equal('my super name')
148 expect(video
.description
).to
.equal('my super description')
149 expect(video
.podUrl
).to
.equal('localhost:9001')
150 expect(video
.author
).to
.equal('root')
151 expect(video
.isLocal
).to
.be
.true
152 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
153 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
155 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
157 expect(test
).to
.equal(true)
164 it('Should search the video by podUrl', function (done
) {
165 utils
.searchVideo(server
.url
, '9001', 'podUrl', function (err
, res
) {
168 expect(res
.body
.total
).to
.equal(1)
169 expect(res
.body
.data
).to
.be
.an('array')
170 expect(res
.body
.data
.length
).to
.equal(1)
172 const video
= res
.body
.data
[0]
173 expect(video
.name
).to
.equal('my super name')
174 expect(video
.description
).to
.equal('my super description')
175 expect(video
.podUrl
).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(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
181 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
183 expect(test
).to
.equal(true)
190 it('Should search the video by tag', function (done
) {
191 utils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
194 expect(res
.body
.total
).to
.equal(1)
195 expect(res
.body
.data
).to
.be
.an('array')
196 expect(res
.body
.data
.length
).to
.equal(1)
198 const video
= res
.body
.data
[0]
199 expect(video
.name
).to
.equal('my super name')
200 expect(video
.description
).to
.equal('my super description')
201 expect(video
.podUrl
).to
.equal('localhost:9001')
202 expect(video
.author
).to
.equal('root')
203 expect(video
.isLocal
).to
.be
.true
204 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
205 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
207 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
209 expect(test
).to
.equal(true)
216 it('Should not find a search by name by default', function (done
) {
217 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
220 expect(res
.body
.total
).to
.equal(0)
221 expect(res
.body
.data
).to
.be
.an('array')
222 expect(res
.body
.data
.length
).to
.equal(0)
228 it('Should not find a search by author', function (done
) {
229 utils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
232 expect(res
.body
.total
).to
.equal(0)
233 expect(res
.body
.data
).to
.be
.an('array')
234 expect(res
.body
.data
.length
).to
.equal(0)
240 it('Should not find a search by tag', function (done
) {
241 utils
.searchVideo(server
.url
, 'tag', 'tags', function (err
, res
) {
244 expect(res
.body
.total
).to
.equal(0)
245 expect(res
.body
.data
).to
.be
.an('array')
246 expect(res
.body
.data
.length
).to
.equal(0)
252 it('Should remove the video', function (done
) {
253 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
256 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
259 expect(files
.length
).to
.equal(0)
265 it('Should not have videos', function (done
) {
266 utils
.getVideosList(server
.url
, function (err
, res
) {
269 expect(res
.body
.total
).to
.equal(0)
270 expect(res
.body
.data
).to
.be
.an('array')
271 expect(res
.body
.data
.length
).to
.equal(0)
277 it('Should upload 6 videos', function (done
) {
280 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
281 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
283 async
.each(videos
, function (video
, callbackEach
) {
284 const name
= video
+ ' name'
285 const description
= video
+ ' description'
286 const tags
= [ 'tag1', 'tag2', 'tag3' ]
288 utils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
292 it('Should have the correct durations', function (done
) {
293 utils
.getVideosList(server
.url
, function (err
, res
) {
296 expect(res
.body
.total
).to
.equal(6)
297 const videos
= res
.body
.data
298 expect(videos
).to
.be
.an('array')
299 expect(videos
.length
).to
.equal(6)
301 const videosByName
= keyBy(videos
, 'name')
302 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
303 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
304 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
305 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
306 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
307 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
313 it('Should have the correct thumbnails', function (done
) {
314 utils
.getVideosList(server
.url
, function (err
, res
) {
317 const videos
= res
.body
.data
319 videosListBase
= videos
321 async
.each(videos
, function (video
, callbackEach
) {
323 const videoName
= video
.name
.replace(' name', '')
325 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
328 expect(test
).to
.equal(true)
335 it('Should list only the two first videos', function (done
) {
336 utils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
339 const videos
= res
.body
.data
340 expect(res
.body
.total
).to
.equal(6)
341 expect(videos
.length
).to
.equal(2)
342 expect(videos
[0].name
=== videosListBase
[0].name
)
343 expect(videos
[1].name
=== videosListBase
[1].name
)
349 it('Should list only the next three videos', function (done
) {
350 utils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
353 const videos
= res
.body
.data
354 expect(res
.body
.total
).to
.equal(6)
355 expect(videos
.length
).to
.equal(4)
356 expect(videos
[0].name
=== videosListBase
[2].name
)
357 expect(videos
[1].name
=== videosListBase
[3].name
)
358 expect(videos
[2].name
=== videosListBase
[4].name
)
364 it('Should list the last video', function (done
) {
365 utils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
368 const videos
= res
.body
.data
369 expect(res
.body
.total
).to
.equal(6)
370 expect(videos
.length
).to
.equal(1)
371 expect(videos
[0].name
=== videosListBase
[5].name
)
377 it('Should search the first video', function (done
) {
378 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, function (err
, res
) {
381 const videos
= res
.body
.data
382 expect(res
.body
.total
).to
.equal(4)
383 expect(videos
.length
).to
.equal(1)
384 expect(videos
[0].name
=== 'video_short.webm name')
390 it('Should search the last two videos', function (done
) {
391 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, function (err
, res
) {
394 const videos
= res
.body
.data
395 expect(res
.body
.total
).to
.equal(4)
396 expect(videos
.length
).to
.equal(2)
397 expect(videos
[0].name
=== 'video_short2.webm name')
398 expect(videos
[1].name
=== 'video_short3.webm name')
404 it('Should search all the webm videos', function (done
) {
405 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
408 const videos
= res
.body
.data
409 expect(res
.body
.total
).to
.equal(4)
410 expect(videos
.length
).to
.equal(4)
416 it('Should search all the root author videos', function (done
) {
417 utils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
420 const videos
= res
.body
.data
421 expect(res
.body
.total
).to
.equal(6)
422 expect(videos
.length
).to
.equal(6)
428 it('Should search all the 9001 port videos', function (done
) {
429 utils
.searchVideoWithPagination(server
.url
, '9001', 'podUrl', 0, 15, function (err
, res
) {
432 const videos
= res
.body
.data
433 expect(res
.body
.total
).to
.equal(6)
434 expect(videos
.length
).to
.equal(6)
440 it('Should search all the localhost videos', function (done
) {
441 utils
.searchVideoWithPagination(server
.url
, 'localhost', 'podUrl', 0, 15, function (err
, res
) {
444 const videos
= res
.body
.data
445 expect(res
.body
.total
).to
.equal(6)
446 expect(videos
.length
).to
.equal(6)
452 it('Should search the good magnetUri video', function (done
) {
453 const video
= videosListBase
[0]
454 utils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
457 const videos
= res
.body
.data
458 expect(res
.body
.total
).to
.equal(1)
459 expect(videos
.length
).to
.equal(1)
460 expect(videos
[0].name
).to
.equal(video
.name
)
466 it('Should list and sort by name in descending order', function (done
) {
467 utils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
470 const videos
= res
.body
.data
471 expect(res
.body
.total
).to
.equal(6)
472 expect(videos
.length
).to
.equal(6)
473 expect(videos
[5].name
=== 'video_short.mp4 name')
474 expect(videos
[4].name
=== 'video_short.ogv name')
475 expect(videos
[3].name
=== 'video_short.webm name')
476 expect(videos
[2].name
=== 'video_short1.webm name')
477 expect(videos
[1].name
=== 'video_short2.webm name')
478 expect(videos
[0].name
=== 'video_short3.webm name')
484 it('Should search and sort by name in ascending order', function (done
) {
485 utils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
488 const videos
= res
.body
.data
489 expect(res
.body
.total
).to
.equal(4)
490 expect(videos
.length
).to
.equal(4)
492 expect(videos
[0].name
=== 'video_short.webm name')
493 expect(videos
[1].name
=== 'video_short1.webm name')
494 expect(videos
[2].name
=== 'video_short2.webm name')
495 expect(videos
[3].name
=== 'video_short3.webm name')
501 after(function (done
) {
502 process
.kill(-server
.app
.pid
)
503 process
.kill(-webtorrent
.app
.pid
)
505 // Keep the logs if the test failed
507 utils
.flushTests(done
)