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