]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/single-pod.js
0dac9a1833a036f471e3f0ef78fc97fa9727c6bf
[github/Chocobozzz/PeerTube.git] / server / tests / api / single-pod.js
1 /* eslint-disable no-unused-expressions */
2
3 'use strict'
4
5 const chai = require('chai')
6 const each = require('async/each')
7 const expect = chai.expect
8 const fs = require('fs')
9 const keyBy = require('lodash/keyBy')
10 const pathUtils = require('path')
11 const series = require('async/series')
12 const webtorrent = new (require('webtorrent'))()
13
14 const loginUtils = require('../utils/login')
15 const miscsUtils = require('../utils/miscs')
16 const serversUtils = require('../utils/servers')
17 const videosUtils = require('../utils/videos')
18
19 describe('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.truthy
130 expect(video.description).to.equal('my super description')
131 expect(video.podHost).to.equal('localhost:9001')
132 expect(video.magnetUri).to.exist
133 expect(video.author).to.equal('root')
134 expect(video.isLocal).to.be.true
135 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
136 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
137 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
138
139 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
140 if (err) throw err
141 expect(test).to.equal(true)
142
143 videoId = video.id
144 videoUUID = video.uuid
145
146 webtorrent.add(video.magnetUri, function (torrent) {
147 expect(torrent.files).to.exist
148 expect(torrent.files.length).to.equal(1)
149 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
150
151 done()
152 })
153 })
154 })
155 })
156
157 it('Should get the video', function (done) {
158 // Yes, this could be long
159 this.timeout(60000)
160
161 videosUtils.getVideo(server.url, videoId, function (err, res) {
162 if (err) throw err
163
164 const video = res.body
165 expect(video.name).to.equal('my super name')
166 expect(video.category).to.equal(2)
167 expect(video.categoryLabel).to.equal('Films')
168 expect(video.licence).to.equal(6)
169 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
170 expect(video.language).to.equal(3)
171 expect(video.languageLabel).to.equal('Mandarin')
172 expect(video.nsfw).to.be.truthy
173 expect(video.description).to.equal('my super description')
174 expect(video.podHost).to.equal('localhost:9001')
175 expect(video.magnetUri).to.exist
176 expect(video.author).to.equal('root')
177 expect(video.isLocal).to.be.true
178 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
179 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
180 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
181
182 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
183 if (err) throw err
184 expect(test).to.equal(true)
185
186 // Wait the async views increment
187 setTimeout(done, 500)
188 })
189 })
190 })
191
192 it('Should get the video by UUID', function (done) {
193 // Yes, this could be long
194 this.timeout(60000)
195
196 videosUtils.getVideo(server.url, videoUUID, function (err, res) {
197 if (err) throw err
198
199 const video = res.body
200 expect(video.name).to.equal('my super name')
201
202 // Wait the async views increment
203 setTimeout(done, 500)
204 })
205 })
206
207 it('Should have the views updated', function (done) {
208 videosUtils.getVideo(server.url, videoId, function (err, res) {
209 if (err) throw err
210
211 const video = res.body
212 expect(video.views).to.equal(2)
213
214 done()
215 })
216 })
217
218 it('Should search the video by name by default', function (done) {
219 videosUtils.searchVideo(server.url, 'my', function (err, res) {
220 if (err) throw err
221
222 expect(res.body.total).to.equal(1)
223 expect(res.body.data).to.be.an('array')
224 expect(res.body.data.length).to.equal(1)
225
226 const video = res.body.data[0]
227 expect(video.name).to.equal('my super name')
228 expect(video.category).to.equal(2)
229 expect(video.categoryLabel).to.equal('Films')
230 expect(video.licence).to.equal(6)
231 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
232 expect(video.language).to.equal(3)
233 expect(video.languageLabel).to.equal('Mandarin')
234 expect(video.nsfw).to.be.truthy
235 expect(video.description).to.equal('my super description')
236 expect(video.podHost).to.equal('localhost:9001')
237 expect(video.author).to.equal('root')
238 expect(video.isLocal).to.be.true
239 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
240 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
241 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
242
243 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
244 if (err) throw err
245 expect(test).to.equal(true)
246
247 done()
248 })
249 })
250 })
251
252 // Not implemented yet
253 // it('Should search the video by podHost', function (done) {
254 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
255 // if (err) throw err
256
257 // expect(res.body.total).to.equal(1)
258 // expect(res.body.data).to.be.an('array')
259 // expect(res.body.data.length).to.equal(1)
260
261 // const video = res.body.data[0]
262 // expect(video.name).to.equal('my super name')
263 // expect(video.description).to.equal('my super description')
264 // expect(video.podHost).to.equal('localhost:9001')
265 // expect(video.author).to.equal('root')
266 // expect(video.isLocal).to.be.true
267 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
268 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
269 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
270
271 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
272 // if (err) throw err
273 // expect(test).to.equal(true)
274
275 // done()
276 // })
277 // })
278 // })
279
280 it('Should search the video by tag', function (done) {
281 videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
282 if (err) throw err
283
284 expect(res.body.total).to.equal(1)
285 expect(res.body.data).to.be.an('array')
286 expect(res.body.data.length).to.equal(1)
287
288 const video = res.body.data[0]
289 expect(video.name).to.equal('my super name')
290 expect(video.category).to.equal(2)
291 expect(video.categoryLabel).to.equal('Films')
292 expect(video.licence).to.equal(6)
293 expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
294 expect(video.language).to.equal(3)
295 expect(video.languageLabel).to.equal('Mandarin')
296 expect(video.nsfw).to.be.truthy
297 expect(video.description).to.equal('my super description')
298 expect(video.podHost).to.equal('localhost:9001')
299 expect(video.author).to.equal('root')
300 expect(video.isLocal).to.be.true
301 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
302 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
303 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
304
305 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
306 if (err) throw err
307 expect(test).to.equal(true)
308
309 done()
310 })
311 })
312 })
313
314 it('Should not find a search by name by default', function (done) {
315 videosUtils.searchVideo(server.url, 'hello', function (err, res) {
316 if (err) throw err
317
318 expect(res.body.total).to.equal(0)
319 expect(res.body.data).to.be.an('array')
320 expect(res.body.data.length).to.equal(0)
321
322 done()
323 })
324 })
325
326 it('Should not find a search by author', function (done) {
327 videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) {
328 if (err) throw err
329
330 expect(res.body.total).to.equal(0)
331 expect(res.body.data).to.be.an('array')
332 expect(res.body.data.length).to.equal(0)
333
334 done()
335 })
336 })
337
338 it('Should not find a search by tag', function (done) {
339 videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) {
340 if (err) throw err
341
342 expect(res.body.total).to.equal(0)
343 expect(res.body.data).to.be.an('array')
344 expect(res.body.data.length).to.equal(0)
345
346 done()
347 })
348 })
349
350 it('Should remove the video', function (done) {
351 videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
352 if (err) throw err
353
354 fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) {
355 if (err) throw err
356
357 expect(files.length).to.equal(0)
358
359 fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) {
360 if (err) throw err
361
362 expect(files.length).to.equal(0)
363
364 done()
365 })
366 })
367 })
368 })
369
370 it('Should not have videos', function (done) {
371 videosUtils.getVideosList(server.url, function (err, res) {
372 if (err) throw err
373
374 expect(res.body.total).to.equal(0)
375 expect(res.body.data).to.be.an('array')
376 expect(res.body.data.length).to.equal(0)
377
378 done()
379 })
380 })
381
382 it('Should upload 6 videos', function (done) {
383 this.timeout(25000)
384 const videos = [
385 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
386 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
387 ]
388 each(videos, function (video, callbackEach) {
389 const videoAttributes = {
390 name: video + ' name',
391 description: video + ' description',
392 category: 2,
393 licence: 1,
394 language: 1,
395 nsfw: true,
396 tags: [ 'tag1', 'tag2', 'tag3' ],
397 fixture: video
398 }
399
400 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach)
401 }, done)
402 })
403
404 it('Should have the correct durations', function (done) {
405 videosUtils.getVideosList(server.url, function (err, res) {
406 if (err) throw err
407
408 expect(res.body.total).to.equal(6)
409 const videos = res.body.data
410 expect(videos).to.be.an('array')
411 expect(videos.length).to.equal(6)
412
413 const videosByName = keyBy(videos, 'name')
414 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
415 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
416 expect(videosByName['video_short.webm name'].duration).to.equal(5)
417 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
418 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
419 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
420
421 done()
422 })
423 })
424
425 it('Should have the correct thumbnails', function (done) {
426 videosUtils.getVideosList(server.url, function (err, res) {
427 if (err) throw err
428
429 const videos = res.body.data
430 // For the next test
431 videosListBase = videos
432
433 each(videos, function (video, callbackEach) {
434 if (err) throw err
435 const videoName = video.name.replace(' name', '')
436
437 videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) {
438 if (err) throw err
439
440 expect(test).to.equal(true)
441 callbackEach()
442 })
443 }, done)
444 })
445 })
446
447 it('Should list only the two first videos', function (done) {
448 videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) {
449 if (err) throw err
450
451 const videos = res.body.data
452 expect(res.body.total).to.equal(6)
453 expect(videos.length).to.equal(2)
454 expect(videos[0].name).to.equal(videosListBase[0].name)
455 expect(videos[1].name).to.equal(videosListBase[1].name)
456
457 done()
458 })
459 })
460
461 it('Should list only the next three videos', function (done) {
462 videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) {
463 if (err) throw err
464
465 const videos = res.body.data
466 expect(res.body.total).to.equal(6)
467 expect(videos.length).to.equal(3)
468 expect(videos[0].name).to.equal(videosListBase[2].name)
469 expect(videos[1].name).to.equal(videosListBase[3].name)
470 expect(videos[2].name).to.equal(videosListBase[4].name)
471
472 done()
473 })
474 })
475
476 it('Should list the last video', function (done) {
477 videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) {
478 if (err) throw err
479
480 const videos = res.body.data
481 expect(res.body.total).to.equal(6)
482 expect(videos.length).to.equal(1)
483 expect(videos[0].name).to.equal(videosListBase[5].name)
484
485 done()
486 })
487 })
488
489 it('Should search the first video', function (done) {
490 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) {
491 if (err) throw err
492
493 const videos = res.body.data
494 expect(res.body.total).to.equal(4)
495 expect(videos.length).to.equal(1)
496 expect(videos[0].name).to.equal('video_short1.webm name')
497
498 done()
499 })
500 })
501
502 it('Should search the last two videos', function (done) {
503 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) {
504 if (err) throw err
505
506 const videos = res.body.data
507 expect(res.body.total).to.equal(4)
508 expect(videos.length).to.equal(2)
509 expect(videos[0].name).to.equal('video_short3.webm name')
510 expect(videos[1].name).to.equal('video_short.webm name')
511
512 done()
513 })
514 })
515
516 it('Should search all the webm videos', function (done) {
517 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
518 if (err) throw err
519
520 const videos = res.body.data
521 expect(res.body.total).to.equal(4)
522 expect(videos.length).to.equal(4)
523
524 done()
525 })
526 })
527
528 it('Should search all the root author videos', function (done) {
529 videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
530 if (err) throw err
531
532 const videos = res.body.data
533 expect(res.body.total).to.equal(6)
534 expect(videos.length).to.equal(6)
535
536 done()
537 })
538 })
539
540 // Not implemented yet
541 // it('Should search all the 9001 port videos', function (done) {
542 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
543 // if (err) throw err
544
545 // const videos = res.body.data
546 // expect(res.body.total).to.equal(6)
547 // expect(videos.length).to.equal(6)
548
549 // done()
550 // })
551 // })
552
553 // it('Should search all the localhost videos', function (done) {
554 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
555 // if (err) throw err
556
557 // const videos = res.body.data
558 // expect(res.body.total).to.equal(6)
559 // expect(videos.length).to.equal(6)
560
561 // done()
562 // })
563 // })
564
565 it('Should search the right magnetUri video', function (done) {
566 const video = videosListBase[0]
567 videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
568 if (err) throw err
569
570 const videos = res.body.data
571 expect(res.body.total).to.equal(1)
572 expect(videos.length).to.equal(1)
573 expect(videos[0].name).to.equal(video.name)
574
575 done()
576 })
577 })
578
579 it('Should list and sort by name in descending order', function (done) {
580 videosUtils.getVideosListSort(server.url, '-name', function (err, res) {
581 if (err) throw err
582
583 const videos = res.body.data
584 expect(res.body.total).to.equal(6)
585 expect(videos.length).to.equal(6)
586 expect(videos[0].name).to.equal('video_short.webm name')
587 expect(videos[1].name).to.equal('video_short.ogv name')
588 expect(videos[2].name).to.equal('video_short.mp4 name')
589 expect(videos[3].name).to.equal('video_short3.webm name')
590 expect(videos[4].name).to.equal('video_short2.webm name')
591 expect(videos[5].name).to.equal('video_short1.webm name')
592
593 done()
594 })
595 })
596
597 it('Should search and sort by name in ascending order', function (done) {
598 videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
599 if (err) throw err
600
601 const videos = res.body.data
602 expect(res.body.total).to.equal(4)
603 expect(videos.length).to.equal(4)
604
605 expect(videos[0].name).to.equal('video_short1.webm name')
606 expect(videos[1].name).to.equal('video_short2.webm name')
607 expect(videos[2].name).to.equal('video_short3.webm name')
608 expect(videos[3].name).to.equal('video_short.webm name')
609
610 videoId = videos[2].id
611
612 done()
613 })
614 })
615
616 it('Should update a video', function (done) {
617 const attributes = {
618 name: 'my super video updated',
619 category: 4,
620 licence: 2,
621 language: 5,
622 nsfw: false,
623 description: 'my super description updated',
624 tags: [ 'tagup1', 'tagup2' ]
625 }
626 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done)
627 })
628
629 it('Should have the video updated', function (done) {
630 this.timeout(60000)
631
632 videosUtils.getVideo(server.url, videoId, function (err, res) {
633 if (err) throw err
634
635 const video = res.body
636
637 expect(video.name).to.equal('my super video updated')
638 expect(video.category).to.equal(4)
639 expect(video.categoryLabel).to.equal('Art')
640 expect(video.licence).to.equal(2)
641 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
642 expect(video.language).to.equal(5)
643 expect(video.languageLabel).to.equal('Arabic')
644 expect(video.nsfw).to.be.truthy
645 expect(video.description).to.equal('my super description updated')
646 expect(video.podHost).to.equal('localhost:9001')
647 expect(video.author).to.equal('root')
648 expect(video.isLocal).to.be.true
649 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
650 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
651 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
652
653 videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
654 if (err) throw err
655 expect(test).to.equal(true)
656
657 webtorrent.add(video.magnetUri, function (torrent) {
658 expect(torrent.files).to.exist
659 expect(torrent.files.length).to.equal(1)
660 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
661
662 done()
663 })
664 })
665 })
666 })
667
668 it('Should update only the tags of a video', function (done) {
669 const attributes = {
670 tags: [ 'tag1', 'tag2', 'supertag' ]
671 }
672
673 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
674 if (err) throw err
675
676 videosUtils.getVideo(server.url, videoId, function (err, res) {
677 if (err) throw err
678
679 const video = res.body
680
681 expect(video.name).to.equal('my super video updated')
682 expect(video.category).to.equal(4)
683 expect(video.categoryLabel).to.equal('Art')
684 expect(video.licence).to.equal(2)
685 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
686 expect(video.language).to.equal(5)
687 expect(video.languageLabel).to.equal('Arabic')
688 expect(video.nsfw).to.be.truthy
689 expect(video.description).to.equal('my super description updated')
690 expect(video.podHost).to.equal('localhost:9001')
691 expect(video.author).to.equal('root')
692 expect(video.isLocal).to.be.true
693 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
694 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
695 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
696
697 done()
698 })
699 })
700 })
701
702 it('Should update only the description of a video', function (done) {
703 const attributes = {
704 description: 'hello everybody'
705 }
706
707 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
708 if (err) throw err
709
710 videosUtils.getVideo(server.url, videoId, function (err, res) {
711 if (err) throw err
712
713 const video = res.body
714
715 expect(video.name).to.equal('my super video updated')
716 expect(video.category).to.equal(4)
717 expect(video.categoryLabel).to.equal('Art')
718 expect(video.licence).to.equal(2)
719 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
720 expect(video.language).to.equal(5)
721 expect(video.languageLabel).to.equal('Arabic')
722 expect(video.nsfw).to.be.truthy
723 expect(video.description).to.equal('hello everybody')
724 expect(video.podHost).to.equal('localhost:9001')
725 expect(video.author).to.equal('root')
726 expect(video.isLocal).to.be.true
727 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
728 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
729 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
730
731 done()
732 })
733 })
734 })
735
736 it('Should like a video', function (done) {
737 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) {
738 if (err) throw err
739
740 videosUtils.getVideo(server.url, videoId, function (err, res) {
741 if (err) throw err
742
743 const video = res.body
744
745 expect(video.likes).to.equal(1)
746 expect(video.dislikes).to.equal(0)
747
748 done()
749 })
750 })
751 })
752
753 it('Should dislike the same video', function (done) {
754 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) {
755 if (err) throw err
756
757 videosUtils.getVideo(server.url, videoId, function (err, res) {
758 if (err) throw err
759
760 const video = res.body
761
762 expect(video.likes).to.equal(0)
763 expect(video.dislikes).to.equal(1)
764
765 done()
766 })
767 })
768 })
769
770 after(function (done) {
771 process.kill(-server.app.pid)
772
773 // Keep the logs if the test failed
774 if (this.ok) {
775 serversUtils.flushTests(done)
776 } else {
777 done()
778 }
779 })
780 })