]>
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 utils
.uploadVideo(server
.url
, server
.accessToken
, 'my super name', 'my super description', 'video_short.webm', done
)
63 it('Should seed the uploaded video', function (done
) {
64 // Yes, this could be long
67 utils
.getVideosList(server
.url
, function (err
, res
) {
70 expect(res
.body
.total
).to
.equal(1)
71 expect(res
.body
.data
).to
.be
.an('array')
72 expect(res
.body
.data
.length
).to
.equal(1)
74 const video
= res
.body
.data
[0]
75 expect(video
.name
).to
.equal('my super name')
76 expect(video
.description
).to
.equal('my super description')
77 expect(video
.podUrl
).to
.equal('localhost:9001')
78 expect(video
.magnetUri
).to
.exist
79 expect(video
.author
).to
.equal('root')
80 expect(video
.isLocal
).to
.be
.true
81 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
83 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
85 expect(test
).to
.equal(true)
89 webtorrent
.add(video
.magnetUri
, function (torrent
) {
90 expect(torrent
.files
).to
.exist
91 expect(torrent
.files
.length
).to
.equal(1)
92 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
94 // We remove it because we'll add it again
95 webtorrent
.remove(video
.magnetUri
, done
)
101 it('Should get the video', function (done
) {
102 // Yes, this could be long
105 utils
.getVideo(server
.url
, videoId
, function (err
, res
) {
108 const video
= res
.body
109 expect(video
.name
).to
.equal('my super name')
110 expect(video
.description
).to
.equal('my super description')
111 expect(video
.podUrl
).to
.equal('localhost:9001')
112 expect(video
.magnetUri
).to
.exist
113 expect(video
.author
).to
.equal('root')
114 expect(video
.isLocal
).to
.be
.true
115 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
117 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
119 expect(test
).to
.equal(true)
121 webtorrent
.add(video
.magnetUri
, function (torrent
) {
122 expect(torrent
.files
).to
.exist
123 expect(torrent
.files
.length
).to
.equal(1)
124 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
132 it('Should search the video by name by default', function (done
) {
133 utils
.searchVideo(server
.url
, 'my', function (err
, res
) {
136 expect(res
.body
.total
).to
.equal(1)
137 expect(res
.body
.data
).to
.be
.an('array')
138 expect(res
.body
.data
.length
).to
.equal(1)
140 const video
= res
.body
.data
[0]
141 expect(video
.name
).to
.equal('my super name')
142 expect(video
.description
).to
.equal('my super description')
143 expect(video
.podUrl
).to
.equal('localhost:9001')
144 expect(video
.author
).to
.equal('root')
145 expect(video
.isLocal
).to
.be
.true
146 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
148 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
150 expect(test
).to
.equal(true)
157 it('Should search the video by podUrl', function (done
) {
158 utils
.searchVideo(server
.url
, '9001', 'podUrl', function (err
, res
) {
161 expect(res
.body
.total
).to
.equal(1)
162 expect(res
.body
.data
).to
.be
.an('array')
163 expect(res
.body
.data
.length
).to
.equal(1)
165 const video
= res
.body
.data
[0]
166 expect(video
.name
).to
.equal('my super name')
167 expect(video
.description
).to
.equal('my super description')
168 expect(video
.podUrl
).to
.equal('localhost:9001')
169 expect(video
.author
).to
.equal('root')
170 expect(video
.isLocal
).to
.be
.true
171 expect(utils
.dateIsValid(video
.createdDate
)).to
.be
.true
173 utils
.testImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
175 expect(test
).to
.equal(true)
182 it('Should not find a search by name by default', function (done
) {
183 utils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
186 expect(res
.body
.total
).to
.equal(0)
187 expect(res
.body
.data
).to
.be
.an('array')
188 expect(res
.body
.data
.length
).to
.equal(0)
194 it('Should not find a search by author', function (done
) {
195 utils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
198 expect(res
.body
.total
).to
.equal(0)
199 expect(res
.body
.data
).to
.be
.an('array')
200 expect(res
.body
.data
.length
).to
.equal(0)
206 it('Should remove the video', function (done
) {
207 utils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
210 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/uploads/'), function (err
, files
) {
213 expect(files
.length
).to
.equal(0)
219 it('Should not have videos', function (done
) {
220 utils
.getVideosList(server
.url
, 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 upload 6 videos', function (done
) {
234 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
235 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
237 async
.each(videos
, function (video
, callbackEach
) {
238 utils
.uploadVideo(server
.url
, server
.accessToken
, video
+ ' name', video
+ ' description', video
, callbackEach
)
242 it('Should have the correct durations', function (done
) {
243 utils
.getVideosList(server
.url
, function (err
, res
) {
246 expect(res
.body
.total
).to
.equal(6)
247 const videos
= res
.body
.data
248 expect(videos
).to
.be
.an('array')
249 expect(videos
.length
).to
.equal(6)
251 const videosByName
= keyBy(videos
, 'name')
252 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
253 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
254 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
255 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
256 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
257 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
263 it('Should have the correct thumbnails', function (done
) {
264 utils
.getVideosList(server
.url
, function (err
, res
) {
267 const videos
= res
.body
.data
269 videosListBase
= videos
271 async
.each(videos
, function (video
, callbackEach
) {
273 const videoName
= video
.name
.replace(' name', '')
275 utils
.testImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
278 expect(test
).to
.equal(true)
285 it('Should list only the two first videos', function (done
) {
286 utils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
289 const videos
= res
.body
.data
290 expect(res
.body
.total
).to
.equal(6)
291 expect(videos
.length
).to
.equal(2)
292 expect(videos
[0].name
=== videosListBase
[0].name
)
293 expect(videos
[1].name
=== videosListBase
[1].name
)
299 it('Should list only the next three videos', function (done
) {
300 utils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
303 const videos
= res
.body
.data
304 expect(res
.body
.total
).to
.equal(6)
305 expect(videos
.length
).to
.equal(4)
306 expect(videos
[0].name
=== videosListBase
[2].name
)
307 expect(videos
[1].name
=== videosListBase
[3].name
)
308 expect(videos
[2].name
=== videosListBase
[4].name
)
314 it('Should list the last video', function (done
) {
315 utils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
318 const videos
= res
.body
.data
319 expect(res
.body
.total
).to
.equal(6)
320 expect(videos
.length
).to
.equal(1)
321 expect(videos
[0].name
=== videosListBase
[5].name
)
327 it('Should search the first video', function (done
) {
328 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, function (err
, res
) {
331 const videos
= res
.body
.data
332 expect(res
.body
.total
).to
.equal(4)
333 expect(videos
.length
).to
.equal(1)
334 expect(videos
[0].name
=== 'video_short.webm name')
340 it('Should search the last two videos', function (done
) {
341 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, function (err
, res
) {
344 const videos
= res
.body
.data
345 expect(res
.body
.total
).to
.equal(4)
346 expect(videos
.length
).to
.equal(2)
347 expect(videos
[0].name
=== 'video_short2.webm name')
348 expect(videos
[1].name
=== 'video_short3.webm name')
354 it('Should search all the webm videos', function (done
) {
355 utils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
358 const videos
= res
.body
.data
359 expect(res
.body
.total
).to
.equal(4)
360 expect(videos
.length
).to
.equal(4)
366 it('Should search all the root author videos', function (done
) {
367 utils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
370 const videos
= res
.body
.data
371 expect(res
.body
.total
).to
.equal(6)
372 expect(videos
.length
).to
.equal(6)
378 it('Should search all the 9001 port videos', function (done
) {
379 utils
.searchVideoWithPagination(server
.url
, '9001', 'podUrl', 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 localhost videos', function (done
) {
391 utils
.searchVideoWithPagination(server
.url
, 'localhost', '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 the good magnetUri video', function (done
) {
403 const video
= videosListBase
[0]
404 utils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
407 const videos
= res
.body
.data
408 expect(res
.body
.total
).to
.equal(1)
409 expect(videos
.length
).to
.equal(1)
410 expect(videos
[0].name
).to
.equal(video
.name
)
416 it('Should list and sort by name in descending order', function (done
) {
417 utils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
420 const videos
= res
.body
.data
421 expect(res
.body
.total
).to
.equal(6)
422 expect(videos
.length
).to
.equal(6)
423 expect(videos
[5].name
=== 'video_short.mp4 name')
424 expect(videos
[4].name
=== 'video_short.ogv name')
425 expect(videos
[3].name
=== 'video_short.webm name')
426 expect(videos
[2].name
=== 'video_short1.webm name')
427 expect(videos
[1].name
=== 'video_short2.webm name')
428 expect(videos
[0].name
=== 'video_short3.webm name')
434 it('Should search and sort by name in ascending order', function (done
) {
435 utils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
438 const videos
= res
.body
.data
439 expect(res
.body
.total
).to
.equal(4)
440 expect(videos
.length
).to
.equal(4)
442 expect(videos
[0].name
=== 'video_short.webm name')
443 expect(videos
[1].name
=== 'video_short1.webm name')
444 expect(videos
[2].name
=== 'video_short2.webm name')
445 expect(videos
[3].name
=== 'video_short3.webm name')
451 after(function (done
) {
452 process
.kill(-server
.app
.pid
)
453 process
.kill(-webtorrent
.app
.pid
)
455 // Keep the logs if the test failed
457 utils
.flushTests(done
)