]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/singlePod.js
Increase the interval for the friends requests
[github/Chocobozzz/PeerTube.git] / server / tests / api / singlePod.js
1 'use strict'
2
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')
9
10 const webtorrent = require(pathUtils.join(__dirname, '../../lib/webtorrent'))
11 webtorrent.silent = true
12
13 const utils = require('./utils')
14
15 describe('Test a single pod', function () {
16 let server = null
17 let videoId = -1
18 let videosListBase = null
19
20 before(function (done) {
21 this.timeout(20000)
22
23 async.series([
24 function (next) {
25 utils.flushTests(next)
26 },
27 function (next) {
28 utils.runServer(1, function (server1) {
29 server = server1
30 next()
31 })
32 },
33 function (next) {
34 utils.loginAndGetAccessToken(server, function (err, token) {
35 if (err) throw err
36 server.accessToken = token
37 next()
38 })
39 },
40 function (next) {
41 webtorrent.create({ host: 'client', port: '1' }, next)
42 }
43 ], done)
44 })
45
46 it('Should not have videos', function (done) {
47 utils.getVideosList(server.url, function (err, res) {
48 if (err) throw err
49
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)
53
54 done()
55 })
56 })
57
58 it('Should upload the video', function (done) {
59 this.timeout(5000)
60 utils.uploadVideo(server.url, server.accessToken, 'my super name', 'my super description', 'video_short.webm', done)
61 })
62
63 it('Should seed the uploaded video', function (done) {
64 // Yes, this could be long
65 this.timeout(60000)
66
67 utils.getVideosList(server.url, function (err, res) {
68 if (err) throw err
69
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)
73
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
82
83 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
84 if (err) throw err
85 expect(test).to.equal(true)
86
87 videoId = video.id
88
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('')
93
94 // We remove it because we'll add it again
95 webtorrent.remove(video.magnetUri, done)
96 })
97 })
98 })
99 })
100
101 it('Should get the video', function (done) {
102 // Yes, this could be long
103 this.timeout(60000)
104
105 utils.getVideo(server.url, videoId, function (err, res) {
106 if (err) throw err
107
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
116
117 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
118 if (err) throw err
119 expect(test).to.equal(true)
120
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('')
125
126 done()
127 })
128 })
129 })
130 })
131
132 it('Should search the video by name by default', function (done) {
133 utils.searchVideo(server.url, 'my', function (err, res) {
134 if (err) throw err
135
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)
139
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
147
148 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
149 if (err) throw err
150 expect(test).to.equal(true)
151
152 done()
153 })
154 })
155 })
156
157 it('Should search the video by podUrl', function (done) {
158 utils.searchVideo(server.url, '9001', 'podUrl', function (err, res) {
159 if (err) throw err
160
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)
164
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
172
173 utils.testImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
174 if (err) throw err
175 expect(test).to.equal(true)
176
177 done()
178 })
179 })
180 })
181
182 it('Should not find a search by name by default', function (done) {
183 utils.searchVideo(server.url, 'hello', function (err, res) {
184 if (err) throw err
185
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)
189
190 done()
191 })
192 })
193
194 it('Should not find a search by author', function (done) {
195 utils.searchVideo(server.url, 'hello', 'author', function (err, res) {
196 if (err) throw err
197
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)
201
202 done()
203 })
204 })
205
206 it('Should remove the video', function (done) {
207 utils.removeVideo(server.url, server.accessToken, videoId, function (err) {
208 if (err) throw err
209
210 fs.readdir(pathUtils.join(__dirname, '../../../test1/uploads/'), function (err, files) {
211 if (err) throw err
212
213 expect(files.length).to.equal(0)
214 done()
215 })
216 })
217 })
218
219 it('Should not have videos', function (done) {
220 utils.getVideosList(server.url, function (err, res) {
221 if (err) throw err
222
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)
226
227 done()
228 })
229 })
230
231 it('Should upload 6 videos', function (done) {
232 this.timeout(25000)
233 const videos = [
234 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
235 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
236 ]
237 async.each(videos, function (video, callbackEach) {
238 utils.uploadVideo(server.url, server.accessToken, video + ' name', video + ' description', video, callbackEach)
239 }, done)
240 })
241
242 it('Should have the correct durations', function (done) {
243 utils.getVideosList(server.url, function (err, res) {
244 if (err) throw err
245
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)
250
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)
258
259 done()
260 })
261 })
262
263 it('Should have the correct thumbnails', function (done) {
264 utils.getVideosList(server.url, function (err, res) {
265 if (err) throw err
266
267 const videos = res.body.data
268 // For the next test
269 videosListBase = videos
270
271 async.each(videos, function (video, callbackEach) {
272 if (err) throw err
273 const videoName = video.name.replace(' name', '')
274
275 utils.testImage(server.url, videoName, video.thumbnailPath, function (err, test) {
276 if (err) throw err
277
278 expect(test).to.equal(true)
279 callbackEach()
280 })
281 }, done)
282 })
283 })
284
285 it('Should list only the two first videos', function (done) {
286 utils.getVideosListPagination(server.url, 0, 2, function (err, res) {
287 if (err) throw err
288
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)
294
295 done()
296 })
297 })
298
299 it('Should list only the next three videos', function (done) {
300 utils.getVideosListPagination(server.url, 2, 3, function (err, res) {
301 if (err) throw err
302
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)
309
310 done()
311 })
312 })
313
314 it('Should list the last video', function (done) {
315 utils.getVideosListPagination(server.url, 5, 6, function (err, res) {
316 if (err) throw err
317
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)
322
323 done()
324 })
325 })
326
327 it('Should search the first video', function (done) {
328 utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) {
329 if (err) throw err
330
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')
335
336 done()
337 })
338 })
339
340 it('Should search the last two videos', function (done) {
341 utils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) {
342 if (err) throw err
343
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')
349
350 done()
351 })
352 })
353
354 it('Should search all the webm videos', function (done) {
355 utils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
356 if (err) throw err
357
358 const videos = res.body.data
359 expect(res.body.total).to.equal(4)
360 expect(videos.length).to.equal(4)
361
362 done()
363 })
364 })
365
366 it('Should search all the root author videos', function (done) {
367 utils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
368 if (err) throw err
369
370 const videos = res.body.data
371 expect(res.body.total).to.equal(6)
372 expect(videos.length).to.equal(6)
373
374 done()
375 })
376 })
377
378 it('Should search all the 9001 port videos', function (done) {
379 utils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) {
380 if (err) throw err
381
382 const videos = res.body.data
383 expect(res.body.total).to.equal(6)
384 expect(videos.length).to.equal(6)
385
386 done()
387 })
388 })
389
390 it('Should search all the localhost videos', function (done) {
391 utils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) {
392 if (err) throw err
393
394 const videos = res.body.data
395 expect(res.body.total).to.equal(6)
396 expect(videos.length).to.equal(6)
397
398 done()
399 })
400 })
401
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) {
405 if (err) throw err
406
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)
411
412 done()
413 })
414 })
415
416 it('Should list and sort by name in descending order', function (done) {
417 utils.getVideosListSort(server.url, '-name', function (err, res) {
418 if (err) throw err
419
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')
429
430 done()
431 })
432 })
433
434 it('Should search and sort by name in ascending order', function (done) {
435 utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
436 if (err) throw err
437
438 const videos = res.body.data
439 expect(res.body.total).to.equal(4)
440 expect(videos.length).to.equal(4)
441
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')
446
447 done()
448 })
449 })
450
451 after(function (done) {
452 process.kill(-server.app.pid)
453 process.kill(-webtorrent.app.pid)
454
455 // Keep the logs if the test failed
456 if (this.ok) {
457 utils.flushTests(done)
458 } else {
459 done()
460 }
461 })
462 })