Merge branch 'feature/design' into develop
[oweals/peertube.git] / server / tests / api / single-server.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import { keyBy } from 'lodash'
5 import 'mocha'
6 import { join } from 'path'
7 import {
8   dateIsValid,
9   flushTests,
10   getVideo,
11   getVideoCategories,
12   getVideoLanguages,
13   getVideoLicences,
14   getVideoPrivacies,
15   getVideosList,
16   getVideosListPagination,
17   getVideosListSort,
18   killallServers,
19   rateVideo,
20   readdirPromise,
21   removeVideo,
22   runServer,
23   searchVideo,
24   searchVideoWithPagination,
25   searchVideoWithSort,
26   ServerInfo,
27   setAccessTokensToServers,
28   testVideoImage,
29   updateVideo,
30   uploadVideo,
31   wait,
32   webtorrentAdd
33 } from '../utils'
34 import { viewVideo } from '../utils/videos'
35
36 const expect = chai.expect
37
38 describe('Test a single server', function () {
39   let server: ServerInfo = null
40   let videoId = -1
41   let videoUUID = ''
42   let videosListBase: any[] = null
43
44   before(async function () {
45     this.timeout(10000)
46
47     await flushTests()
48
49     server = await runServer(1)
50
51     await setAccessTokensToServers([ server ])
52   })
53
54   it('Should list video categories', async function () {
55     const res = await getVideoCategories(server.url)
56
57     const categories = res.body
58     expect(Object.keys(categories)).to.have.length.above(10)
59
60     expect(categories[11]).to.equal('News')
61   })
62
63   it('Should list video licences', async function () {
64     const res = await getVideoLicences(server.url)
65
66     const licences = res.body
67     expect(Object.keys(licences)).to.have.length.above(5)
68
69     expect(licences[3]).to.equal('Attribution - No Derivatives')
70   })
71
72   it('Should list video languages', async function () {
73     const res = await getVideoLanguages(server.url)
74
75     const languages = res.body
76     expect(Object.keys(languages)).to.have.length.above(5)
77
78     expect(languages[3]).to.equal('Mandarin')
79   })
80
81   it('Should list video privacies', async function () {
82     const res = await getVideoPrivacies(server.url)
83
84     const privacies = res.body
85     expect(Object.keys(privacies)).to.have.length.at.least(3)
86
87     expect(privacies[3]).to.equal('Private')
88   })
89
90   it('Should not have videos', async function () {
91     const res = await getVideosList(server.url)
92
93     expect(res.body.total).to.equal(0)
94     expect(res.body.data).to.be.an('array')
95     expect(res.body.data.length).to.equal(0)
96   })
97
98   it('Should upload the video', async function () {
99     const videoAttributes = {
100       name: 'my super name',
101       category: 2,
102       nsfw: true,
103       licence: 6,
104       tags: [ 'tag1', 'tag2', 'tag3' ]
105     }
106     const res = await uploadVideo(server.url, server.accessToken, videoAttributes)
107     expect(res.body.video).to.not.be.undefined
108     expect(res.body.video.id).to.equal(1)
109     expect(res.body.video.uuid).to.have.length.above(5)
110   })
111
112   it('Should seed the uploaded video', async function () {
113     // Yes, this could be long
114     this.timeout(60000)
115
116     const res = await getVideosList(server.url)
117
118     expect(res.body.total).to.equal(1)
119     expect(res.body.data).to.be.an('array')
120     expect(res.body.data.length).to.equal(1)
121
122     const video = res.body.data[0]
123     expect(video.name).to.equal('my super name')
124     expect(video.category).to.equal(2)
125     expect(video.categoryLabel).to.equal('Films')
126     expect(video.licence).to.equal(6)
127     expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
128     expect(video.language).to.equal(3)
129     expect(video.languageLabel).to.equal('Mandarin')
130     expect(video.nsfw).to.be.ok
131     expect(video.description).to.equal('my super description')
132     expect(video.serverHost).to.equal('localhost:9001')
133     expect(video.accountName).to.equal('root')
134     expect(video.isLocal).to.be.true
135     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
136     expect(dateIsValid(video.createdAt)).to.be.true
137     expect(dateIsValid(video.updatedAt)).to.be.true
138
139     const res2 = await getVideo(server.url, res.body.data[0].id)
140     const videoDetails = res2.body
141
142     expect(videoDetails.files).to.have.lengthOf(1)
143
144     const file = videoDetails.files[0]
145     const magnetUri = file.magnetUri
146     expect(file.magnetUri).to.have.lengthOf.above(2)
147     expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
148     expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
149     expect(file.resolution).to.equal(720)
150     expect(file.resolutionLabel).to.equal('720p')
151     expect(file.size).to.equal(218910)
152
153     const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
154     expect(test).to.equal(true)
155
156     videoId = videoDetails.id
157     videoUUID = videoDetails.uuid
158
159     const torrent = await webtorrentAdd(magnetUri)
160     expect(torrent.files).to.be.an('array')
161     expect(torrent.files.length).to.equal(1)
162     expect(torrent.files[0].path).to.exist.and.to.not.equal('')
163   })
164
165   it('Should get the video', async function () {
166     // Yes, this could be long
167     this.timeout(60000)
168
169     const res = await getVideo(server.url, videoId)
170
171     const video = res.body
172     expect(video.name).to.equal('my super name')
173     expect(video.category).to.equal(2)
174     expect(video.categoryLabel).to.equal('Films')
175     expect(video.licence).to.equal(6)
176     expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
177     expect(video.language).to.equal(3)
178     expect(video.languageLabel).to.equal('Mandarin')
179     expect(video.nsfw).to.be.ok
180     expect(video.description).to.equal('my super description')
181     expect(video.serverHost).to.equal('localhost:9001')
182     expect(video.accountName).to.equal('root')
183     expect(video.isLocal).to.be.true
184     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
185     expect(dateIsValid(video.createdAt)).to.be.true
186     expect(dateIsValid(video.updatedAt)).to.be.true
187     expect(video.channel.name).to.equal('Default root channel')
188     expect(video.channel.isLocal).to.be.true
189     expect(dateIsValid(video.channel.createdAt)).to.be.true
190     expect(dateIsValid(video.channel.updatedAt)).to.be.true
191
192     expect(video.files).to.have.lengthOf(1)
193
194     const file = video.files[0]
195     expect(file.magnetUri).to.have.lengthOf.above(2)
196     expect(file.resolution).to.equal(720)
197     expect(file.resolutionLabel).to.equal('720p')
198     expect(file.size).to.equal(218910)
199
200     const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
201     expect(test).to.equal(true)
202
203     // Wait the async views increment
204     await wait(500)
205   })
206
207   it('Should get the video by UUID', async function () {
208     // Yes, this could be long
209     this.timeout(60000)
210
211     const res = await getVideo(server.url, videoUUID)
212
213     const video = res.body
214     expect(video.name).to.equal('my super name')
215
216     // Wait the async views increment
217     await wait(500)
218   })
219
220   it('Should have the views updated', async function () {
221     await viewVideo(server.url, videoId)
222     await viewVideo(server.url, videoId)
223     await viewVideo(server.url, videoId)
224
225     const res = await getVideo(server.url, videoId)
226
227     const video = res.body
228     expect(video.views).to.equal(3)
229   })
230
231   it('Should search the video by name', async function () {
232     const res = await searchVideo(server.url, 'my')
233
234     expect(res.body.total).to.equal(1)
235     expect(res.body.data).to.be.an('array')
236     expect(res.body.data.length).to.equal(1)
237
238     const video = res.body.data[0]
239     expect(video.name).to.equal('my super name')
240     expect(video.category).to.equal(2)
241     expect(video.categoryLabel).to.equal('Films')
242     expect(video.licence).to.equal(6)
243     expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
244     expect(video.language).to.equal(3)
245     expect(video.languageLabel).to.equal('Mandarin')
246     expect(video.nsfw).to.be.ok
247     expect(video.description).to.equal('my super description')
248     expect(video.serverHost).to.equal('localhost:9001')
249     expect(video.accountName).to.equal('root')
250     expect(video.isLocal).to.be.true
251     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
252     expect(dateIsValid(video.createdAt)).to.be.true
253     expect(dateIsValid(video.updatedAt)).to.be.true
254
255     const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
256     expect(test).to.equal(true)
257   })
258
259   // Not implemented yet
260   // it('Should search the video by serverHost', async function () {
261   //     const res = await   videosUtils.searchVideo(server.url, '9001', 'host')
262
263   //     expect(res.body.total).to.equal(1)
264   //     expect(res.body.data).to.be.an('array')
265   //     expect(res.body.data.length).to.equal(1)
266
267   //     const video = res.body.data[0]
268   //     expect(video.name).to.equal('my super name')
269   //     expect(video.description).to.equal('my super description')
270   //     expect(video.serverHost).to.equal('localhost:9001')
271   //     expect(video.author).to.equal('root')
272   //     expect(video.isLocal).to.be.true
273   //     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
274   //     expect(dateIsValid(video.createdAt)).to.be.true
275   //     expect(dateIsValid(video.updatedAt)).to.be.true
276
277   //     const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
278   //       expect(test).to.equal(true)
279
280   //       done()
281   //     })
282   //   })
283   // })
284
285   // Not implemented yet
286   // it('Should search the video by tag', async function () {
287   //   const res = await searchVideo(server.url, 'tag1')
288   //
289   //   expect(res.body.total).to.equal(1)
290   //   expect(res.body.data).to.be.an('array')
291   //   expect(res.body.data.length).to.equal(1)
292   //
293   //   const video = res.body.data[0]
294   //   expect(video.name).to.equal('my super name')
295   //   expect(video.category).to.equal(2)
296   //   expect(video.categoryLabel).to.equal('Films')
297   //   expect(video.licence).to.equal(6)
298   //   expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
299   //   expect(video.language).to.equal(3)
300   //   expect(video.languageLabel).to.equal('Mandarin')
301   //   expect(video.nsfw).to.be.ok
302   //   expect(video.description).to.equal('my super description')
303   //   expect(video.serverHost).to.equal('localhost:9001')
304   //   expect(video.accountName).to.equal('root')
305   //   expect(video.isLocal).to.be.true
306   //   expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
307   //   expect(dateIsValid(video.createdAt)).to.be.true
308   //   expect(dateIsValid(video.updatedAt)).to.be.true
309   //
310   //   const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
311   //   expect(test).to.equal(true)
312   // })
313
314   it('Should not find a search by name', async function () {
315     const res = await searchVideo(server.url, 'hello')
316
317     expect(res.body.total).to.equal(0)
318     expect(res.body.data).to.be.an('array')
319     expect(res.body.data.length).to.equal(0)
320   })
321
322   // Not implemented yet
323   // it('Should not find a search by author', async function () {
324   //   const res = await searchVideo(server.url, 'hello')
325   //
326   //   expect(res.body.total).to.equal(0)
327   //   expect(res.body.data).to.be.an('array')
328   //   expect(res.body.data.length).to.equal(0)
329   // })
330   //
331   // Not implemented yet
332   // it('Should not find a search by tag', async function () {
333   //   const res = await searchVideo(server.url, 'hello')
334   //
335   //   expect(res.body.total).to.equal(0)
336   //   expect(res.body.data).to.be.an('array')
337   //   expect(res.body.data.length).to.equal(0)
338   // })
339
340   it('Should remove the video', async function () {
341     await removeVideo(server.url, server.accessToken, videoId)
342
343     const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
344     expect(files1).to.have.lengthOf(0)
345
346     const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
347     expect(files2).to.have.lengthOf(0)
348   })
349
350   it('Should not have videos', async function () {
351     const res = await getVideosList(server.url)
352
353     expect(res.body.total).to.equal(0)
354     expect(res.body.data).to.be.an('array')
355     expect(res.body.data).to.have.lengthOf(0)
356   })
357
358   it('Should upload 6 videos', async function () {
359     this.timeout(25000)
360
361     const videos = [
362       'video_short.mp4', 'video_short.ogv', 'video_short.webm',
363       'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
364     ]
365
366     const tasks: Promise<any>[] = []
367     for (const video of videos) {
368       const videoAttributes = {
369         name: video + ' name',
370         description: video + ' description',
371         category: 2,
372         licence: 1,
373         language: 1,
374         nsfw: true,
375         tags: [ 'tag1', 'tag2', 'tag3' ],
376         fixture: video
377       }
378
379       const p = uploadVideo(server.url, server.accessToken, videoAttributes)
380       tasks.push(p)
381     }
382
383     await Promise.all(tasks)
384   })
385
386   it('Should have the correct durations', async function () {
387     const res = await getVideosList(server.url)
388
389     expect(res.body.total).to.equal(6)
390     const videos = res.body.data
391     expect(videos).to.be.an('array')
392     expect(videos).to.have.lengthOf(6)
393
394     const videosByName = keyBy<{ duration: number }>(videos, 'name')
395     expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
396     expect(videosByName['video_short.ogv name'].duration).to.equal(5)
397     expect(videosByName['video_short.webm name'].duration).to.equal(5)
398     expect(videosByName['video_short1.webm name'].duration).to.equal(10)
399     expect(videosByName['video_short2.webm name'].duration).to.equal(5)
400     expect(videosByName['video_short3.webm name'].duration).to.equal(5)
401   })
402
403   it('Should have the correct thumbnails', async function () {
404     const res = await getVideosList(server.url)
405
406     const videos = res.body.data
407     // For the next test
408     videosListBase = videos
409
410     for (const video of videos) {
411       const videoName = video.name.replace(' name', '')
412       const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
413
414       expect(test).to.equal(true)
415     }
416   })
417
418   it('Should list only the two first videos', async function () {
419     const res = await getVideosListPagination(server.url, 0, 2, 'name')
420
421     const videos = res.body.data
422     expect(res.body.total).to.equal(6)
423     expect(videos.length).to.equal(2)
424     expect(videos[0].name).to.equal(videosListBase[0].name)
425     expect(videos[1].name).to.equal(videosListBase[1].name)
426   })
427
428   it('Should list only the next three videos', async function () {
429     const res = await getVideosListPagination(server.url, 2, 3, 'name')
430
431     const videos = res.body.data
432     expect(res.body.total).to.equal(6)
433     expect(videos.length).to.equal(3)
434     expect(videos[0].name).to.equal(videosListBase[2].name)
435     expect(videos[1].name).to.equal(videosListBase[3].name)
436     expect(videos[2].name).to.equal(videosListBase[4].name)
437   })
438
439   it('Should list the last video', async function () {
440     const res = await getVideosListPagination(server.url, 5, 6, 'name')
441
442     const videos = res.body.data
443     expect(res.body.total).to.equal(6)
444     expect(videos.length).to.equal(1)
445     expect(videos[0].name).to.equal(videosListBase[5].name)
446   })
447
448   it('Should search the first video', async function () {
449     const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
450
451     const videos = res.body.data
452     expect(res.body.total).to.equal(4)
453     expect(videos.length).to.equal(1)
454     expect(videos[0].name).to.equal('video_short1.webm name')
455   })
456
457   it('Should search the last two videos', async function () {
458     const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
459
460     const videos = res.body.data
461     expect(res.body.total).to.equal(4)
462     expect(videos.length).to.equal(2)
463     expect(videos[0].name).to.equal('video_short3.webm name')
464     expect(videos[1].name).to.equal('video_short.webm name')
465   })
466
467   it('Should search all the webm videos', async function () {
468     const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
469
470     const videos = res.body.data
471     expect(res.body.total).to.equal(4)
472     expect(videos.length).to.equal(4)
473   })
474
475   // Not implemented yet
476   // it('Should search all the root author videos', async function () {
477   //   const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
478   //
479   //   const videos = res.body.data
480   //   expect(res.body.total).to.equal(6)
481   //   expect(videos.length).to.equal(6)
482   // })
483
484   // Not implemented yet
485   // it('Should search all the 9001 port videos', async function () {
486   // const res = await   videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
487
488   //     const videos = res.body.data
489   //     expect(res.body.total).to.equal(6)
490   //     expect(videos.length).to.equal(6)
491
492   //     done()
493   //   })
494   // })
495
496   // it('Should search all the localhost videos', async function () {
497   // const res = await   videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
498
499   //     const videos = res.body.data
500   //     expect(res.body.total).to.equal(6)
501   //     expect(videos.length).to.equal(6)
502
503   //     done()
504   //   })
505   // })
506
507   it('Should list and sort by name in descending order', async function () {
508     const res = await getVideosListSort(server.url, '-name')
509
510     const videos = res.body.data
511     expect(res.body.total).to.equal(6)
512     expect(videos.length).to.equal(6)
513     expect(videos[0].name).to.equal('video_short.webm name')
514     expect(videos[1].name).to.equal('video_short.ogv name')
515     expect(videos[2].name).to.equal('video_short.mp4 name')
516     expect(videos[3].name).to.equal('video_short3.webm name')
517     expect(videos[4].name).to.equal('video_short2.webm name')
518     expect(videos[5].name).to.equal('video_short1.webm name')
519   })
520
521   it('Should search and sort by name in ascending order', async function () {
522     const res = await searchVideoWithSort(server.url, 'webm', 'name')
523
524     const videos = res.body.data
525     expect(res.body.total).to.equal(4)
526     expect(videos.length).to.equal(4)
527
528     expect(videos[0].name).to.equal('video_short1.webm name')
529     expect(videos[1].name).to.equal('video_short2.webm name')
530     expect(videos[2].name).to.equal('video_short3.webm name')
531     expect(videos[3].name).to.equal('video_short.webm name')
532
533     videoId = videos[2].id
534   })
535
536   it('Should update a video', async function () {
537     const attributes = {
538       name: 'my super video updated',
539       category: 4,
540       licence: 2,
541       language: 5,
542       nsfw: false,
543       description: 'my super description updated',
544       tags: [ 'tagup1', 'tagup2' ]
545     }
546     await updateVideo(server.url, server.accessToken, videoId, attributes)
547   })
548
549   it('Should have the video updated', async function () {
550     this.timeout(60000)
551
552     const res = await getVideo(server.url, videoId)
553
554     const video = res.body
555
556     expect(video.name).to.equal('my super video updated')
557     expect(video.category).to.equal(4)
558     expect(video.categoryLabel).to.equal('Art')
559     expect(video.licence).to.equal(2)
560     expect(video.licenceLabel).to.equal('Attribution - Share Alike')
561     expect(video.language).to.equal(5)
562     expect(video.languageLabel).to.equal('Arabic')
563     expect(video.nsfw).to.be.ok
564     expect(video.description).to.equal('my super description updated')
565     expect(video.serverHost).to.equal('localhost:9001')
566     expect(video.accountName).to.equal('root')
567     expect(video.account.name).to.equal('root')
568     expect(video.isLocal).to.be.true
569     expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
570     expect(dateIsValid(video.createdAt)).to.be.true
571     expect(dateIsValid(video.updatedAt)).to.be.true
572
573     expect(video.channel.name).to.equal('Default root channel')
574     expect(video.channel.isLocal).to.be.true
575     expect(dateIsValid(video.channel.createdAt)).to.be.true
576     expect(dateIsValid(video.channel.updatedAt)).to.be.true
577
578     expect(video.files).to.have.lengthOf(1)
579
580     const file = video.files[0]
581     const magnetUri = file.magnetUri
582     expect(file.magnetUri).to.have.lengthOf.above(2)
583     expect(file.resolution).to.equal(720)
584     expect(file.resolutionLabel).to.equal('720p')
585     expect(file.size).to.equal(292677)
586
587     const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
588     expect(test).to.equal(true)
589
590     const torrent = await webtorrentAdd(magnetUri)
591     expect(torrent.files).to.be.an('array')
592     expect(torrent.files.length).to.equal(1)
593     expect(torrent.files[0].path).to.exist.and.to.not.equal('')
594   })
595
596   it('Should update only the tags of a video', async function () {
597     const attributes = {
598       tags: [ 'tag1', 'tag2', 'supertag' ]
599     }
600
601     await updateVideo(server.url, server.accessToken, videoId, attributes)
602
603     const res = await getVideo(server.url, videoId)
604     const video = res.body
605
606     expect(video.name).to.equal('my super video updated')
607     expect(video.category).to.equal(4)
608     expect(video.categoryLabel).to.equal('Art')
609     expect(video.licence).to.equal(2)
610     expect(video.licenceLabel).to.equal('Attribution - Share Alike')
611     expect(video.language).to.equal(5)
612     expect(video.languageLabel).to.equal('Arabic')
613     expect(video.nsfw).to.be.ok
614     expect(video.description).to.equal('my super description updated')
615     expect(video.serverHost).to.equal('localhost:9001')
616     expect(video.accountName).to.equal('root')
617     expect(video.isLocal).to.be.true
618     expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
619     expect(dateIsValid(video.createdAt)).to.be.true
620     expect(dateIsValid(video.updatedAt)).to.be.true
621
622     expect(video.channel.name).to.equal('Default root channel')
623     expect(video.channel.isLocal).to.be.true
624     expect(dateIsValid(video.channel.createdAt)).to.be.true
625     expect(dateIsValid(video.channel.updatedAt)).to.be.true
626
627     expect(video.files).to.have.lengthOf(1)
628
629     const file = video.files[0]
630     expect(file.magnetUri).to.have.lengthOf.above(2)
631     expect(file.resolution).to.equal(720)
632     expect(file.resolutionLabel).to.equal('720p')
633     expect(file.size).to.equal(292677)
634   })
635
636   it('Should update only the description of a video', async function () {
637     const attributes = {
638       description: 'hello everybody'
639     }
640
641     await updateVideo(server.url, server.accessToken, videoId, attributes)
642
643     const res = await getVideo(server.url, videoId)
644     const video = res.body
645
646     expect(video.name).to.equal('my super video updated')
647     expect(video.category).to.equal(4)
648     expect(video.categoryLabel).to.equal('Art')
649     expect(video.licence).to.equal(2)
650     expect(video.licenceLabel).to.equal('Attribution - Share Alike')
651     expect(video.language).to.equal(5)
652     expect(video.languageLabel).to.equal('Arabic')
653     expect(video.nsfw).to.be.ok
654     expect(video.description).to.equal('hello everybody')
655     expect(video.serverHost).to.equal('localhost:9001')
656     expect(video.accountName).to.equal('root')
657     expect(video.isLocal).to.be.true
658     expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
659     expect(dateIsValid(video.createdAt)).to.be.true
660     expect(dateIsValid(video.updatedAt)).to.be.true
661
662     expect(video.channel.name).to.equal('Default root channel')
663     expect(video.channel.isLocal).to.be.true
664     expect(dateIsValid(video.channel.createdAt)).to.be.true
665     expect(dateIsValid(video.channel.updatedAt)).to.be.true
666
667     expect(video.files).to.have.lengthOf(1)
668
669     const file = video.files[0]
670     expect(file.magnetUri).to.have.lengthOf.above(2)
671     expect(file.resolution).to.equal(720)
672     expect(file.resolutionLabel).to.equal('720p')
673     expect(file.size).to.equal(292677)
674   })
675
676   it('Should like a video', async function () {
677     await rateVideo(server.url, server.accessToken, videoId, 'like')
678
679     const res = await getVideo(server.url, videoId)
680     const video = res.body
681
682     expect(video.likes).to.equal(1)
683     expect(video.dislikes).to.equal(0)
684   })
685
686   it('Should dislike the same video', async function () {
687     await rateVideo(server.url, server.accessToken, videoId, 'dislike')
688
689     const res = await getVideo(server.url, videoId)
690     const video = res.body
691
692     expect(video.likes).to.equal(0)
693     expect(video.dislikes).to.equal(1)
694   })
695
696   after(async function () {
697     killallServers([ server ])
698
699     // Keep the logs if the test failed
700     if (this['ok']) {
701       await flushTests()
702     }
703   })
704 })