aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/single-pod.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/single-pod.js')
-rw-r--r--server/tests/api/single-pod.js841
1 files changed, 0 insertions, 841 deletions
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
deleted file mode 100644
index 6933d18dd..000000000
--- a/server/tests/api/single-pod.js
+++ /dev/null
@@ -1,841 +0,0 @@
1/* eslint-disable no-unused-expressions */
2
3'use strict'
4
5const chai = require('chai')
6const each = require('async/each')
7const expect = chai.expect
8const fs = require('fs')
9const keyBy = require('lodash/keyBy')
10const pathUtils = require('path')
11const series = require('async/series')
12const webtorrent = new (require('webtorrent'))()
13
14const loginUtils = require('../utils/login')
15const miscsUtils = require('../utils/miscs')
16const serversUtils = require('../utils/servers')
17const videosUtils = require('../utils/videos')
18
19describe('Test a single pod', function () {
20 let server = null
21 let videoId = -1
22 let videoUUID = ''
23 let videosListBase = null
24
25 before(function (done) {
26 this.timeout(120000)
27
28 series([
29 function (next) {
30 serversUtils.flushTests(next)
31 },
32 function (next) {
33 serversUtils.runServer(1, function (server1) {
34 server = server1
35 next()
36 })
37 },
38 function (next) {
39 loginUtils.loginAndGetAccessToken(server, function (err, token) {
40 if (err) throw err
41 server.accessToken = token
42 next()
43 })
44 }
45 ], done)
46 })
47
48 it('Should list video categories', function (done) {
49 videosUtils.getVideoCategories(server.url, function (err, res) {
50 if (err) throw err
51
52 const categories = res.body
53 expect(Object.keys(categories)).to.have.length.above(10)
54
55 expect(categories[11]).to.equal('News')
56
57 done()
58 })
59 })
60
61 it('Should list video licences', function (done) {
62 videosUtils.getVideoLicences(server.url, function (err, res) {
63 if (err) throw err
64
65 const licences = res.body
66 expect(Object.keys(licences)).to.have.length.above(5)
67
68 expect(licences[3]).to.equal('Attribution - No Derivatives')
69
70 done()
71 })
72 })
73
74 it('Should list video languages', function (done) {
75 videosUtils.getVideoLanguages(server.url, function (err, res) {
76 if (err) throw err
77
78 const languages = res.body
79 expect(Object.keys(languages)).to.have.length.above(5)
80
81 expect(languages[3]).to.equal('Mandarin')
82
83 done()
84 })
85 })
86
87 it('Should not have videos', function (done) {
88 videosUtils.getVideosList(server.url, function (err, res) {
89 if (err) throw err
90
91 expect(res.body.total).to.equal(0)
92 expect(res.body.data).to.be.an('array')
93 expect(res.body.data.length).to.equal(0)
94
95 done()
96 })
97 })
98
99 it('Should upload the video', function (done) {
100 const videoAttributes = {
101 name: 'my super name',
102 category: 2,
103 nsfw: true,
104 licence: 6,
105 tags: [ 'tag1', 'tag2', 'tag3' ]
106 }
107 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done)
108 })
109
110 it('Should seed the uploaded video', function (done) {
111 // Yes, this could be long
112 this.timeout(60000)
113
114 videosUtils.getVideosList(server.url, function (err, res) {
115 if (err) throw err
116
117 expect(res.body.total).to.equal(1)
118 expect(res.body.data).to.be.an('array')
119 expect(res.body.data.length).to.equal(1)
120
121 const video = res.body.data[0]
122 expect(video.name).to.equal('my super name')
123 expect(video.category).to.equal(2)
124 expect(video.categoryLabel).to.equal('Films')
125 expect(video.licence).to.equal(6)
126 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
127 expect(video.language).to.equal(3)
128 expect(video.languageLabel).to.equal('Mandarin')
129 expect(video.nsfw).to.be.ok
130 expect(video.description).to.equal('my super description')
131 expect(video.podHost).to.equal('localhost:9001')
132 expect(video.author).to.equal('root')
133 expect(video.isLocal).to.be.true
134 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
135 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
136 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
137
138 expect(video.files).to.have.lengthOf(1)
139
140 const file = video.files[0]
141 const magnetUri = file.magnetUri
142 expect(file.magnetUri).to.exist
143 expect(file.resolution).to.equal(0)
144 expect(file.resolutionLabel).to.equal('original')
145 expect(file.size).to.equal(218910)
146
147 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
148 if (err) throw err
149 expect(test).to.equal(true)
150
151 videoId = video.id
152 videoUUID = video.uuid
153
154 webtorrent.add(magnetUri, function (torrent) {
155 expect(torrent.files).to.exist
156 expect(torrent.files.length).to.equal(1)
157 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
158
159 done()
160 })
161 })
162 })
163 })
164
165 it('Should get the video', function (done) {
166 // Yes, this could be long
167 this.timeout(60000)
168
169 videosUtils.getVideo(server.url, videoId, function (err, res) {
170 if (err) throw err
171
172 const video = res.body
173 expect(video.name).to.equal('my super name')
174 expect(video.category).to.equal(2)
175 expect(video.categoryLabel).to.equal('Films')
176 expect(video.licence).to.equal(6)
177 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
178 expect(video.language).to.equal(3)
179 expect(video.languageLabel).to.equal('Mandarin')
180 expect(video.nsfw).to.be.ok
181 expect(video.description).to.equal('my super description')
182 expect(video.podHost).to.equal('localhost:9001')
183 expect(video.author).to.equal('root')
184 expect(video.isLocal).to.be.true
185 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
186 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
187 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
188
189 expect(video.files).to.have.lengthOf(1)
190
191 const file = video.files[0]
192 const magnetUri = file.magnetUri
193 expect(file.magnetUri).to.exist
194 expect(file.resolution).to.equal(0)
195 expect(file.resolutionLabel).to.equal('original')
196 expect(file.size).to.equal(218910)
197
198 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
199 if (err) throw err
200 expect(test).to.equal(true)
201
202 // Wait the async views increment
203 setTimeout(done, 500)
204 })
205 })
206 })
207
208 it('Should get the video by UUID', function (done) {
209 // Yes, this could be long
210 this.timeout(60000)
211
212 videosUtils.getVideo(server.url, videoUUID, function (err, res) {
213 if (err) throw err
214
215 const video = res.body
216 expect(video.name).to.equal('my super name')
217
218 // Wait the async views increment
219 setTimeout(done, 500)
220 })
221 })
222
223 it('Should have the views updated', function (done) {
224 videosUtils.getVideo(server.url, videoId, function (err, res) {
225 if (err) throw err
226
227 const video = res.body
228 expect(video.views).to.equal(2)
229
230 done()
231 })
232 })
233
234 it('Should search the video by name by default', function (done) {
235 videosUtils.searchVideo(server.url, 'my', function (err, res) {
236 if (err) throw err
237
238 expect(res.body.total).to.equal(1)
239 expect(res.body.data).to.be.an('array')
240 expect(res.body.data.length).to.equal(1)
241
242 const video = res.body.data[0]
243 expect(video.name).to.equal('my super name')
244 expect(video.category).to.equal(2)
245 expect(video.categoryLabel).to.equal('Films')
246 expect(video.licence).to.equal(6)
247 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
248 expect(video.language).to.equal(3)
249 expect(video.languageLabel).to.equal('Mandarin')
250 expect(video.nsfw).to.be.ok
251 expect(video.description).to.equal('my super description')
252 expect(video.podHost).to.equal('localhost:9001')
253 expect(video.author).to.equal('root')
254 expect(video.isLocal).to.be.true
255 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
256 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
257 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
258
259 expect(video.files).to.have.lengthOf(1)
260
261 const file = video.files[0]
262 const magnetUri = file.magnetUri
263 expect(file.magnetUri).to.exist
264 expect(file.resolution).to.equal(0)
265 expect(file.resolutionLabel).to.equal('original')
266 expect(file.size).to.equal(218910)
267
268 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
269 if (err) throw err
270 expect(test).to.equal(true)
271
272 done()
273 })
274 })
275 })
276
277 // Not implemented yet
278 // it('Should search the video by podHost', function (done) {
279 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
280 // if (err) throw err
281
282 // expect(res.body.total).to.equal(1)
283 // expect(res.body.data).to.be.an('array')
284 // expect(res.body.data.length).to.equal(1)
285
286 // const video = res.body.data[0]
287 // expect(video.name).to.equal('my super name')
288 // expect(video.description).to.equal('my super description')
289 // expect(video.podHost).to.equal('localhost:9001')
290 // expect(video.author).to.equal('root')
291 // expect(video.isLocal).to.be.true
292 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
293 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
294 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
295
296 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
297 // if (err) throw err
298 // expect(test).to.equal(true)
299
300 // done()
301 // })
302 // })
303 // })
304
305 it('Should search the video by tag', function (done) {
306 videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
307 if (err) throw err
308
309 expect(res.body.total).to.equal(1)
310 expect(res.body.data).to.be.an('array')
311 expect(res.body.data.length).to.equal(1)
312
313 const video = res.body.data[0]
314 expect(video.name).to.equal('my super name')
315 expect(video.category).to.equal(2)
316 expect(video.categoryLabel).to.equal('Films')
317 expect(video.licence).to.equal(6)
318 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
319 expect(video.language).to.equal(3)
320 expect(video.languageLabel).to.equal('Mandarin')
321 expect(video.nsfw).to.be.ok
322 expect(video.description).to.equal('my super description')
323 expect(video.podHost).to.equal('localhost:9001')
324 expect(video.author).to.equal('root')
325 expect(video.isLocal).to.be.true
326 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
327 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
328 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
329
330 expect(video.files).to.have.lengthOf(1)
331
332 const file = video.files[0]
333 const magnetUri = file.magnetUri
334 expect(file.magnetUri).to.exist
335 expect(file.resolution).to.equal(0)
336 expect(file.resolutionLabel).to.equal('original')
337 expect(file.size).to.equal(218910)
338
339 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
340 if (err) throw err
341 expect(test).to.equal(true)
342
343 done()
344 })
345 })
346 })
347
348 it('Should not find a search by name by default', function (done) {
349 videosUtils.searchVideo(server.url, 'hello', function (err, res) {
350 if (err) throw err
351
352 expect(res.body.total).to.equal(0)
353 expect(res.body.data).to.be.an('array')
354 expect(res.body.data.length).to.equal(0)
355
356 done()
357 })
358 })
359
360 it('Should not find a search by author', function (done) {
361 videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) {
362 if (err) throw err
363
364 expect(res.body.total).to.equal(0)
365 expect(res.body.data).to.be.an('array')
366 expect(res.body.data.length).to.equal(0)
367
368 done()
369 })
370 })
371
372 it('Should not find a search by tag', function (done) {
373 videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) {
374 if (err) throw err
375
376 expect(res.body.total).to.equal(0)
377 expect(res.body.data).to.be.an('array')
378 expect(res.body.data.length).to.equal(0)
379
380 done()
381 })
382 })
383
384 it('Should remove the video', function (done) {
385 videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
386 if (err) throw err
387
388 fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) {
389 if (err) throw err
390
391 expect(files.length).to.equal(0)
392
393 fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) {
394 if (err) throw err
395
396 expect(files.length).to.equal(0)
397
398 done()
399 })
400 })
401 })
402 })
403
404 it('Should not have videos', function (done) {
405 videosUtils.getVideosList(server.url, function (err, res) {
406 if (err) throw err
407
408 expect(res.body.total).to.equal(0)
409 expect(res.body.data).to.be.an('array')
410 expect(res.body.data.length).to.equal(0)
411
412 done()
413 })
414 })
415
416 it('Should upload 6 videos', function (done) {
417 this.timeout(25000)
418 const videos = [
419 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
420 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
421 ]
422 each(videos, function (video, callbackEach) {
423 const videoAttributes = {
424 name: video + ' name',
425 description: video + ' description',
426 category: 2,
427 licence: 1,
428 language: 1,
429 nsfw: true,
430 tags: [ 'tag1', 'tag2', 'tag3' ],
431 fixture: video
432 }
433
434 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach)
435 }, done)
436 })
437
438 it('Should have the correct durations', function (done) {
439 videosUtils.getVideosList(server.url, function (err, res) {
440 if (err) throw err
441
442 expect(res.body.total).to.equal(6)
443 const videos = res.body.data
444 expect(videos).to.be.an('array')
445 expect(videos.length).to.equal(6)
446
447 const videosByName = keyBy(videos, 'name')
448 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
449 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
450 expect(videosByName['video_short.webm name'].duration).to.equal(5)
451 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
452 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
453 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
454
455 done()
456 })
457 })
458
459 it('Should have the correct thumbnails', function (done) {
460 videosUtils.getVideosList(server.url, function (err, res) {
461 if (err) throw err
462
463 const videos = res.body.data
464 // For the next test
465 videosListBase = videos
466
467 each(videos, function (video, callbackEach) {
468 if (err) throw err
469 const videoName = video.name.replace(' name', '')
470
471 videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) {
472 if (err) throw err
473
474 expect(test).to.equal(true)
475 callbackEach()
476 })
477 }, done)
478 })
479 })
480
481 it('Should list only the two first videos', function (done) {
482 videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) {
483 if (err) throw err
484
485 const videos = res.body.data
486 expect(res.body.total).to.equal(6)
487 expect(videos.length).to.equal(2)
488 expect(videos[0].name).to.equal(videosListBase[0].name)
489 expect(videos[1].name).to.equal(videosListBase[1].name)
490
491 done()
492 })
493 })
494
495 it('Should list only the next three videos', function (done) {
496 videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) {
497 if (err) throw err
498
499 const videos = res.body.data
500 expect(res.body.total).to.equal(6)
501 expect(videos.length).to.equal(3)
502 expect(videos[0].name).to.equal(videosListBase[2].name)
503 expect(videos[1].name).to.equal(videosListBase[3].name)
504 expect(videos[2].name).to.equal(videosListBase[4].name)
505
506 done()
507 })
508 })
509
510 it('Should list the last video', function (done) {
511 videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) {
512 if (err) throw err
513
514 const videos = res.body.data
515 expect(res.body.total).to.equal(6)
516 expect(videos.length).to.equal(1)
517 expect(videos[0].name).to.equal(videosListBase[5].name)
518
519 done()
520 })
521 })
522
523 it('Should search the first video', function (done) {
524 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) {
525 if (err) throw err
526
527 const videos = res.body.data
528 expect(res.body.total).to.equal(4)
529 expect(videos.length).to.equal(1)
530 expect(videos[0].name).to.equal('video_short1.webm name')
531
532 done()
533 })
534 })
535
536 it('Should search the last two videos', function (done) {
537 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) {
538 if (err) throw err
539
540 const videos = res.body.data
541 expect(res.body.total).to.equal(4)
542 expect(videos.length).to.equal(2)
543 expect(videos[0].name).to.equal('video_short3.webm name')
544 expect(videos[1].name).to.equal('video_short.webm name')
545
546 done()
547 })
548 })
549
550 it('Should search all the webm videos', function (done) {
551 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
552 if (err) throw err
553
554 const videos = res.body.data
555 expect(res.body.total).to.equal(4)
556 expect(videos.length).to.equal(4)
557
558 done()
559 })
560 })
561
562 it('Should search all the root author videos', function (done) {
563 videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
564 if (err) throw err
565
566 const videos = res.body.data
567 expect(res.body.total).to.equal(6)
568 expect(videos.length).to.equal(6)
569
570 done()
571 })
572 })
573
574 // Not implemented yet
575 // it('Should search all the 9001 port videos', function (done) {
576 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
577 // if (err) throw err
578
579 // const videos = res.body.data
580 // expect(res.body.total).to.equal(6)
581 // expect(videos.length).to.equal(6)
582
583 // done()
584 // })
585 // })
586
587 // it('Should search all the localhost videos', function (done) {
588 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
589 // if (err) throw err
590
591 // const videos = res.body.data
592 // expect(res.body.total).to.equal(6)
593 // expect(videos.length).to.equal(6)
594
595 // done()
596 // })
597 // })
598
599 it('Should search the right magnetUri video', function (done) {
600 const video = videosListBase[0]
601 videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.files[0].magnetUri), 'magnetUri', 0, 15, function (err, res) {
602 if (err) throw err
603
604 const videos = res.body.data
605 expect(res.body.total).to.equal(1)
606 expect(videos.length).to.equal(1)
607 expect(videos[0].name).to.equal(video.name)
608
609 done()
610 })
611 })
612
613 it('Should list and sort by name in descending order', function (done) {
614 videosUtils.getVideosListSort(server.url, '-name', function (err, res) {
615 if (err) throw err
616
617 const videos = res.body.data
618 expect(res.body.total).to.equal(6)
619 expect(videos.length).to.equal(6)
620 expect(videos[0].name).to.equal('video_short.webm name')
621 expect(videos[1].name).to.equal('video_short.ogv name')
622 expect(videos[2].name).to.equal('video_short.mp4 name')
623 expect(videos[3].name).to.equal('video_short3.webm name')
624 expect(videos[4].name).to.equal('video_short2.webm name')
625 expect(videos[5].name).to.equal('video_short1.webm name')
626
627 done()
628 })
629 })
630
631 it('Should search and sort by name in ascending order', function (done) {
632 videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
633 if (err) throw err
634
635 const videos = res.body.data
636 expect(res.body.total).to.equal(4)
637 expect(videos.length).to.equal(4)
638
639 expect(videos[0].name).to.equal('video_short1.webm name')
640 expect(videos[1].name).to.equal('video_short2.webm name')
641 expect(videos[2].name).to.equal('video_short3.webm name')
642 expect(videos[3].name).to.equal('video_short.webm name')
643
644 videoId = videos[2].id
645
646 done()
647 })
648 })
649
650 it('Should update a video', function (done) {
651 const attributes = {
652 name: 'my super video updated',
653 category: 4,
654 licence: 2,
655 language: 5,
656 nsfw: false,
657 description: 'my super description updated',
658 tags: [ 'tagup1', 'tagup2' ]
659 }
660 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done)
661 })
662
663 it('Should have the video updated', function (done) {
664 this.timeout(60000)
665
666 videosUtils.getVideo(server.url, videoId, function (err, res) {
667 if (err) throw err
668
669 const video = res.body
670
671 expect(video.name).to.equal('my super video updated')
672 expect(video.category).to.equal(4)
673 expect(video.categoryLabel).to.equal('Art')
674 expect(video.licence).to.equal(2)
675 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
676 expect(video.language).to.equal(5)
677 expect(video.languageLabel).to.equal('Arabic')
678 expect(video.nsfw).to.be.ok
679 expect(video.description).to.equal('my super description updated')
680 expect(video.podHost).to.equal('localhost:9001')
681 expect(video.author).to.equal('root')
682 expect(video.isLocal).to.be.true
683 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
684 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
685 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
686
687 expect(video.files).to.have.lengthOf(1)
688
689 const file = video.files[0]
690 const magnetUri = file.magnetUri
691 expect(file.magnetUri).to.exist
692 expect(file.resolution).to.equal(0)
693 expect(file.resolutionLabel).to.equal('original')
694 expect(file.size).to.equal(292677)
695
696 videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
697 if (err) throw err
698 expect(test).to.equal(true)
699
700 webtorrent.add(magnetUri, function (torrent) {
701 expect(torrent.files).to.exist
702 expect(torrent.files.length).to.equal(1)
703 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
704
705 done()
706 })
707 })
708 })
709 })
710
711 it('Should update only the tags of a video', function (done) {
712 const attributes = {
713 tags: [ 'tag1', 'tag2', 'supertag' ]
714 }
715
716 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
717 if (err) throw err
718
719 videosUtils.getVideo(server.url, videoId, function (err, res) {
720 if (err) throw err
721
722 const video = res.body
723
724 expect(video.name).to.equal('my super video updated')
725 expect(video.category).to.equal(4)
726 expect(video.categoryLabel).to.equal('Art')
727 expect(video.licence).to.equal(2)
728 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
729 expect(video.language).to.equal(5)
730 expect(video.languageLabel).to.equal('Arabic')
731 expect(video.nsfw).to.be.ok
732 expect(video.description).to.equal('my super description updated')
733 expect(video.podHost).to.equal('localhost:9001')
734 expect(video.author).to.equal('root')
735 expect(video.isLocal).to.be.true
736 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
737 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
738 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
739
740 expect(video.files).to.have.lengthOf(1)
741
742 const file = video.files[0]
743 const magnetUri = file.magnetUri
744 expect(file.magnetUri).to.exist
745 expect(file.resolution).to.equal(0)
746 expect(file.resolutionLabel).to.equal('original')
747 expect(file.size).to.equal(292677)
748
749 done()
750 })
751 })
752 })
753
754 it('Should update only the description of a video', function (done) {
755 const attributes = {
756 description: 'hello everybody'
757 }
758
759 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
760 if (err) throw err
761
762 videosUtils.getVideo(server.url, videoId, function (err, res) {
763 if (err) throw err
764
765 const video = res.body
766
767 expect(video.name).to.equal('my super video updated')
768 expect(video.category).to.equal(4)
769 expect(video.categoryLabel).to.equal('Art')
770 expect(video.licence).to.equal(2)
771 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
772 expect(video.language).to.equal(5)
773 expect(video.languageLabel).to.equal('Arabic')
774 expect(video.nsfw).to.be.ok
775 expect(video.description).to.equal('hello everybody')
776 expect(video.podHost).to.equal('localhost:9001')
777 expect(video.author).to.equal('root')
778 expect(video.isLocal).to.be.true
779 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
780 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
781 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
782
783 expect(video.files).to.have.lengthOf(1)
784
785 const file = video.files[0]
786 const magnetUri = file.magnetUri
787 expect(file.magnetUri).to.exist
788 expect(file.resolution).to.equal(0)
789 expect(file.resolutionLabel).to.equal('original')
790 expect(file.size).to.equal(292677)
791
792 done()
793 })
794 })
795 })
796
797 it('Should like a video', function (done) {
798 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) {
799 if (err) throw err
800
801 videosUtils.getVideo(server.url, videoId, function (err, res) {
802 if (err) throw err
803
804 const video = res.body
805
806 expect(video.likes).to.equal(1)
807 expect(video.dislikes).to.equal(0)
808
809 done()
810 })
811 })
812 })
813
814 it('Should dislike the same video', function (done) {
815 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) {
816 if (err) throw err
817
818 videosUtils.getVideo(server.url, videoId, function (err, res) {
819 if (err) throw err
820
821 const video = res.body
822
823 expect(video.likes).to.equal(0)
824 expect(video.dislikes).to.equal(1)
825
826 done()
827 })
828 })
829 })
830
831 after(function (done) {
832 process.kill(-server.app.pid)
833
834 // Keep the logs if the test failed
835 if (this.ok) {
836 serversUtils.flushTests(done)
837 } else {
838 done()
839 }
840 })
841})