]>
git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/single-pod.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')
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
.podUrl
).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
.createdDate
)).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
.podUrl
).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
.createdDate
)).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
.podUrl
).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
.createdDate
)).to
.be
.true
147 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
149 expect(test
).to
.equal(true)
156 it('Should search the video by podUrl', function (done
) {
157 videosUtils
.searchVideo(server
.url
, '9001', 'podUrl', function (err
, res
) {
160 expect(res
.body
.total
).to
.equal(1)
161 expect(res
.body
.data
).to
.be
.an('array')
162 expect(res
.body
.data
.length
).to
.equal(1)
164 const video
= res
.body
.data
[0]
165 expect(video
.name
).to
.equal('my super name')
166 expect(video
.description
).to
.equal('my super description')
167 expect(video
.podUrl
).to
.equal('localhost:9001')
168 expect(video
.author
).to
.equal('root')
169 expect(video
.isLocal
).to
.be
.true
170 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
171 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
173 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
175 expect(test
).to
.equal(true)
182 it('Should search the video by tag', function (done
) {
183 videosUtils
.searchVideo(server
.url
, 'tag1', 'tags', function (err
, res
) {
186 expect(res
.body
.total
).to
.equal(1)
187 expect(res
.body
.data
).to
.be
.an('array')
188 expect(res
.body
.data
.length
).to
.equal(1)
190 const video
= res
.body
.data
[0]
191 expect(video
.name
).to
.equal('my super name')
192 expect(video
.description
).to
.equal('my super description')
193 expect(video
.podUrl
).to
.equal('localhost:9001')
194 expect(video
.author
).to
.equal('root')
195 expect(video
.isLocal
).to
.be
.true
196 expect(video
.tags
).to
.deep
.equal([ 'tag1', 'tag2', 'tag3' ])
197 expect(miscsUtils
.dateIsValid(video
.createdDate
)).to
.be
.true
199 videosUtils
.testVideoImage(server
.url
, 'video_short.webm', video
.thumbnailPath
, function (err
, test
) {
201 expect(test
).to
.equal(true)
208 it('Should not find a search by name by default', function (done
) {
209 videosUtils
.searchVideo(server
.url
, 'hello', function (err
, res
) {
212 expect(res
.body
.total
).to
.equal(0)
213 expect(res
.body
.data
).to
.be
.an('array')
214 expect(res
.body
.data
.length
).to
.equal(0)
220 it('Should not find a search by author', function (done
) {
221 videosUtils
.searchVideo(server
.url
, 'hello', 'author', function (err
, res
) {
224 expect(res
.body
.total
).to
.equal(0)
225 expect(res
.body
.data
).to
.be
.an('array')
226 expect(res
.body
.data
.length
).to
.equal(0)
232 it('Should not find a search by tag', function (done
) {
233 videosUtils
.searchVideo(server
.url
, 'tag', 'tags', function (err
, res
) {
236 expect(res
.body
.total
).to
.equal(0)
237 expect(res
.body
.data
).to
.be
.an('array')
238 expect(res
.body
.data
.length
).to
.equal(0)
244 it('Should remove the video', function (done
) {
245 videosUtils
.removeVideo(server
.url
, server
.accessToken
, videoId
, function (err
) {
248 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/videos/'), function (err
, files
) {
251 expect(files
.length
).to
.equal(0)
253 fs
.readdir(pathUtils
.join(__dirname
, '../../../test1/thumbnails/'), function (err
, files
) {
256 expect(files
.length
).to
.equal(0)
264 it('Should not have videos', function (done
) {
265 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
268 expect(res
.body
.total
).to
.equal(0)
269 expect(res
.body
.data
).to
.be
.an('array')
270 expect(res
.body
.data
.length
).to
.equal(0)
276 it('Should upload 6 videos', function (done
) {
279 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
280 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
282 each(videos
, function (video
, callbackEach
) {
283 const name
= video
+ ' name'
284 const description
= video
+ ' description'
285 const tags
= [ 'tag1', 'tag2', 'tag3' ]
287 videosUtils
.uploadVideo(server
.url
, server
.accessToken
, name
, description
, tags
, video
, callbackEach
)
291 it('Should have the correct durations', function (done
) {
292 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
295 expect(res
.body
.total
).to
.equal(6)
296 const videos
= res
.body
.data
297 expect(videos
).to
.be
.an('array')
298 expect(videos
.length
).to
.equal(6)
300 const videosByName
= keyBy(videos
, 'name')
301 expect(videosByName
['video_short.mp4 name'].duration
).to
.equal(5)
302 expect(videosByName
['video_short.ogv name'].duration
).to
.equal(5)
303 expect(videosByName
['video_short.webm name'].duration
).to
.equal(5)
304 expect(videosByName
['video_short1.webm name'].duration
).to
.equal(10)
305 expect(videosByName
['video_short2.webm name'].duration
).to
.equal(5)
306 expect(videosByName
['video_short3.webm name'].duration
).to
.equal(5)
312 it('Should have the correct thumbnails', function (done
) {
313 videosUtils
.getVideosList(server
.url
, function (err
, res
) {
316 const videos
= res
.body
.data
318 videosListBase
= videos
320 each(videos
, function (video
, callbackEach
) {
322 const videoName
= video
.name
.replace(' name', '')
324 videosUtils
.testVideoImage(server
.url
, videoName
, video
.thumbnailPath
, function (err
, test
) {
327 expect(test
).to
.equal(true)
334 it('Should list only the two first videos', function (done
) {
335 videosUtils
.getVideosListPagination(server
.url
, 0, 2, function (err
, res
) {
338 const videos
= res
.body
.data
339 expect(res
.body
.total
).to
.equal(6)
340 expect(videos
.length
).to
.equal(2)
341 expect(videos
[0].name
=== videosListBase
[0].name
)
342 expect(videos
[1].name
=== videosListBase
[1].name
)
348 it('Should list only the next three videos', function (done
) {
349 videosUtils
.getVideosListPagination(server
.url
, 2, 3, function (err
, res
) {
352 const videos
= res
.body
.data
353 expect(res
.body
.total
).to
.equal(6)
354 expect(videos
.length
).to
.equal(3)
355 expect(videos
[0].name
=== videosListBase
[2].name
)
356 expect(videos
[1].name
=== videosListBase
[3].name
)
357 expect(videos
[2].name
=== videosListBase
[4].name
)
363 it('Should list the last video', function (done
) {
364 videosUtils
.getVideosListPagination(server
.url
, 5, 6, function (err
, res
) {
367 const videos
= res
.body
.data
368 expect(res
.body
.total
).to
.equal(6)
369 expect(videos
.length
).to
.equal(1)
370 expect(videos
[0].name
=== videosListBase
[5].name
)
376 it('Should search the first video', function (done
) {
377 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 1, function (err
, res
) {
380 const videos
= res
.body
.data
381 expect(res
.body
.total
).to
.equal(4)
382 expect(videos
.length
).to
.equal(1)
383 expect(videos
[0].name
=== 'video_short.webm name')
389 it('Should search the last two videos', function (done
) {
390 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 2, 2, function (err
, res
) {
393 const videos
= res
.body
.data
394 expect(res
.body
.total
).to
.equal(4)
395 expect(videos
.length
).to
.equal(2)
396 expect(videos
[0].name
=== 'video_short2.webm name')
397 expect(videos
[1].name
=== 'video_short3.webm name')
403 it('Should search all the webm videos', function (done
) {
404 videosUtils
.searchVideoWithPagination(server
.url
, 'webm', 'name', 0, 15, function (err
, res
) {
407 const videos
= res
.body
.data
408 expect(res
.body
.total
).to
.equal(4)
409 expect(videos
.length
).to
.equal(4)
415 it('Should search all the root author videos', function (done
) {
416 videosUtils
.searchVideoWithPagination(server
.url
, 'root', 'author', 0, 15, function (err
, res
) {
419 const videos
= res
.body
.data
420 expect(res
.body
.total
).to
.equal(6)
421 expect(videos
.length
).to
.equal(6)
427 it('Should search all the 9001 port videos', function (done
) {
428 videosUtils
.searchVideoWithPagination(server
.url
, '9001', 'podUrl', 0, 15, function (err
, res
) {
431 const videos
= res
.body
.data
432 expect(res
.body
.total
).to
.equal(6)
433 expect(videos
.length
).to
.equal(6)
439 it('Should search all the localhost videos', function (done
) {
440 videosUtils
.searchVideoWithPagination(server
.url
, 'localhost', 'podUrl', 0, 15, function (err
, res
) {
443 const videos
= res
.body
.data
444 expect(res
.body
.total
).to
.equal(6)
445 expect(videos
.length
).to
.equal(6)
451 it('Should search the good magnetUri video', function (done
) {
452 const video
= videosListBase
[0]
453 videosUtils
.searchVideoWithPagination(server
.url
, encodeURIComponent(video
.magnetUri
), 'magnetUri', 0, 15, function (err
, res
) {
456 const videos
= res
.body
.data
457 expect(res
.body
.total
).to
.equal(1)
458 expect(videos
.length
).to
.equal(1)
459 expect(videos
[0].name
).to
.equal(video
.name
)
465 it('Should list and sort by name in descending order', function (done
) {
466 videosUtils
.getVideosListSort(server
.url
, '-name', function (err
, res
) {
469 const videos
= res
.body
.data
470 expect(res
.body
.total
).to
.equal(6)
471 expect(videos
.length
).to
.equal(6)
472 expect(videos
[5].name
=== 'video_short.mp4 name')
473 expect(videos
[4].name
=== 'video_short.ogv name')
474 expect(videos
[3].name
=== 'video_short.webm name')
475 expect(videos
[2].name
=== 'video_short1.webm name')
476 expect(videos
[1].name
=== 'video_short2.webm name')
477 expect(videos
[0].name
=== 'video_short3.webm name')
483 it('Should search and sort by name in ascending order', function (done
) {
484 videosUtils
.searchVideoWithSort(server
.url
, 'webm', 'name', function (err
, res
) {
487 const videos
= res
.body
.data
488 expect(res
.body
.total
).to
.equal(4)
489 expect(videos
.length
).to
.equal(4)
491 expect(videos
[0].name
=== 'video_short.webm name')
492 expect(videos
[1].name
=== 'video_short1.webm name')
493 expect(videos
[2].name
=== 'video_short2.webm name')
494 expect(videos
[3].name
=== 'video_short3.webm name')
500 after(function (done
) {
501 process
.kill(-server
.app
.pid
)
503 // Keep the logs if the test failed
505 serversUtils
.flushTests(done
)