]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/single-server.ts
Design confirm dialog
[github/Chocobozzz/PeerTube.git] / server / tests / api / single-server.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
3import { keyBy } from 'lodash'
4import { join } from 'path'
5import 'mocha'
6import * as chai from 'chai'
7const expect = chai.expect
8
9import {
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,
11474c3c 25 getVideoPrivacies,
0e1dc3e7
C
26 testVideoImage,
27 webtorrentAdd,
28 getVideo,
29 readdirPromise,
30 getVideosListPagination,
31 searchVideoWithPagination,
32 getVideosListSort,
33 searchVideoWithSort,
34 updateVideo
35} from '../utils'
1f3e9fec 36import { viewVideo } from '../utils/videos'
0e1dc3e7 37
9a27cdc2 38describe('Test a single server', function () {
0e1dc3e7
C
39 let server: ServerInfo = null
40 let videoId = -1
41 let videoUUID = ''
42 let videosListBase: any[] = null
43
44 before(async function () {
572f8d3d 45 this.timeout(10000)
0e1dc3e7
C
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
11474c3c
C
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
0e1dc3e7
C
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')
afffe988 129 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 130 expect(video.accountName).to.equal('root')
0e1dc3e7
C
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
5f04dd2f
C
136 const res2 = await getVideo(server.url, res.body.data[0].id)
137 const videoDetails = res2.body
0e1dc3e7 138
5f04dd2f
C
139 expect(videoDetails.files).to.have.lengthOf(1)
140
141 const file = videoDetails.files[0]
0e1dc3e7
C
142 const magnetUri = file.magnetUri
143 expect(file.magnetUri).to.have.lengthOf.above(2)
5f04dd2f
C
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`)
14d3270f
C
146 expect(file.resolution).to.equal(720)
147 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
148 expect(file.size).to.equal(218910)
149
5f04dd2f 150 const test = await testVideoImage(server.url, 'video_short.webm', videoDetails.thumbnailPath)
0e1dc3e7
C
151 expect(test).to.equal(true)
152
5f04dd2f
C
153 videoId = videoDetails.id
154 videoUUID = videoDetails.uuid
0e1dc3e7
C
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')
afffe988 178 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 179 expect(video.accountName).to.equal('root')
0e1dc3e7
C
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
5f04dd2f
C
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
0e1dc3e7
C
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)
14d3270f
C
193 expect(file.resolution).to.equal(720)
194 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
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 () {
1f3e9fec
C
218 await viewVideo(server.url, videoId)
219 await viewVideo(server.url, videoId)
220 await viewVideo(server.url, videoId)
221
0e1dc3e7
C
222 const res = await getVideo(server.url, videoId)
223
224 const video = res.body
5f04dd2f 225 expect(video.views).to.equal(3)
0e1dc3e7
C
226 })
227
f3aaa9a9 228 it('Should search the video by name', async function () {
0e1dc3e7
C
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')
afffe988 245 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 246 expect(video.accountName).to.equal('root')
0e1dc3e7
C
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
0e1dc3e7
C
252 const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
253 expect(test).to.equal(true)
254 })
255
256 // Not implemented yet
afffe988 257 // it('Should search the video by serverHost', async function () {
0e1dc3e7
C
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')
afffe988 267 // expect(video.serverHost).to.equal('localhost:9001')
0e1dc3e7
C
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
f3aaa9a9
C
282 // Not implemented yet
283 // it('Should search the video by tag', async function () {
284 // const res = await searchVideo(server.url, 'tag1')
285 //
286 // expect(res.body.total).to.equal(1)
287 // expect(res.body.data).to.be.an('array')
288 // expect(res.body.data.length).to.equal(1)
289 //
290 // const video = res.body.data[0]
291 // expect(video.name).to.equal('my super name')
292 // expect(video.category).to.equal(2)
293 // expect(video.categoryLabel).to.equal('Films')
294 // expect(video.licence).to.equal(6)
295 // expect(video.licenceLabel).to.equal('Attribution - Non Commercial - No Derivatives')
296 // expect(video.language).to.equal(3)
297 // expect(video.languageLabel).to.equal('Mandarin')
298 // expect(video.nsfw).to.be.ok
299 // expect(video.description).to.equal('my super description')
300 // expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 301 // expect(video.accountName).to.equal('root')
f3aaa9a9
C
302 // expect(video.isLocal).to.be.true
303 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
304 // expect(dateIsValid(video.createdAt)).to.be.true
305 // expect(dateIsValid(video.updatedAt)).to.be.true
306 //
307 // const test = await testVideoImage(server.url, 'video_short.webm', video.thumbnailPath)
308 // expect(test).to.equal(true)
309 // })
0e1dc3e7 310
f3aaa9a9 311 it('Should not find a search by name', async function () {
0e1dc3e7
C
312 const res = await searchVideo(server.url, 'hello')
313
314 expect(res.body.total).to.equal(0)
315 expect(res.body.data).to.be.an('array')
316 expect(res.body.data.length).to.equal(0)
317 })
318
f3aaa9a9
C
319 // Not implemented yet
320 // it('Should not find a search by author', async function () {
321 // const res = await searchVideo(server.url, 'hello')
322 //
323 // expect(res.body.total).to.equal(0)
324 // expect(res.body.data).to.be.an('array')
325 // expect(res.body.data.length).to.equal(0)
326 // })
327 //
328 // Not implemented yet
329 // it('Should not find a search by tag', async function () {
330 // const res = await searchVideo(server.url, 'hello')
331 //
332 // expect(res.body.total).to.equal(0)
333 // expect(res.body.data).to.be.an('array')
334 // expect(res.body.data.length).to.equal(0)
335 // })
0e1dc3e7
C
336
337 it('Should remove the video', async function () {
338 await removeVideo(server.url, server.accessToken, videoId)
339
340 const files1 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/videos/'))
341 expect(files1).to.have.lengthOf(0)
342
343 const files2 = await readdirPromise(join(__dirname, '..', '..', '..', 'test1/thumbnails/'))
344 expect(files2).to.have.lengthOf(0)
345 })
346
347 it('Should not have videos', async function () {
348 const res = await getVideosList(server.url)
349
350 expect(res.body.total).to.equal(0)
351 expect(res.body.data).to.be.an('array')
352 expect(res.body.data).to.have.lengthOf(0)
353 })
354
355 it('Should upload 6 videos', async function () {
356 this.timeout(25000)
357
358 const videos = [
359 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
360 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
361 ]
362
afffe988 363 // const tasks: Promise<any>[] = []
0e1dc3e7
C
364 for (const video of videos) {
365 const videoAttributes = {
366 name: video + ' name',
367 description: video + ' description',
368 category: 2,
369 licence: 1,
370 language: 1,
371 nsfw: true,
372 tags: [ 'tag1', 'tag2', 'tag3' ],
373 fixture: video
374 }
375
376 const p = uploadVideo(server.url, server.accessToken, videoAttributes)
afffe988 377 await p
0e1dc3e7 378 }
afffe988
C
379 // FIXME: concurrent uploads does not work :(
380 // tasks.push(p)
381 // }
382 //
383 // await Promise.all(tasks)
0e1dc3e7
C
384 })
385
386 it('Should have the correct durations', async function () {
387 const res = await getVideosList(server.url)
388
389 expect(res.body.total).to.equal(6)
390 const videos = res.body.data
391 expect(videos).to.be.an('array')
392 expect(videos).to.have.lengthOf(6)
393
394 const videosByName = keyBy<{ duration: number }>(videos, 'name')
395 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
396 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
397 expect(videosByName['video_short.webm name'].duration).to.equal(5)
398 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
399 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
400 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
401 })
402
403 it('Should have the correct thumbnails', async function () {
404 const res = await getVideosList(server.url)
405
406 const videos = res.body.data
407 // For the next test
408 videosListBase = videos
409
410 for (const video of videos) {
411 const videoName = video.name.replace(' name', '')
412 const test = await testVideoImage(server.url, videoName, video.thumbnailPath)
413
414 expect(test).to.equal(true)
415 }
416 })
417
418 it('Should list only the two first videos', async function () {
419 const res = await getVideosListPagination(server.url, 0, 2, 'name')
420
421 const videos = res.body.data
422 expect(res.body.total).to.equal(6)
423 expect(videos.length).to.equal(2)
424 expect(videos[0].name).to.equal(videosListBase[0].name)
425 expect(videos[1].name).to.equal(videosListBase[1].name)
426 })
427
428 it('Should list only the next three videos', async function () {
429 const res = await getVideosListPagination(server.url, 2, 3, 'name')
430
431 const videos = res.body.data
432 expect(res.body.total).to.equal(6)
433 expect(videos.length).to.equal(3)
434 expect(videos[0].name).to.equal(videosListBase[2].name)
435 expect(videos[1].name).to.equal(videosListBase[3].name)
436 expect(videos[2].name).to.equal(videosListBase[4].name)
437 })
438
439 it('Should list the last video', async function () {
440 const res = await getVideosListPagination(server.url, 5, 6, 'name')
441
442 const videos = res.body.data
443 expect(res.body.total).to.equal(6)
444 expect(videos.length).to.equal(1)
445 expect(videos[0].name).to.equal(videosListBase[5].name)
446 })
447
448 it('Should search the first video', async function () {
f3aaa9a9 449 const res = await searchVideoWithPagination(server.url, 'webm', 0, 1, 'name')
0e1dc3e7
C
450
451 const videos = res.body.data
452 expect(res.body.total).to.equal(4)
453 expect(videos.length).to.equal(1)
454 expect(videos[0].name).to.equal('video_short1.webm name')
455 })
456
457 it('Should search the last two videos', async function () {
f3aaa9a9 458 const res = await searchVideoWithPagination(server.url, 'webm', 2, 2, 'name')
0e1dc3e7
C
459
460 const videos = res.body.data
461 expect(res.body.total).to.equal(4)
462 expect(videos.length).to.equal(2)
463 expect(videos[0].name).to.equal('video_short3.webm name')
464 expect(videos[1].name).to.equal('video_short.webm name')
465 })
466
467 it('Should search all the webm videos', async function () {
f3aaa9a9 468 const res = await searchVideoWithPagination(server.url, 'webm', 0, 15)
0e1dc3e7
C
469
470 const videos = res.body.data
471 expect(res.body.total).to.equal(4)
472 expect(videos.length).to.equal(4)
473 })
474
f3aaa9a9
C
475 // Not implemented yet
476 // it('Should search all the root author videos', async function () {
477 // const res = await searchVideoWithPagination(server.url, 'root', 0, 15)
478 //
479 // const videos = res.body.data
480 // expect(res.body.total).to.equal(6)
481 // expect(videos.length).to.equal(6)
482 // })
0e1dc3e7
C
483
484 // Not implemented yet
485 // it('Should search all the 9001 port videos', async function () {
486 // const res = await videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15)
487
488 // const videos = res.body.data
489 // expect(res.body.total).to.equal(6)
490 // expect(videos.length).to.equal(6)
491
492 // done()
493 // })
494 // })
495
496 // it('Should search all the localhost videos', async function () {
497 // const res = await videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15)
498
499 // const videos = res.body.data
500 // expect(res.body.total).to.equal(6)
501 // expect(videos.length).to.equal(6)
502
503 // done()
504 // })
505 // })
506
0e1dc3e7
C
507 it('Should list and sort by name in descending order', async function () {
508 const res = await getVideosListSort(server.url, '-name')
509
510 const videos = res.body.data
511 expect(res.body.total).to.equal(6)
512 expect(videos.length).to.equal(6)
513 expect(videos[0].name).to.equal('video_short.webm name')
514 expect(videos[1].name).to.equal('video_short.ogv name')
515 expect(videos[2].name).to.equal('video_short.mp4 name')
516 expect(videos[3].name).to.equal('video_short3.webm name')
517 expect(videos[4].name).to.equal('video_short2.webm name')
518 expect(videos[5].name).to.equal('video_short1.webm name')
519 })
520
521 it('Should search and sort by name in ascending order', async function () {
522 const res = await searchVideoWithSort(server.url, 'webm', 'name')
523
524 const videos = res.body.data
525 expect(res.body.total).to.equal(4)
526 expect(videos.length).to.equal(4)
527
528 expect(videos[0].name).to.equal('video_short1.webm name')
529 expect(videos[1].name).to.equal('video_short2.webm name')
530 expect(videos[2].name).to.equal('video_short3.webm name')
531 expect(videos[3].name).to.equal('video_short.webm name')
532
533 videoId = videos[2].id
534 })
535
536 it('Should update a video', async function () {
537 const attributes = {
538 name: 'my super video updated',
539 category: 4,
540 licence: 2,
541 language: 5,
542 nsfw: false,
543 description: 'my super description updated',
544 tags: [ 'tagup1', 'tagup2' ]
545 }
546 await updateVideo(server.url, server.accessToken, videoId, attributes)
547 })
548
549 it('Should have the video updated', async function () {
550 this.timeout(60000)
551
552 const res = await getVideo(server.url, videoId)
553
554 const video = res.body
555
556 expect(video.name).to.equal('my super video updated')
557 expect(video.category).to.equal(4)
558 expect(video.categoryLabel).to.equal('Art')
559 expect(video.licence).to.equal(2)
560 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
561 expect(video.language).to.equal(5)
562 expect(video.languageLabel).to.equal('Arabic')
563 expect(video.nsfw).to.be.ok
564 expect(video.description).to.equal('my super description updated')
afffe988 565 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba
C
566 expect(video.accountName).to.equal('root')
567 expect(video.account.name).to.equal('root')
0e1dc3e7
C
568 expect(video.isLocal).to.be.true
569 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
570 expect(dateIsValid(video.createdAt)).to.be.true
571 expect(dateIsValid(video.updatedAt)).to.be.true
572
5f04dd2f
C
573 expect(video.channel.name).to.equal('Default root channel')
574 expect(video.channel.isLocal).to.be.true
575 expect(dateIsValid(video.channel.createdAt)).to.be.true
576 expect(dateIsValid(video.channel.updatedAt)).to.be.true
577
0e1dc3e7
C
578 expect(video.files).to.have.lengthOf(1)
579
580 const file = video.files[0]
581 const magnetUri = file.magnetUri
582 expect(file.magnetUri).to.have.lengthOf.above(2)
14d3270f
C
583 expect(file.resolution).to.equal(720)
584 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
585 expect(file.size).to.equal(292677)
586
587 const test = await testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath)
588 expect(test).to.equal(true)
589
590 const torrent = await webtorrentAdd(magnetUri)
591 expect(torrent.files).to.be.an('array')
592 expect(torrent.files.length).to.equal(1)
593 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
594 })
595
596 it('Should update only the tags of a video', async function () {
597 const attributes = {
598 tags: [ 'tag1', 'tag2', 'supertag' ]
599 }
600
601 await updateVideo(server.url, server.accessToken, videoId, attributes)
602
603 const res = await getVideo(server.url, videoId)
604 const video = res.body
605
606 expect(video.name).to.equal('my super video updated')
607 expect(video.category).to.equal(4)
608 expect(video.categoryLabel).to.equal('Art')
609 expect(video.licence).to.equal(2)
610 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
611 expect(video.language).to.equal(5)
612 expect(video.languageLabel).to.equal('Arabic')
613 expect(video.nsfw).to.be.ok
614 expect(video.description).to.equal('my super description updated')
afffe988 615 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 616 expect(video.accountName).to.equal('root')
0e1dc3e7 617 expect(video.isLocal).to.be.true
df1966c9 618 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
0e1dc3e7
C
619 expect(dateIsValid(video.createdAt)).to.be.true
620 expect(dateIsValid(video.updatedAt)).to.be.true
621
5f04dd2f
C
622 expect(video.channel.name).to.equal('Default root channel')
623 expect(video.channel.isLocal).to.be.true
624 expect(dateIsValid(video.channel.createdAt)).to.be.true
625 expect(dateIsValid(video.channel.updatedAt)).to.be.true
626
0e1dc3e7
C
627 expect(video.files).to.have.lengthOf(1)
628
629 const file = video.files[0]
630 expect(file.magnetUri).to.have.lengthOf.above(2)
14d3270f
C
631 expect(file.resolution).to.equal(720)
632 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
633 expect(file.size).to.equal(292677)
634 })
635
636 it('Should update only the description of a video', async function () {
637 const attributes = {
638 description: 'hello everybody'
639 }
640
641 await updateVideo(server.url, server.accessToken, videoId, attributes)
642
643 const res = await getVideo(server.url, videoId)
644 const video = res.body
645
646 expect(video.name).to.equal('my super video updated')
647 expect(video.category).to.equal(4)
648 expect(video.categoryLabel).to.equal('Art')
649 expect(video.licence).to.equal(2)
650 expect(video.licenceLabel).to.equal('Attribution - Share Alike')
651 expect(video.language).to.equal(5)
652 expect(video.languageLabel).to.equal('Arabic')
653 expect(video.nsfw).to.be.ok
654 expect(video.description).to.equal('hello everybody')
afffe988 655 expect(video.serverHost).to.equal('localhost:9001')
b1fa3eba 656 expect(video.accountName).to.equal('root')
0e1dc3e7 657 expect(video.isLocal).to.be.true
df1966c9 658 expect(video.tags).to.deep.equal([ 'supertag', 'tag1', 'tag2' ])
0e1dc3e7
C
659 expect(dateIsValid(video.createdAt)).to.be.true
660 expect(dateIsValid(video.updatedAt)).to.be.true
5f04dd2f
C
661
662 expect(video.channel.name).to.equal('Default root channel')
663 expect(video.channel.isLocal).to.be.true
664 expect(dateIsValid(video.channel.createdAt)).to.be.true
665 expect(dateIsValid(video.channel.updatedAt)).to.be.true
0e1dc3e7
C
666
667 expect(video.files).to.have.lengthOf(1)
668
669 const file = video.files[0]
670 expect(file.magnetUri).to.have.lengthOf.above(2)
14d3270f
C
671 expect(file.resolution).to.equal(720)
672 expect(file.resolutionLabel).to.equal('720p')
0e1dc3e7
C
673 expect(file.size).to.equal(292677)
674 })
675
676 it('Should like a video', async function () {
677 await rateVideo(server.url, server.accessToken, videoId, 'like')
678
679 const res = await getVideo(server.url, videoId)
680 const video = res.body
681
682 expect(video.likes).to.equal(1)
683 expect(video.dislikes).to.equal(0)
684 })
685
686 it('Should dislike the same video', async function () {
687 await rateVideo(server.url, server.accessToken, videoId, 'dislike')
688
689 const res = await getVideo(server.url, videoId)
690 const video = res.body
691
692 expect(video.likes).to.equal(0)
693 expect(video.dislikes).to.equal(1)
694 })
695
696 after(async function () {
697 killallServers([ server ])
698
699 // Keep the logs if the test failed
700 if (this['ok']) {
701 await flushTests()
702 }
703 })
704})