Make some fields optional when uploading a video
[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     await uploadVideo(server.url, server.accessToken, videoAttributes)
108   })
109
110   it('Should seed the uploaded video', async function () {
111     // Yes, this could be long
112     this.timeout(60000)
113
114     const res = await getVideosList(server.url)
115
116     expect(res.body.total).to.equal(1)
117     expect(res.body.data).to.be.an('array')
118     expect(res.body.data.length).to.equal(1)
119
120     const video = res.body.data[0]
121     expect(video.name).to.equal('my super name')
122     expect(video.category).to.equal(2)
123     expect(video.categoryLabel).to.equal('Films')
124     expect(video.licence).to.equal(6)
125     expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
126     expect(video.language).to.equal(3)
127     expect(video.languageLabel).to.equal('Mandarin')
128     expect(video.nsfw).to.be.ok
129     expect(video.description).to.equal('my super description')
130     expect(video.serverHost).to.equal('localhost:9001')
131     expect(video.accountName).to.equal('root')
132     expect(video.isLocal).to.be.true
133     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
134     expect(dateIsValid(video.createdAt)).to.be.true
135     expect(dateIsValid(video.updatedAt)).to.be.true
136
137     const res2 = await getVideo(server.url, res.body.data[0].id)
138     const videoDetails = res2.body
139
140     expect(videoDetails.files).to.have.lengthOf(1)
141
142     const file = videoDetails.files[0]
143     const magnetUri = file.magnetUri
144     expect(file.magnetUri).to.have.lengthOf.above(2)
145     expect(file.torrentUrl).to.equal(`${server.url}/static/torrents/${videoDetails.uuid}-${file.resolution}.torrent`)
146     expect(file.fileUrl).to.equal(`${server.url}/static/webseed/${videoDetails.uuid}-${file.resolution}.webm`)
147     expect(file.resolution).to.equal(720)
148     expect(file.resolutionLabel).to.equal('720p')
149     expect(file.size).to.equal(218910)
150
151     const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
152     expect(test).to.equal(true)
153
154     videoId = videoDetails.id
155     videoUUID = videoDetails.uuid
156
157     const torrent = await webtorrentAdd(magnetUri)
158     expect(torrent.files).to.be.an('array')
159     expect(torrent.files.length).to.equal(1)
160     expect(torrent.files[0].path).to.exist.and.to.not.equal('')
161   })
162
163   it('Should get the video', async function () {
164     // Yes, this could be long
165     this.timeout(60000)
166
167     const res = await getVideo(server.url, videoId)
168
169     const video = res.body
170     expect(video.name).to.equal('my super name')
171     expect(video.category).to.equal(2)
172     expect(video.categoryLabel).to.equal('Films')
173     expect(video.licence).to.equal(6)
174     expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
175     expect(video.language).to.equal(3)
176     expect(video.languageLabel).to.equal('Mandarin')
177     expect(video.nsfw).to.be.ok
178     expect(video.description).to.equal('my super description')
179     expect(video.serverHost).to.equal('localhost:9001')
180     expect(video.accountName).to.equal('root')
181     expect(video.isLocal).to.be.true
182     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
183     expect(dateIsValid(video.createdAt)).to.be.true
184     expect(dateIsValid(video.updatedAt)).to.be.true
185     expect(video.channel.name).to.equal('Default root channel')
186     expect(video.channel.isLocal).to.be.true
187     expect(dateIsValid(video.channel.createdAt)).to.be.true
188     expect(dateIsValid(video.channel.updatedAt)).to.be.true
189
190     expect(video.files).to.have.lengthOf(1)
191
192     const file = video.files[0]
193     expect(file.magnetUri).to.have.lengthOf.above(2)
194     expect(file.resolution).to.equal(720)
195     expect(file.resolutionLabel).to.equal('720p')
196     expect(file.size).to.equal(218910)
197
198     const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
199     expect(test).to.equal(true)
200
201     // Wait the async views increment
202     await wait(500)
203   })
204
205   it('Should get the video by UUID', async function () {
206     // Yes, this could be long
207     this.timeout(60000)
208
209     const res = await getVideo(server.url, videoUUID)
210
211     const video = res.body
212     expect(video.name).to.equal('my super name')
213
214     // Wait the async views increment
215     await wait(500)
216   })
217
218   it('Should have the views updated', async function () {
219     await viewVideo(server.url, videoId)
220     await viewVideo(server.url, videoId)
221     await viewVideo(server.url, videoId)
222
223     const res = await getVideo(server.url, videoId)
224
225     const video = res.body
226     expect(video.views).to.equal(3)
227   })
228
229   it('Should search the video by name', async function () {
230     const res = await searchVideo(server.url, 'my')
231
232     expect(res.body.total).to.equal(1)
233     expect(res.body.data).to.be.an('array')
234     expect(res.body.data.length).to.equal(1)
235
236     const video = res.body.data[0]
237     expect(video.name).to.equal('my super name')
238     expect(video.category).to.equal(2)
239     expect(video.categoryLabel).to.equal('Films')
240     expect(video.licence).to.equal(6)
241     expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
242     expect(video.language).to.equal(3)
243     expect(video.languageLabel).to.equal('Mandarin')
244     expect(video.nsfw).to.be.ok
245     expect(video.description).to.equal('my super description')
246     expect(video.serverHost).to.equal('localhost:9001')
247     expect(video.accountName).to.equal('root')
248     expect(video.isLocal).to.be.true
249     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
250     expect(dateIsValid(video.createdAt)).to.be.true
251     expect(dateIsValid(video.updatedAt)).to.be.true
252
253     const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
254     expect(test).to.equal(true)
255   })
256
257   // Not implemented yet
258   // it('Should search the video by serverHost', async function () {
259   //     const res = await   videosUtils.searchVideo(server.url, '9001', 'host')
260
261   //     expect(res.body.total).to.equal(1)
262   //     expect(res.body.data).to.be.an('array')
263   //     expect(res.body.data.length).to.equal(1)
264
265   //     const video = res.body.data[0]
266   //     expect(video.name).to.equal('my super name')
267   //     expect(video.description).to.equal('my super description')
268   //     expect(video.serverHost).to.equal('localhost:9001')
269   //     expect(video.author).to.equal('root')
270   //     expect(video.isLocal).to.be.true
271   //     expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
272   //     expect(dateIsValid(video.createdAt)).to.be.true
273   //     expect(dateIsValid(video.updatedAt)).to.be.true
274
275   //     const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
276   //       expect(test).to.equal(true)
277
278   //       done()
279   //     })
280   //   })
281   // })
282
283   // Not implemented yet
284   // it('Should search the video by tag', async function () {
285   //   const res = await searchVideo(server.url, 'tag1')
286   //
287   //   expect(res.body.total).to.equal(1)
288   //   expect(res.body.data).to.be.an('array')
289   //   expect(res.body.data.length).to.equal(1)
290   //
291   //   const video = res.body.data[0]
292   //   expect(video.name).to.equal('my super name')
293   //   expect(video.category).to.equal(2)
294   //   expect(video.categoryLabel).to.equal('Films')
295   //   expect(video.licence).to.equal(6)
296   //   expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
297   //   expect(video.language).to.equal(3)
298   //   expect(video.languageLabel).to.equal('Mandarin')
299   //   expect(video.nsfw).to.be.ok
300   //   expect(video.description).to.equal('my super description')
301   //   expect(video.serverHost).to.equal('localhost:9001')
302   //   expect(video.accountName).to.equal('root')
303   //   expect(video.isLocal).to.be.true
304   //   expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
305   //   expect(dateIsValid(video.createdAt)).to.be.true
306   //   expect(dateIsValid(video.updatedAt)).to.be.true
307   //
308   //   const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
309   //   expect(test).to.equal(true)
310   // })
311
312   it('Should not find a search by name', async function () {
313     const res = await searchVideo(server.url, 'hello')
314
315     expect(res.body.total).to.equal(0)
316     expect(res.body.data).to.be.an('array')
317     expect(res.body.data.length).to.equal(0)
318   })
319
320   // Not implemented yet
321   // it('Should not find a search by author', async function () {
322   //   const res = await searchVideo(server.url, 'hello')
323   //
324   //   expect(res.body.total).to.equal(0)
325   //   expect(res.body.data).to.be.an('array')
326   //   expect(res.body.data.length).to.equal(0)
327   // })
328   //
329   // Not implemented yet
330   // it('Should not find a search by tag', async function () {
331   //   const res = await searchVideo(server.url, 'hello')
332   //
333   //   expect(res.body.total).to.equal(0)
334   //   expect(res.body.data).to.be.an('array')
335   //   expect(res.body.data.length).to.equal(0)
336   // })
337
338   it('Should remove the video', async function () {
339     await removeVideo(server.url, server.accessToken, videoId)
340
341     const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
342     expect(files1).to.have.lengthOf(0)
343
344     const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
345     expect(files2).to.have.lengthOf(0)
346   })
347
348   it('Should not have videos', async function () {
349     const res = await getVideosList(server.url)
350
351     expect(res.body.total).to.equal(0)
352     expect(res.body.data).to.be.an('array')
353     expect(res.body.data).to.have.lengthOf(0)
354   })
355
356   it('Should upload 6 videos', async function () {
357     this.timeout(25000)
358
359     const videos = [
360       'video_short.mp4', 'video_short.ogv', 'video_short.webm',
361       'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
362     ]
363
364     // const tasks: Promise<any>[] = []
365     for (const video of videos) {
366       const videoAttributes = {
367         name: video + ' name',
368         description: video + ' description',
369         category: 2,
370         licence: 1,
371         language: 1,
372         nsfw: true,
373         tags: [ 'tag1', 'tag2', 'tag3' ],
374         fixture: video
375       }
376
377       const p = uploadVideo(server.url, server.accessToken, videoAttributes)
378       await p
379     }
380     // FIXME: concurrent uploads does not work :(
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(204)
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 })