]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/single-pod.js
Fix david-dm badge links
[github/Chocobozzz/PeerTube.git] / server / tests / api / single-pod.js
CommitLineData
72329aaa
C
1/* eslint-disable no-unused-expressions */
2
9f10b292
C
3'use strict'
4
f0f5567b 5const chai = require('chai')
1a42c9e2 6const each = require('async/each')
f0f5567b
C
7const expect = chai.expect
8const fs = require('fs')
3a8a8b51 9const keyBy = require('lodash/keyBy')
f0f5567b 10const pathUtils = require('path')
1a42c9e2 11const series = require('async/series')
bf94b6f0 12const webtorrent = new (require('webtorrent'))()
9f10b292 13
8d309058
C
14const loginUtils = require('../utils/login')
15const miscsUtils = require('../utils/miscs')
16const serversUtils = require('../utils/servers')
17const videosUtils = require('../utils/videos')
9f10b292 18
9f10b292 19describe('Test a single pod', function () {
0c1cbbfe 20 let server = null
bc503c2a 21 let videoId = -1
fbf1134e 22 let videosListBase = null
9f10b292
C
23
24 before(function (done) {
25 this.timeout(20000)
26
1a42c9e2 27 series([
9f10b292 28 function (next) {
8d309058 29 serversUtils.flushTests(next)
9f10b292
C
30 },
31 function (next) {
8d309058 32 serversUtils.runServer(1, function (server1) {
0c1cbbfe
C
33 server = server1
34 next()
35 })
36 },
37 function (next) {
8d309058 38 loginUtils.loginAndGetAccessToken(server, function (err, token) {
0c1cbbfe 39 if (err) throw err
b6c6f935 40 server.accessToken = token
9f10b292
C
41 next()
42 })
9f10b292
C
43 }
44 ], done)
45 })
8c308c2b 46
6e07c3de
C
47 it('Should list video categories', function (done) {
48 videosUtils.getVideoCategories(server.url, function (err, res) {
49 if (err) throw err
50
51 const categories = res.body
52 expect(Object.keys(categories)).to.have.length.above(10)
53
54 expect(categories[11]).to.equal('News')
55
56 done()
57 })
58 })
59
9f10b292 60 it('Should not have videos', function (done) {
8d309058 61 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 62 if (err) throw err
8c308c2b 63
68ce3ae0
C
64 expect(res.body.total).to.equal(0)
65 expect(res.body.data).to.be.an('array')
66 expect(res.body.data.length).to.equal(0)
8c308c2b 67
9f10b292 68 done()
8c308c2b 69 })
9f10b292 70 })
8c308c2b 71
9f10b292 72 it('Should upload the video', function (done) {
b4c5ac97
C
73 const videoAttributes = {
74 name: 'my super name',
75 category: 2,
76 tags: [ 'tag1', 'tag2', 'tag3' ]
77 }
78 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, done)
9f10b292 79 })
8c308c2b 80
9f10b292
C
81 it('Should seed the uploaded video', function (done) {
82 // Yes, this could be long
83 this.timeout(60000)
8c308c2b 84
8d309058 85 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 86 if (err) throw err
8c308c2b 87
68ce3ae0
C
88 expect(res.body.total).to.equal(1)
89 expect(res.body.data).to.be.an('array')
90 expect(res.body.data.length).to.equal(1)
8c308c2b 91
68ce3ae0 92 const video = res.body.data[0]
9f10b292 93 expect(video.name).to.equal('my super name')
6e07c3de
C
94 expect(video.category).to.equal(2)
95 expect(video.categoryLabel).to.equal('Films')
9f10b292 96 expect(video.description).to.equal('my super description')
a4254ea1 97 expect(video.podHost).to.equal('localhost:9001')
9f10b292 98 expect(video.magnetUri).to.exist
6d8ada5f
C
99 expect(video.author).to.equal('root')
100 expect(video.isLocal).to.be.true
be587647 101 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
feb4bdfd 102 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 103 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
8c308c2b 104
8d309058 105 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
106 if (err) throw err
107 expect(test).to.equal(true)
2df82d42 108
bc503c2a 109 videoId = video.id
2df82d42 110
9e5f3740
C
111 webtorrent.add(video.magnetUri, function (torrent) {
112 expect(torrent.files).to.exist
113 expect(torrent.files.length).to.equal(1)
114 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
115
790e65fc 116 done()
9e5f3740 117 })
2df82d42
C
118 })
119 })
120 })
121
122 it('Should get the video', function (done) {
123 // Yes, this could be long
124 this.timeout(60000)
125
8d309058 126 videosUtils.getVideo(server.url, videoId, function (err, res) {
2df82d42
C
127 if (err) throw err
128
129 const video = res.body
130 expect(video.name).to.equal('my super name')
6e07c3de
C
131 expect(video.category).to.equal(2)
132 expect(video.categoryLabel).to.equal('Films')
2df82d42 133 expect(video.description).to.equal('my super description')
a4254ea1 134 expect(video.podHost).to.equal('localhost:9001')
2df82d42 135 expect(video.magnetUri).to.exist
6d8ada5f
C
136 expect(video.author).to.equal('root')
137 expect(video.isLocal).to.be.true
be587647 138 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
feb4bdfd 139 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 140 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
8c308c2b 141
8d309058 142 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
143 if (err) throw err
144 expect(test).to.equal(true)
8c308c2b 145
ede4db9e 146 done()
876d1bcf 147 })
8c308c2b 148 })
9f10b292 149 })
8c308c2b 150
9e167724
C
151 it('Should have the views updated', function (done) {
152 videosUtils.getVideo(server.url, videoId, function (err, res) {
153 if (err) throw err
154
155 const video = res.body
156 expect(video.views).to.equal(1)
157
158 done()
159 })
160 })
161
46246b5f 162 it('Should search the video by name by default', function (done) {
8d309058 163 videosUtils.searchVideo(server.url, 'my', function (err, res) {
9f10b292 164 if (err) throw err
4d5f8138 165
68ce3ae0
C
166 expect(res.body.total).to.equal(1)
167 expect(res.body.data).to.be.an('array')
168 expect(res.body.data.length).to.equal(1)
4d5f8138 169
68ce3ae0 170 const video = res.body.data[0]
9f10b292 171 expect(video.name).to.equal('my super name')
6e07c3de
C
172 expect(video.category).to.equal(2)
173 expect(video.categoryLabel).to.equal('Films')
9f10b292 174 expect(video.description).to.equal('my super description')
a4254ea1 175 expect(video.podHost).to.equal('localhost:9001')
6d8ada5f
C
176 expect(video.author).to.equal('root')
177 expect(video.isLocal).to.be.true
be587647 178 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
feb4bdfd 179 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 180 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
4d5f8138 181
8d309058 182 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
9e5f3740
C
183 if (err) throw err
184 expect(test).to.equal(true)
185
186 done()
187 })
4d5f8138 188 })
9f10b292 189 })
4d5f8138 190
7920c273
C
191 // Not implemented yet
192 // it('Should search the video by podHost', function (done) {
193 // videosUtils.searchVideo(server.url, '9001', 'host', function (err, res) {
194 // if (err) throw err
195
196 // expect(res.body.total).to.equal(1)
197 // expect(res.body.data).to.be.an('array')
198 // expect(res.body.data.length).to.equal(1)
199
200 // const video = res.body.data[0]
201 // expect(video.name).to.equal('my super name')
202 // expect(video.description).to.equal('my super description')
203 // expect(video.podHost).to.equal('localhost:9001')
204 // expect(video.author).to.equal('root')
205 // expect(video.isLocal).to.be.true
206 // expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
207 // expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 208 // expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
7920c273
C
209
210 // videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
211 // if (err) throw err
212 // expect(test).to.equal(true)
213
214 // done()
215 // })
216 // })
217 // })
46246b5f 218
8d199cb8 219 it('Should search the video by tag', function (done) {
8d309058 220 videosUtils.searchVideo(server.url, 'tag1', 'tags', function (err, res) {
8d199cb8
C
221 if (err) throw err
222
223 expect(res.body.total).to.equal(1)
224 expect(res.body.data).to.be.an('array')
225 expect(res.body.data.length).to.equal(1)
226
227 const video = res.body.data[0]
228 expect(video.name).to.equal('my super name')
6e07c3de
C
229 expect(video.category).to.equal(2)
230 expect(video.categoryLabel).to.equal('Films')
8d199cb8 231 expect(video.description).to.equal('my super description')
a4254ea1 232 expect(video.podHost).to.equal('localhost:9001')
8d199cb8
C
233 expect(video.author).to.equal('root')
234 expect(video.isLocal).to.be.true
235 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
feb4bdfd 236 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 237 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
8d199cb8 238
8d309058 239 videosUtils.testVideoImage(server.url, 'video_short.webm', video.thumbnailPath, function (err, test) {
8d199cb8
C
240 if (err) throw err
241 expect(test).to.equal(true)
242
243 done()
244 })
245 })
246 })
247
46246b5f 248 it('Should not find a search by name by default', function (done) {
8d309058 249 videosUtils.searchVideo(server.url, 'hello', function (err, res) {
9f10b292 250 if (err) throw err
4d5f8138 251
68ce3ae0
C
252 expect(res.body.total).to.equal(0)
253 expect(res.body.data).to.be.an('array')
254 expect(res.body.data.length).to.equal(0)
4d5f8138 255
9f10b292 256 done()
4d5f8138 257 })
9f10b292 258 })
4d5f8138 259
46246b5f 260 it('Should not find a search by author', function (done) {
8d309058 261 videosUtils.searchVideo(server.url, 'hello', 'author', function (err, res) {
46246b5f
C
262 if (err) throw err
263
264 expect(res.body.total).to.equal(0)
265 expect(res.body.data).to.be.an('array')
266 expect(res.body.data.length).to.equal(0)
267
268 done()
269 })
270 })
271
8d199cb8 272 it('Should not find a search by tag', function (done) {
7920c273 273 videosUtils.searchVideo(server.url, 'hello', 'tags', function (err, res) {
8d199cb8
C
274 if (err) throw err
275
276 expect(res.body.total).to.equal(0)
277 expect(res.body.data).to.be.an('array')
278 expect(res.body.data.length).to.equal(0)
279
280 done()
281 })
282 })
283
9f10b292 284 it('Should remove the video', function (done) {
8d309058 285 videosUtils.removeVideo(server.url, server.accessToken, videoId, function (err) {
9f10b292 286 if (err) throw err
f5a60a51 287
15103f11 288 fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/videos/'), function (err, files) {
9f10b292 289 if (err) throw err
f5a60a51 290
9f10b292 291 expect(files.length).to.equal(0)
b3d92510 292
15103f11 293 fs.readdir(pathUtils.join(__dirname, '..', '..', '..', 'test1/thumbnails/'), function (err, files) {
b3d92510
C
294 if (err) throw err
295
296 expect(files.length).to.equal(0)
297
298 done()
299 })
876d1bcf 300 })
8c308c2b 301 })
9f10b292 302 })
8c308c2b 303
9f10b292 304 it('Should not have videos', function (done) {
8d309058 305 videosUtils.getVideosList(server.url, function (err, res) {
9f10b292 306 if (err) throw err
8c308c2b 307
68ce3ae0
C
308 expect(res.body.total).to.equal(0)
309 expect(res.body.data).to.be.an('array')
310 expect(res.body.data.length).to.equal(0)
8c308c2b 311
9f10b292 312 done()
8c308c2b 313 })
9f10b292 314 })
8c308c2b 315
3a8a8b51
C
316 it('Should upload 6 videos', function (done) {
317 this.timeout(25000)
318 const videos = [
319 'video_short.mp4', 'video_short.ogv', 'video_short.webm',
320 'video_short1.webm', 'video_short2.webm', 'video_short3.webm'
321 ]
1a42c9e2 322 each(videos, function (video, callbackEach) {
b4c5ac97
C
323 const videoAttributes = {
324 name: video + ' name',
325 description: video + ' description',
326 category: 2,
327 tags: [ 'tag1', 'tag2', 'tag3' ],
328 fixture: video
329 }
be587647 330
b4c5ac97 331 videosUtils.uploadVideo(server.url, server.accessToken, videoAttributes, callbackEach)
3a8a8b51
C
332 }, done)
333 })
334
335 it('Should have the correct durations', function (done) {
8d309058 336 videosUtils.getVideosList(server.url, function (err, res) {
3a8a8b51
C
337 if (err) throw err
338
68ce3ae0
C
339 expect(res.body.total).to.equal(6)
340 const videos = res.body.data
3a8a8b51
C
341 expect(videos).to.be.an('array')
342 expect(videos.length).to.equal(6)
343
bc503c2a
C
344 const videosByName = keyBy(videos, 'name')
345 expect(videosByName['video_short.mp4 name'].duration).to.equal(5)
346 expect(videosByName['video_short.ogv name'].duration).to.equal(5)
347 expect(videosByName['video_short.webm name'].duration).to.equal(5)
348 expect(videosByName['video_short1.webm name'].duration).to.equal(10)
349 expect(videosByName['video_short2.webm name'].duration).to.equal(5)
350 expect(videosByName['video_short3.webm name'].duration).to.equal(5)
3a8a8b51
C
351
352 done()
353 })
354 })
355
9e5f3740 356 it('Should have the correct thumbnails', function (done) {
8d309058 357 videosUtils.getVideosList(server.url, function (err, res) {
fbf1134e
C
358 if (err) throw err
359
68ce3ae0 360 const videos = res.body.data
fbf1134e
C
361 // For the next test
362 videosListBase = videos
9e5f3740 363
1a42c9e2 364 each(videos, function (video, callbackEach) {
9e5f3740 365 if (err) throw err
bc503c2a 366 const videoName = video.name.replace(' name', '')
9e5f3740 367
8d309058 368 videosUtils.testVideoImage(server.url, videoName, video.thumbnailPath, function (err, test) {
9e5f3740
C
369 if (err) throw err
370
371 expect(test).to.equal(true)
bc503c2a 372 callbackEach()
9e5f3740
C
373 })
374 }, done)
375 })
376 })
377
fbf1134e 378 it('Should list only the two first videos', function (done) {
91cc839a 379 videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) {
fbf1134e
C
380 if (err) throw err
381
68ce3ae0
C
382 const videos = res.body.data
383 expect(res.body.total).to.equal(6)
fbf1134e 384 expect(videos.length).to.equal(2)
91cc839a
C
385 expect(videos[0].name).to.equal(videosListBase[0].name)
386 expect(videos[1].name).to.equal(videosListBase[1].name)
fbf1134e
C
387
388 done()
389 })
390 })
391
392 it('Should list only the next three videos', function (done) {
91cc839a 393 videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) {
fbf1134e
C
394 if (err) throw err
395
68ce3ae0
C
396 const videos = res.body.data
397 expect(res.body.total).to.equal(6)
022856f8 398 expect(videos.length).to.equal(3)
91cc839a
C
399 expect(videos[0].name).to.equal(videosListBase[2].name)
400 expect(videos[1].name).to.equal(videosListBase[3].name)
401 expect(videos[2].name).to.equal(videosListBase[4].name)
fbf1134e
C
402
403 done()
404 })
405 })
406
407 it('Should list the last video', function (done) {
91cc839a 408 videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) {
fbf1134e
C
409 if (err) throw err
410
68ce3ae0
C
411 const videos = res.body.data
412 expect(res.body.total).to.equal(6)
fbf1134e 413 expect(videos.length).to.equal(1)
91cc839a 414 expect(videos[0].name).to.equal(videosListBase[5].name)
fbf1134e
C
415
416 done()
417 })
418 })
419
420 it('Should search the first video', function (done) {
91cc839a 421 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) {
fbf1134e
C
422 if (err) throw err
423
68ce3ae0
C
424 const videos = res.body.data
425 expect(res.body.total).to.equal(4)
fbf1134e 426 expect(videos.length).to.equal(1)
91cc839a 427 expect(videos[0].name).to.equal('video_short1.webm name')
fbf1134e
C
428
429 done()
430 })
431 })
432
433 it('Should search the last two videos', function (done) {
91cc839a 434 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) {
fbf1134e
C
435 if (err) throw err
436
68ce3ae0
C
437 const videos = res.body.data
438 expect(res.body.total).to.equal(4)
fbf1134e 439 expect(videos.length).to.equal(2)
91cc839a
C
440 expect(videos[0].name).to.equal('video_short3.webm name')
441 expect(videos[1].name).to.equal('video_short.webm name')
fbf1134e
C
442
443 done()
444 })
445 })
446
46246b5f 447 it('Should search all the webm videos', function (done) {
8d309058 448 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 15, function (err, res) {
fbf1134e
C
449 if (err) throw err
450
68ce3ae0
C
451 const videos = res.body.data
452 expect(res.body.total).to.equal(4)
fbf1134e
C
453 expect(videos.length).to.equal(4)
454
455 done()
456 })
457 })
458
46246b5f 459 it('Should search all the root author videos', function (done) {
8d309058 460 videosUtils.searchVideoWithPagination(server.url, 'root', 'author', 0, 15, function (err, res) {
46246b5f
C
461 if (err) throw err
462
463 const videos = res.body.data
464 expect(res.body.total).to.equal(6)
465 expect(videos.length).to.equal(6)
466
467 done()
468 })
469 })
470
7920c273
C
471 // Not implemented yet
472 // it('Should search all the 9001 port videos', function (done) {
473 // videosUtils.searchVideoWithPagination(server.url, '9001', 'host', 0, 15, function (err, res) {
474 // if (err) throw err
46246b5f 475
7920c273
C
476 // const videos = res.body.data
477 // expect(res.body.total).to.equal(6)
478 // expect(videos.length).to.equal(6)
46246b5f 479
7920c273
C
480 // done()
481 // })
482 // })
46246b5f 483
7920c273
C
484 // it('Should search all the localhost videos', function (done) {
485 // videosUtils.searchVideoWithPagination(server.url, 'localhost', 'host', 0, 15, function (err, res) {
486 // if (err) throw err
46246b5f 487
7920c273
C
488 // const videos = res.body.data
489 // expect(res.body.total).to.equal(6)
490 // expect(videos.length).to.equal(6)
46246b5f 491
7920c273
C
492 // done()
493 // })
494 // })
46246b5f 495
6e07c3de 496 it('Should search the right magnetUri video', function (done) {
46246b5f 497 const video = videosListBase[0]
8d309058 498 videosUtils.searchVideoWithPagination(server.url, encodeURIComponent(video.magnetUri), 'magnetUri', 0, 15, function (err, res) {
46246b5f
C
499 if (err) throw err
500
501 const videos = res.body.data
502 expect(res.body.total).to.equal(1)
503 expect(videos.length).to.equal(1)
504 expect(videos[0].name).to.equal(video.name)
505
506 done()
507 })
508 })
509
a877d5ac 510 it('Should list and sort by name in descending order', function (done) {
8d309058 511 videosUtils.getVideosListSort(server.url, '-name', function (err, res) {
a877d5ac
C
512 if (err) throw err
513
68ce3ae0
C
514 const videos = res.body.data
515 expect(res.body.total).to.equal(6)
a877d5ac 516 expect(videos.length).to.equal(6)
91cc839a
C
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')
a877d5ac
C
523
524 done()
525 })
526 })
527
528 it('Should search and sort by name in ascending order', function (done) {
8d309058 529 videosUtils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
a877d5ac
C
530 if (err) throw err
531
68ce3ae0
C
532 const videos = res.body.data
533 expect(res.body.total).to.equal(4)
a877d5ac
C
534 expect(videos.length).to.equal(4)
535
91cc839a
C
536 expect(videos[0].name).to.equal('video_short1.webm name')
537 expect(videos[1].name).to.equal('video_short2.webm name')
538 expect(videos[2].name).to.equal('video_short3.webm name')
539 expect(videos[3].name).to.equal('video_short.webm name')
a877d5ac 540
91cc839a 541 videoId = videos[2].id
7b1f49de 542
a877d5ac
C
543 done()
544 })
545 })
546
7b1f49de 547 it('Should update a video', function (done) {
b4c5ac97
C
548 const attributes = {
549 name: 'my super video updated',
550 category: 4,
551 description: 'my super description updated',
552 tags: [ 'tagup1', 'tagup2' ]
553 }
554 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, done)
7b1f49de
C
555 })
556
557 it('Should have the video updated', function (done) {
7f4e7c36
C
558 this.timeout(60000)
559
7b1f49de
C
560 videosUtils.getVideo(server.url, videoId, function (err, res) {
561 if (err) throw err
562
563 const video = res.body
564
565 expect(video.name).to.equal('my super video updated')
6e07c3de
C
566 expect(video.category).to.equal(4)
567 expect(video.categoryLabel).to.equal('Art')
7b1f49de
C
568 expect(video.description).to.equal('my super description updated')
569 expect(video.podHost).to.equal('localhost:9001')
570 expect(video.author).to.equal('root')
571 expect(video.isLocal).to.be.true
572 expect(video.tags).to.deep.equal([ 'tagup1', 'tagup2' ])
573 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 574 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
7b1f49de 575
7f4e7c36
C
576 videosUtils.testVideoImage(server.url, 'video_short3.webm', video.thumbnailPath, function (err, test) {
577 if (err) throw err
578 expect(test).to.equal(true)
579
7f4e7c36
C
580 webtorrent.add(video.magnetUri, function (torrent) {
581 expect(torrent.files).to.exist
582 expect(torrent.files.length).to.equal(1)
583 expect(torrent.files[0].path).to.exist.and.to.not.equal('')
584
585 done()
586 })
587 })
7b1f49de
C
588 })
589 })
590
591 it('Should update only the tags of a video', function (done) {
b4c5ac97
C
592 const attributes = {
593 tags: [ 'tag1', 'tag2', 'supertag' ]
594 }
7b1f49de 595
b4c5ac97 596 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
7b1f49de
C
597 if (err) throw err
598
599 videosUtils.getVideo(server.url, videoId, function (err, res) {
600 if (err) throw err
601
602 const video = res.body
603
604 expect(video.name).to.equal('my super video updated')
6e07c3de
C
605 expect(video.category).to.equal(4)
606 expect(video.categoryLabel).to.equal('Art')
7b1f49de
C
607 expect(video.description).to.equal('my super description updated')
608 expect(video.podHost).to.equal('localhost:9001')
609 expect(video.author).to.equal('root')
610 expect(video.isLocal).to.be.true
611 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
612 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 613 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
7b1f49de
C
614
615 done()
616 })
617 })
618 })
619
620 it('Should update only the description of a video', function (done) {
b4c5ac97
C
621 const attributes = {
622 description: 'hello everybody'
623 }
7b1f49de 624
b4c5ac97 625 videosUtils.updateVideo(server.url, server.accessToken, videoId, attributes, function (err) {
7b1f49de
C
626 if (err) throw err
627
628 videosUtils.getVideo(server.url, videoId, function (err, res) {
629 if (err) throw err
630
631 const video = res.body
632
633 expect(video.name).to.equal('my super video updated')
6e07c3de
C
634 expect(video.category).to.equal(4)
635 expect(video.categoryLabel).to.equal('Art')
7b1f49de
C
636 expect(video.description).to.equal('hello everybody')
637 expect(video.podHost).to.equal('localhost:9001')
638 expect(video.author).to.equal('root')
639 expect(video.isLocal).to.be.true
640 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'supertag' ])
641 expect(miscsUtils.dateIsValid(video.createdAt)).to.be.true
79066fdf 642 expect(miscsUtils.dateIsValid(video.updatedAt)).to.be.true
7b1f49de
C
643
644 done()
645 })
646 })
647 })
648
d38b8281
C
649 it('Should like a video', function (done) {
650 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'like', function (err) {
651 if (err) throw err
652
653 videosUtils.getVideo(server.url, videoId, function (err, res) {
654 if (err) throw err
655
656 const video = res.body
657
658 expect(video.likes).to.equal(1)
659 expect(video.dislikes).to.equal(0)
660
661 done()
662 })
663 })
664 })
665
666 it('Should dislike the same video', function (done) {
667 videosUtils.rateVideo(server.url, server.accessToken, videoId, 'dislike', function (err) {
668 if (err) throw err
669
670 videosUtils.getVideo(server.url, videoId, function (err, res) {
671 if (err) throw err
672
673 const video = res.body
674
675 expect(video.likes).to.equal(0)
676 expect(video.dislikes).to.equal(1)
677
678 done()
679 })
680 })
681 })
682
9f10b292 683 after(function (done) {
0c1cbbfe 684 process.kill(-server.app.pid)
8c308c2b 685
9f10b292
C
686 // Keep the logs if the test failed
687 if (this.ok) {
8d309058 688 serversUtils.flushTests(done)
9f10b292
C
689 } else {
690 done()
691 }
8c308c2b 692 })
9f10b292 693})