]>
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 not find a search by name by default', function (done
) {
191 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
194 expect(res
.body
.total
).to
.equal(0)
195 expect(res
.body
.data
).to
.be
.an('array')
196 expect(res
.body
.data
.length
).to
.equal(0)
202 it('Should not find a search by author', function (done
) {
203 utils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
206 expect(res
.body
.total
).to
.equal(0)
207 expect(res
.body
.data
).to
.be
.an('array')
208 expect(res
.body
.data
.length
).to
.equal(0)
214 it('Should remove the video', function (done
) {
215 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
218 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
221 expect(files
.length
).to
.equal(0)
227 it('Should not have videos', function (done
) {
228 utils
.getVideosList(server
.url
, 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 upload 6 videos', function (done
) {
242 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
243 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
245 async
.each(videos
, function (video
, callbackEach
) {
246 const name
= video
+ ' name'
247 const description
= video
+ ' description'
248 const tags
= [ 'tag1', 'tag2', 'tag3' ]
250 utils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
254 it('Should have the correct durations', function (done
) {
255 utils
.getVideosList(server
.url
, function (err
, res
) {
258 expect(res
.body
.total
).to
.equal(6)
259 const videos
= res
.body
.data
260 expect(videos
).to
.be
.an('array')
261 expect(videos
.length
).to
.equal(6)
263 const videosByName
= keyBy(videos
, 'name')
264 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
265 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
266 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
267 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
268 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
269 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
275 it('Should have the correct thumbnails', function (done
) {
276 utils
.getVideosList(server
.url
, function (err
, res
) {
279 const videos
= res
.body
.data
281 videosListBase
= videos
283 async
.each(videos
, function (video
, callbackEach
) {
285 const videoName
= video
.name
.replace(' name', '')
287 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
290 expect(test
).to
.equal(true)
297 it('Should list only the two first videos', function (done
) {
298 utils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
301 const videos
= res
.body
.data
302 expect(res
.body
.total
).to
.equal(6)
303 expect(videos
.length
).to
.equal(2)
304 expect(videos
[0].name
=== videosListBase
[0].name
)
305 expect(videos
[1].name
=== videosListBase
[1].name
)
311 it('Should list only the next three videos', function (done
) {
312 utils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
315 const videos
= res
.body
.data
316 expect(res
.body
.total
).to
.equal(6)
317 expect(videos
.length
).to
.equal(4)
318 expect(videos
[0].name
=== videosListBase
[2].name
)
319 expect(videos
[1].name
=== videosListBase
[3].name
)
320 expect(videos
[2].name
=== videosListBase
[4].name
)
326 it('Should list the last video', function (done
) {
327 utils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
330 const videos
= res
.body
.data
331 expect(res
.body
.total
).to
.equal(6)
332 expect(videos
.length
).to
.equal(1)
333 expect(videos
[0].name
=== videosListBase
[5].name
)
339 it('Should search the first video', function (done
) {
340 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, function (err
, res
) {
343 const videos
= res
.body
.data
344 expect(res
.body
.total
).to
.equal(4)
345 expect(videos
.length
).to
.equal(1)
346 expect(videos
[0].name
=== 'video_short.webm name')
352 it('Should search the last two videos', function (done
) {
353 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, function (err
, res
) {
356 const videos
= res
.body
.data
357 expect(res
.body
.total
).to
.equal(4)
358 expect(videos
.length
).to
.equal(2)
359 expect(videos
[0].name
=== 'video_short2.webm name')
360 expect(videos
[1].name
=== 'video_short3.webm name')
366 it('Should search all the webm videos', function (done
) {
367 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
370 const videos
= res
.body
.data
371 expect(res
.body
.total
).to
.equal(4)
372 expect(videos
.length
).to
.equal(4)
378 it('Should search all the root author videos', function (done
) {
379 utils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
382 const videos
= res
.body
.data
383 expect(res
.body
.total
).to
.equal(6)
384 expect(videos
.length
).to
.equal(6)
390 it('Should search all the 9001 port videos', function (done
) {
391 utils
.searchVideoWithPagination(server
.url
, '9001', 'podUrl', 0, 15, function (err
, res
) {
394 const videos
= res
.body
.data
395 expect(res
.body
.total
).to
.equal(6)
396 expect(videos
.length
).to
.equal(6)
402 it('Should search all the localhost videos', function (done
) {
403 utils
.searchVideoWithPagination(server
.url
, 'localhost', 'podUrl', 0, 15, function (err
, res
) {
406 const videos
= res
.body
.data
407 expect(res
.body
.total
).to
.equal(6)
408 expect(videos
.length
).to
.equal(6)
414 it('Should search the good magnetUri video', function (done
) {
415 const video
= videosListBase
[0]
416 utils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
419 const videos
= res
.body
.data
420 expect(res
.body
.total
).to
.equal(1)
421 expect(videos
.length
).to
.equal(1)
422 expect(videos
[0].name
).to
.equal(video
.name
)
428 it('Should list and sort by name in descending order', function (done
) {
429 utils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
432 const videos
= res
.body
.data
433 expect(res
.body
.total
).to
.equal(6)
434 expect(videos
.length
).to
.equal(6)
435 expect(videos
[5].name
=== 'video_short.mp4 name')
436 expect(videos
[4].name
=== 'video_short.ogv name')
437 expect(videos
[3].name
=== 'video_short.webm name')
438 expect(videos
[2].name
=== 'video_short1.webm name')
439 expect(videos
[1].name
=== 'video_short2.webm name')
440 expect(videos
[0].name
=== 'video_short3.webm name')
446 it('Should search and sort by name in ascending order', function (done
) {
447 utils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
450 const videos
= res
.body
.data
451 expect(res
.body
.total
).to
.equal(4)
452 expect(videos
.length
).to
.equal(4)
454 expect(videos
[0].name
=== 'video_short.webm name')
455 expect(videos
[1].name
=== 'video_short1.webm name')
456 expect(videos
[2].name
=== 'video_short2.webm name')
457 expect(videos
[3].name
=== 'video_short3.webm name')
463 after(function (done
) {
464 process
.kill(-server
.app
.pid
)
465 process
.kill(-webtorrent
.app
.pid
)
467 // Keep the logs if the test failed
469 utils
.flushTests(done
)