]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/single-server.ts
Design second video upload step
[github/Chocobozzz/PeerTube.git] / server / tests / api / single-server.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
8e7f08b5 3import * as chai from 'chai'
0e1dc3e7 4import { keyBy } from 'lodash'
0e1dc3e7 5import 'mocha'
8e7f08b5
C
6import { join } from 'path'
7import * as request from 'supertest'
0e1dc3e7 8import {
0e1dc3e7 9 dateIsValid,
8e7f08b5
C
10 flushTests,
11 getVideo,
0e1dc3e7 12 getVideoCategories,
0e1dc3e7 13 getVideoLanguages,
8e7f08b5 14 getVideoLicences,
11474c3c 15 getVideoPrivacies,
8e7f08b5 16 getVideosList,
0e1dc3e7 17 getVideosListPagination,
0e1dc3e7 18 getVideosListSort,
8e7f08b5
C
19 killallServers,
20 rateVideo,
21 readdirPromise,
22 removeVideo,
23 runServer,
24 searchVideo,
25 searchVideoWithPagination,
0e1dc3e7 26 searchVideoWithSort,
8e7f08b5
C
27 ServerInfo,
28 setAccessTokensToServers,
29 testVideoImage,
30 updateVideo,
31 uploadVideo,
32 wait,
33 webtorrentAdd
0e1dc3e7 34} from '../utils'
1f3e9fec 35import { viewVideo } from '../utils/videos'
0e1dc3e7 36
8e7f08b5
C
37const expect = chai.expect
38
9a27cdc2 39describe('Test a single server', function () {
0e1dc3e7
C
40 let server: ServerInfo = null
41 let videoId = -1
42 let videoUUID = ''
43 let videosListBase: any[] = null
44
45 before(async function () {
572f8d3d 46 this.timeout(10000)
0e1dc3e7
C
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
11474c3c
C
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
0e1dc3e7
C
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 }
cadb46d8
C
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)
0e1dc3e7
C
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')
afffe988 133 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 134 expect(video.accountName).to.equal('root')
0e1dc3e7
C
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
5f04dd2f
C
140 const res2 = await getVideo(server.url, res.body.data[0].id)
141 const videoDetails = res2.body
0e1dc3e7 142
5f04dd2f
C
143 expect(videoDetails.files).to.have.lengthOf(1)
144
145 const file = videoDetails.files[0]
0e1dc3e7
C
146 const magnetUri = file.magnetUri
147 expect(file.magnetUri).to.have.lengthOf.above(2)
5f04dd2f
C
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`)
14d3270f
C
150 expect(file.resolution).to.equal(720)
151 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
152 expect(file.size).to.equal(218910)
153
5f04dd2f 154 const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
0e1dc3e7
C
155 expect(test).to.equal(true)
156
5f04dd2f
C
157 videoId = videoDetails.id
158 videoUUID = videoDetails.uuid
0e1dc3e7
C
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')
afffe988 182 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 183 expect(video.accountName).to.equal('root')
0e1dc3e7
C
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
5f04dd2f
C
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
0e1dc3e7
C
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)
14d3270f
C
197 expect(file.resolution).to.equal(720)
198 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
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 () {
1f3e9fec
C
222 await viewVideo(server.url, videoId)
223 await viewVideo(server.url, videoId)
224 await viewVideo(server.url, videoId)
225
0e1dc3e7
C
226 const res = await getVideo(server.url, videoId)
227
228 const video = res.body
5f04dd2f 229 expect(video.views).to.equal(3)
0e1dc3e7
C
230 })
231
f3aaa9a9 232 it('Should search the video by name', async function () {
0e1dc3e7
C
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')
afffe988 249 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 250 expect(video.accountName).to.equal('root')
0e1dc3e7
C
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
0e1dc3e7
C
256 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
257 expect(test).to.equal(true)
258 })
259
260 // Not implemented yet
afffe988 261 // it('Should search the video by serverHost', async function () {
0e1dc3e7
C
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')
afffe988 271 // expect(video.serverHost).to.equal('localhost:9001')
0e1dc3e7
C
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
f3aaa9a9
C
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')
b1fa3eba 305 // expect(video.accountName).to.equal('root')
f3aaa9a9
C
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 // })
0e1dc3e7 314
f3aaa9a9 315 it('Should not find a search by name', async function () {
0e1dc3e7
C
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
f3aaa9a9
C
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 // })
0e1dc3e7
C
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
afffe988 367 // const tasks: Promise<any>[] = []
0e1dc3e7
C
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)
afffe988 381 await p
0e1dc3e7 382 }
afffe988
C
383 // FIXME: concurrent uploads does not work :(
384 // tasks.push(p)
385 // }
386 //
387 // await Promise.all(tasks)
0e1dc3e7
C
388 })
389
390 it('Should have the correct durations', async function () {
391 const res = await getVideosList(server.url)
392
393 expect(res.body.total).to.equal(6)
394 const videos = res.body.data
395 expect(videos).to.be.an('array')
396 expect(videos).to.have.lengthOf(6)
397
398 const videosByName = keyBy<{ duration: number }>(videos, 'name')
399 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
400 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
401 expect(videosByName['video_short.webm name'].duration).to.equal(5)
402 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
403 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
404 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
405 })
406
407 it('Should have the correct thumbnails', async function () {
408 const res = await getVideosList(server.url)
409
410 const videos = res.body.data
411 // For the next test
412 videosListBase = videos
413
414 for (const video of videos) {
415 const videoName = video.name.replace(' name', '')
416 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
417
418 expect(test).to.equal(true)
419 }
420 })
421
422 it('Should list only the two first videos', async function () {
423 const res = await getVideosListPagination(server.url, 0, 2, 'name')
424
425 const videos = res.body.data
426 expect(res.body.total).to.equal(6)
427 expect(videos.length).to.equal(2)
428 expect(videos[0].name).to.equal(videosListBase[0].name)
429 expect(videos[1].name).to.equal(videosListBase[1].name)
430 })
431
432 it('Should list only the next three videos', async function () {
433 const res = await getVideosListPagination(server.url, 2, 3, 'name')
434
435 const videos = res.body.data
436 expect(res.body.total).to.equal(6)
437 expect(videos.length).to.equal(3)
438 expect(videos[0].name).to.equal(videosListBase[2].name)
439 expect(videos[1].name).to.equal(videosListBase[3].name)
440 expect(videos[2].name).to.equal(videosListBase[4].name)
441 })
442
443 it('Should list the last video', async function () {
444 const res = await getVideosListPagination(server.url, 5, 6, 'name')
445
446 const videos = res.body.data
447 expect(res.body.total).to.equal(6)
448 expect(videos.length).to.equal(1)
449 expect(videos[0].name).to.equal(videosListBase[5].name)
450 })
451
452 it('Should search the first video', async function () {
f3aaa9a9 453 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
0e1dc3e7
C
454
455 const videos = res.body.data
456 expect(res.body.total).to.equal(4)
457 expect(videos.length).to.equal(1)
458 expect(videos[0].name).to.equal('video_short1.webm name')
459 })
460
461 it('Should search the last two videos', async function () {
f3aaa9a9 462 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
0e1dc3e7
C
463
464 const videos = res.body.data
465 expect(res.body.total).to.equal(4)
466 expect(videos.length).to.equal(2)
467 expect(videos[0].name).to.equal('video_short3.webm name')
468 expect(videos[1].name).to.equal('video_short.webm name')
469 })
470
471 it('Should search all the webm videos', async function () {
f3aaa9a9 472 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
0e1dc3e7
C
473
474 const videos = res.body.data
475 expect(res.body.total).to.equal(4)
476 expect(videos.length).to.equal(4)
477 })
478
f3aaa9a9
C
479 // Not implemented yet
480 // it('Should search all the root author videos', async function () {
481 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
482 //
483 // const videos = res.body.data
484 // expect(res.body.total).to.equal(6)
485 // expect(videos.length).to.equal(6)
486 // })
0e1dc3e7
C
487
488 // Not implemented yet
489 // it('Should search all the 9001 port videos', async function () {
490 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
491
492 // const videos = res.body.data
493 // expect(res.body.total).to.equal(6)
494 // expect(videos.length).to.equal(6)
495
496 // done()
497 // })
498 // })
499
500 // it('Should search all the localhost videos', async function () {
501 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
502
503 // const videos = res.body.data
504 // expect(res.body.total).to.equal(6)
505 // expect(videos.length).to.equal(6)
506
507 // done()
508 // })
509 // })
510
0e1dc3e7
C
511 it('Should list and sort by name in descending order', async function () {
512 const res = await getVideosListSort(server.url, '-name')
513
514 const videos = res.body.data
515 expect(res.body.total).to.equal(6)
516 expect(videos.length).to.equal(6)
517 expect(videos[0].name).to.equal('video_short.webm name')
518 expect(videos[1].name).to.equal('video_short.ogv name')
519 expect(videos[2].name).to.equal('video_short.mp4 name')
520 expect(videos[3].name).to.equal('video_short3.webm name')
521 expect(videos[4].name).to.equal('video_short2.webm name')
522 expect(videos[5].name).to.equal('video_short1.webm name')
523 })
524
525 it('Should search and sort by name in ascending order', async function () {
526 const res = await searchVideoWithSort(server.url, 'webm', 'name')
527
528 const videos = res.body.data
529 expect(res.body.total).to.equal(4)
530 expect(videos.length).to.equal(4)
531
532 expect(videos[0].name).to.equal('video_short1.webm name')
533 expect(videos[1].name).to.equal('video_short2.webm name')
534 expect(videos[2].name).to.equal('video_short3.webm name')
535 expect(videos[3].name).to.equal('video_short.webm name')
536
537 videoId = videos[2].id
538 })
539
540 it('Should update a video', async function () {
541 const attributes = {
542 name: 'my super video updated',
543 category: 4,
544 licence: 2,
545 language: 5,
546 nsfw: false,
547 description: 'my super description updated',
548 tags: [ 'tagup1', 'tagup2' ]
549 }
550 await updateVideo(server.url, server.accessToken, videoId, attributes)
551 })
552
553 it('Should have the video updated', async function () {
554 this.timeout(60000)
555
556 const res = await getVideo(server.url, videoId)
557
558 const video = res.body
559
560 expect(video.name).to.equal('my super video updated')
561 expect(video.category).to.equal(4)
562 expect(video.categoryLabel).to.equal('Art')
563 expect(video.licence).to.equal(2)
564 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
565 expect(video.language).to.equal(5)
566 expect(video.languageLabel).to.equal('Arabic')
567 expect(video.nsfw).to.be.ok
568 expect(video.description).to.equal('my super description updated')
afffe988 569 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba
C
570 expect(video.accountName).to.equal('root')
571 expect(video.account.name).to.equal('root')
0e1dc3e7
C
572 expect(video.isLocal).to.be.true
573 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
574 expect(dateIsValid(video.createdAt)).to.be.true
575 expect(dateIsValid(video.updatedAt)).to.be.true
576
5f04dd2f
C
577 expect(video.channel.name).to.equal('Default root channel')
578 expect(video.channel.isLocal).to.be.true
579 expect(dateIsValid(video.channel.createdAt)).to.be.true
580 expect(dateIsValid(video.channel.updatedAt)).to.be.true
581
0e1dc3e7
C
582 expect(video.files).to.have.lengthOf(1)
583
584 const file = video.files[0]
585 const magnetUri = file.magnetUri
586 expect(file.magnetUri).to.have.lengthOf.above(2)
14d3270f
C
587 expect(file.resolution).to.equal(720)
588 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
589 expect(file.size).to.equal(292677)
590
591 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
592 expect(test).to.equal(true)
593
594 const torrent = await webtorrentAdd(magnetUri)
595 expect(torrent.files).to.be.an('array')
596 expect(torrent.files.length).to.equal(1)
597 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
598 })
599
600 it('Should update only the tags of a video', async function () {
601 const attributes = {
602 tags: [ 'tag1', 'tag2', 'supertag' ]
603 }
604
605 await updateVideo(server.url, server.accessToken, videoId, attributes)
606
607 const res = await getVideo(server.url, videoId)
608 const video = res.body
609
610 expect(video.name).to.equal('my super video updated')
611 expect(video.category).to.equal(4)
612 expect(video.categoryLabel).to.equal('Art')
613 expect(video.licence).to.equal(2)
614 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
615 expect(video.language).to.equal(5)
616 expect(video.languageLabel).to.equal('Arabic')
617 expect(video.nsfw).to.be.ok
618 expect(video.description).to.equal('my super description updated')
afffe988 619 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 620 expect(video.accountName).to.equal('root')
0e1dc3e7 621 expect(video.isLocal).to.be.true
df1966c9 622 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
0e1dc3e7
C
623 expect(dateIsValid(video.createdAt)).to.be.true
624 expect(dateIsValid(video.updatedAt)).to.be.true
625
5f04dd2f
C
626 expect(video.channel.name).to.equal('Default root channel')
627 expect(video.channel.isLocal).to.be.true
628 expect(dateIsValid(video.channel.createdAt)).to.be.true
629 expect(dateIsValid(video.channel.updatedAt)).to.be.true
630
0e1dc3e7
C
631 expect(video.files).to.have.lengthOf(1)
632
633 const file = video.files[0]
634 expect(file.magnetUri).to.have.lengthOf.above(2)
14d3270f
C
635 expect(file.resolution).to.equal(720)
636 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
637 expect(file.size).to.equal(292677)
638 })
639
640 it('Should update only the description of a video', async function () {
641 const attributes = {
642 description: 'hello everybody'
643 }
644
645 await updateVideo(server.url, server.accessToken, videoId, attributes)
646
647 const res = await getVideo(server.url, videoId)
648 const video = res.body
649
650 expect(video.name).to.equal('my super video updated')
651 expect(video.category).to.equal(4)
652 expect(video.categoryLabel).to.equal('Art')
653 expect(video.licence).to.equal(2)
654 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
655 expect(video.language).to.equal(5)
656 expect(video.languageLabel).to.equal('Arabic')
657 expect(video.nsfw).to.be.ok
658 expect(video.description).to.equal('hello everybody')
afffe988 659 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 660 expect(video.accountName).to.equal('root')
0e1dc3e7 661 expect(video.isLocal).to.be.true
df1966c9 662 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
0e1dc3e7
C
663 expect(dateIsValid(video.createdAt)).to.be.true
664 expect(dateIsValid(video.updatedAt)).to.be.true
5f04dd2f
C
665
666 expect(video.channel.name).to.equal('Default root channel')
667 expect(video.channel.isLocal).to.be.true
668 expect(dateIsValid(video.channel.createdAt)).to.be.true
669 expect(dateIsValid(video.channel.updatedAt)).to.be.true
0e1dc3e7
C
670
671 expect(video.files).to.have.lengthOf(1)
672
673 const file = video.files[0]
674 expect(file.magnetUri).to.have.lengthOf.above(2)
14d3270f
C
675 expect(file.resolution).to.equal(720)
676 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
677 expect(file.size).to.equal(292677)
678 })
679
680 it('Should like a video', async function () {
681 await rateVideo(server.url, server.accessToken, videoId, 'like')
682
683 const res = await getVideo(server.url, videoId)
684 const video = res.body
685
686 expect(video.likes).to.equal(1)
687 expect(video.dislikes).to.equal(0)
688 })
689
690 it('Should dislike the same video', async function () {
691 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
692
693 const res = await getVideo(server.url, videoId)
694 const video = res.body
695
696 expect(video.likes).to.equal(0)
697 expect(video.dislikes).to.equal(1)
698 })
699
8e7f08b5
C
700 it('Should upload a video with minimum parameters', async function () {
701 const path = '/api/v1/videos/upload'
702
703 const req = request(server.url)
704 .post(path)
705 .set('Accept', 'application/json')
706 .set('Authorization', 'Bearer ' + server.accessToken)
707 .field('name', 'minimum parameters')
708 .field('privacy', '1')
709 .field('nsfw', 'false')
710 .field('channelId', '1')
711
712 const filePath = join(__dirname, '..', 'api', 'fixtures', 'video_short.webm')
713
714 await req.attach('videofile', filePath)
715 .expect(204)
716
717 const res = await getVideosList(server.url)
718 const video = res.body.data.find(v => v.name === 'minimum parameters')
719
720 expect(video.name).to.equal('minimum parameters')
721 expect(video.category).to.equal(null)
722 expect(video.categoryLabel).to.equal('Misc')
723 expect(video.licence).to.equal(null)
724 expect(video.licenceLabel).to.equal('Unknown')
725 expect(video.language).to.equal(null)
726 expect(video.languageLabel).to.equal('Unknown')
727 expect(video.nsfw).to.not.be.ok
728 expect(video.description).to.equal(null)
729 expect(video.serverHost).to.equal('localhost:9001')
730 expect(video.accountName).to.equal('root')
731 expect(video.isLocal).to.be.true
732 expect(video.tags).to.deep.equal([ ])
733 expect(dateIsValid(video.createdAt)).to.be.true
734 expect(dateIsValid(video.updatedAt)).to.be.true
735 })
736
0e1dc3e7
C
737 after(async function () {
738 killallServers([ server ])
739
740 // Keep the logs if the test failed
741 if (this['ok']) {
742 await flushTests()
743 }
744 })
745})