]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/single-pod.js
66b762f82a7766f7bbc2eadbfc29a5e098eb8a10
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')
10 const webtorrent
= new (require('webtorrent'))()
12 const loginUtils
= require('../utils/login')
13 const miscsUtils
= require('../utils/miscs')
14 const serversUtils
= require('../utils/servers')
15 const videosUtils
= require('../utils/videos')
17 describe('Test a single pod', function () {
20 let videosListBase
= null
22 before(function (done
) {
27 serversUtils
.flushTests(next
)
30 serversUtils
.runServer(1, function (server1
) {
36 loginUtils
.loginAndGetAccessToken(server
, function (err
, token
) {
38 server
.accessToken
= token
45 it('Should not have videos', function (done
) {
46 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
49 expect(res
.body
.total
).to
.equal(0)
50 expect(res
.body
.data
).to
.be
.an('array')
51 expect(res
.body
.data
.length
).to
.equal(0)
57 it('Should upload the video', function (done
) {
59 const name
= 'my super name'
60 const description
= 'my super description'
61 const tags
= [ 'tag1', 'tag2', 'tag3' ]
62 const file
= 'video_short.webm'
63 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, file
, done
)
66 it('Should seed the uploaded video', function (done
) {
67 // Yes, this could be long
70 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
73 expect(res
.body
.total
).to
.equal(1)
74 expect(res
.body
.data
).to
.be
.an('array')
75 expect(res
.body
.data
.length
).to
.equal(1)
77 const video
= res
.body
.data
[0]
78 expect(video
.name
).to
.equal('my super name')
79 expect(video
.description
).to
.equal('my super description')
80 expect(video
.podHost
).to
.equal('localhost:9001')
81 expect(video
.magnetUri
).to
.exist
82 expect(video
.author
).to
.equal('root')
83 expect(video
.isLocal
).to
.be
.true
84 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
85 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
87 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
89 expect(test
).to
.equal(true)
93 webtorrent
.add(video
.magnetUri
, function (torrent
) {
94 expect(torrent
.files
).to
.exist
95 expect(torrent
.files
.length
).to
.equal(1)
96 expect(torrent
.files
[0].path
).to
.exist
.and
.to
.not
.equal('')
104 it('Should get the video', function (done
) {
105 // Yes, this could be long
108 videosUtils
.getVideo(server
.url
, videoId
, function (err
, res
) {
111 const video
= res
.body
112 expect(video
.name
).to
.equal('my super name')
113 expect(video
.description
).to
.equal('my super description')
114 expect(video
.podHost
).to
.equal('localhost:9001')
115 expect(video
.magnetUri
).to
.exist
116 expect(video
.author
).to
.equal('root')
117 expect(video
.isLocal
).to
.be
.true
118 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
119 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
121 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
123 expect(test
).to
.equal(true)
130 it('Should search the video by name by default', function (done
) {
131 videosUtils
.searchVideo(server
.url
, 'my', function (err
, res
) {
134 expect(res
.body
.total
).to
.equal(1)
135 expect(res
.body
.data
).to
.be
.an('array')
136 expect(res
.body
.data
.length
).to
.equal(1)
138 const video
= res
.body
.data
[0]
139 expect(video
.name
).to
.equal('my super name')
140 expect(video
.description
).to
.equal('my super description')
141 expect(video
.podHost
).to
.equal('localhost:9001')
142 expect(video
.author
).to
.equal('root')
143 expect(video
.isLocal
).to
.be
.true
144 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
145 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
147 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
149 expect(test
).to
.equal(true)
156 // Not implemented yet
157 // it('Should search the video by podHost', function (done) {
158 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
159 // if (err) throw err
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.podHost).to.equal('localhost:9001')
169 // expect(video.author).to.equal('root')
170 // expect(video.isLocal).to.be.true
171 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
172 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
174 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
175 // if (err) throw err
176 // expect(test).to.equal(true)
183 it('Should search the video by tag', function (done
) {
184 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
187 expect(res
.body
.total
).to
.equal(1)
188 expect(res
.body
.data
).to
.be
.an('array')
189 expect(res
.body
.data
.length
).to
.equal(1)
191 const video
= res
.body
.data
[0]
192 expect(video
.name
).to
.equal('my super name')
193 expect(video
.description
).to
.equal('my super description')
194 expect(video
.podHost
).to
.equal('localhost:9001')
195 expect(video
.author
).to
.equal('root')
196 expect(video
.isLocal
).to
.be
.true
197 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
198 expect(miscsUtils
.dateIsValid(video
.createdAt
)).to
.be
.true
200 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
202 expect(test
).to
.equal(true)
209 it('Should not find a search by name by default', function (done
) {
210 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
213 expect(res
.body
.total
).to
.equal(0)
214 expect(res
.body
.data
).to
.be
.an('array')
215 expect(res
.body
.data
.length
).to
.equal(0)
221 it('Should not find a search by author', function (done
) {
222 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
225 expect(res
.body
.total
).to
.equal(0)
226 expect(res
.body
.data
).to
.be
.an('array')
227 expect(res
.body
.data
.length
).to
.equal(0)
233 it('Should not find a search by tag', function (done
) {
234 videosUtils
.searchVideo(server
.url
, 'hello', 'tags', function (err
, res
) {
237 expect(res
.body
.total
).to
.equal(0)
238 expect(res
.body
.data
).to
.be
.an('array')
239 expect(res
.body
.data
.length
).to
.equal(0)
245 it('Should remove the video', function (done
) {
246 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
249 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/videos/'), function (err
, files
) {
252 expect(files
.length
).to
.equal(0)
254 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/thumbnails/'), function (err
, files
) {
257 expect(files
.length
).to
.equal(0)
265 it('Should not have videos', function (done
) {
266 videosUtils
.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 each(videos
, function (video
, callbackEach
) {
284 const name
= video
+ ' name'
285 const description
= video
+ ' description'
286 const tags
= [ 'tag1', 'tag2', 'tag3' ]
288 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
292 it('Should have the correct durations', function (done
) {
293 videosUtils
.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 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
317 const videos
= res
.body
.data
319 videosListBase
= videos
321 each(videos
, function (video
, callbackEach
) {
323 const videoName
= video
.name
.replace(' name', '')
325 videosUtils
.testVideoImage(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 videosUtils
.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 videosUtils
.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(3)
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 videosUtils
.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 videosUtils
.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 videosUtils
.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 videosUtils
.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 videosUtils
.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 // Not implemented yet
429 // it('Should search all the 9001 port videos', function (done) {
430 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
431 // if (err) throw err
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 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
443 // if (err) throw err
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 videosUtils
.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 videosUtils
.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 videosUtils
.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
)
505 // Keep the logs if the test failed
507 serversUtils
.flushTests(done
)