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