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