aboutsummaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-01-12 13:08:47 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-01-12 13:08:47 +0100
commit91cc839af88730ba55f84997c56b85ea100070a7 (patch)
tree2c9f5917370c3674e268234e76082f90c9244088
parent790e65fcf7a0a9f065ecc68c5982efb80cd2e1ca (diff)
downloadPeerTube-91cc839af88730ba55f84997c56b85ea100070a7.tar.gz
PeerTube-91cc839af88730ba55f84997c56b85ea100070a7.tar.zst
PeerTube-91cc839af88730ba55f84997c56b85ea100070a7.zip
Server: fix single pod tests
-rw-r--r--server/models/video.js2
-rw-r--r--server/tests/api/single-pod.js52
-rw-r--r--server/tests/utils/videos.js54
3 files changed, 61 insertions, 47 deletions
diff --git a/server/models/video.js b/server/models/video.js
index ceed976b0..17eff6428 100644
--- a/server/models/video.js
+++ b/server/models/video.js
@@ -335,7 +335,7 @@ function toFormatedJSON () {
335 author: this.Author.name, 335 author: this.Author.name,
336 duration: this.duration, 336 duration: this.duration,
337 tags: map(this.Tags, 'name'), 337 tags: map(this.Tags, 'name'),
338 thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(), 338 thumbnailPath: pathUtils.join(constants.STATIC_PATHS.THUMBNAILS, this.getThumbnailName()),
339 createdAt: this.createdAt, 339 createdAt: this.createdAt,
340 updatedAt: this.updatedAt 340 updatedAt: this.updatedAt
341 } 341 }
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 2ac83bbf4..2db60448f 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -338,69 +338,69 @@ describe('Test a single pod', function () {
338 }) 338 })
339 339
340 it('Should list only the two first videos', function (done) { 340 it('Should list only the two first videos', function (done) {
341 videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) { 341 videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) {
342 if (err) throw err 342 if (err) throw err
343 343
344 const videos = res.body.data 344 const videos = res.body.data
345 expect(res.body.total).to.equal(6) 345 expect(res.body.total).to.equal(6)
346 expect(videos.length).to.equal(2) 346 expect(videos.length).to.equal(2)
347 expect(videos[0].name === videosListBase[0].name) 347 expect(videos[0].name).to.equal(videosListBase[0].name)
348 expect(videos[1].name === videosListBase[1].name) 348 expect(videos[1].name).to.equal(videosListBase[1].name)
349 349
350 done() 350 done()
351 }) 351 })
352 }) 352 })
353 353
354 it('Should list only the next three videos', function (done) { 354 it('Should list only the next three videos', function (done) {
355 videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) { 355 videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) {
356 if (err) throw err 356 if (err) throw err
357 357
358 const videos = res.body.data 358 const videos = res.body.data
359 expect(res.body.total).to.equal(6) 359 expect(res.body.total).to.equal(6)
360 expect(videos.length).to.equal(3) 360 expect(videos.length).to.equal(3)
361 expect(videos[0].name === videosListBase[2].name) 361 expect(videos[0].name).to.equal(videosListBase[2].name)
362 expect(videos[1].name === videosListBase[3].name) 362 expect(videos[1].name).to.equal(videosListBase[3].name)
363 expect(videos[2].name === videosListBase[4].name) 363 expect(videos[2].name).to.equal(videosListBase[4].name)
364 364
365 done() 365 done()
366 }) 366 })
367 }) 367 })
368 368
369 it('Should list the last video', function (done) { 369 it('Should list the last video', function (done) {
370 videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) { 370 videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) {
371 if (err) throw err 371 if (err) throw err
372 372
373 const videos = res.body.data 373 const videos = res.body.data
374 expect(res.body.total).to.equal(6) 374 expect(res.body.total).to.equal(6)
375 expect(videos.length).to.equal(1) 375 expect(videos.length).to.equal(1)
376 expect(videos[0].name === videosListBase[5].name) 376 expect(videos[0].name).to.equal(videosListBase[5].name)
377 377
378 done() 378 done()
379 }) 379 })
380 }) 380 })
381 381
382 it('Should search the first video', function (done) { 382 it('Should search the first video', function (done) {
383 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { 383 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) {
384 if (err) throw err 384 if (err) throw err
385 385
386 const videos = res.body.data 386 const videos = res.body.data
387 expect(res.body.total).to.equal(4) 387 expect(res.body.total).to.equal(4)
388 expect(videos.length).to.equal(1) 388 expect(videos.length).to.equal(1)
389 expect(videos[0].name === 'video_short.webm name') 389 expect(videos[0].name).to.equal('video_short1.webm name')
390 390
391 done() 391 done()
392 }) 392 })
393 }) 393 })
394 394
395 it('Should search the last two videos', function (done) { 395 it('Should search the last two videos', function (done) {
396 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { 396 videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) {
397 if (err) throw err 397 if (err) throw err
398 398
399 const videos = res.body.data 399 const videos = res.body.data
400 expect(res.body.total).to.equal(4) 400 expect(res.body.total).to.equal(4)
401 expect(videos.length).to.equal(2) 401 expect(videos.length).to.equal(2)
402 expect(videos[0].name === 'video_short2.webm name') 402 expect(videos[0].name).to.equal('video_short3.webm name')
403 expect(videos[1].name === 'video_short3.webm name') 403 expect(videos[1].name).to.equal('video_short.webm name')
404 404
405 done() 405 done()
406 }) 406 })
@@ -476,12 +476,12 @@ describe('Test a single pod', function () {
476 const videos = res.body.data 476 const videos = res.body.data
477 expect(res.body.total).to.equal(6) 477 expect(res.body.total).to.equal(6)
478 expect(videos.length).to.equal(6) 478 expect(videos.length).to.equal(6)
479 expect(videos[5].name === 'video_short.mp4 name') 479 expect(videos[0].name).to.equal('video_short.webm name')
480 expect(videos[4].name === 'video_short.ogv name') 480 expect(videos[1].name).to.equal('video_short.ogv name')
481 expect(videos[3].name === 'video_short.webm name') 481 expect(videos[2].name).to.equal('video_short.mp4 name')
482 expect(videos[2].name === 'video_short1.webm name') 482 expect(videos[3].name).to.equal('video_short3.webm name')
483 expect(videos[1].name === 'video_short2.webm name') 483 expect(videos[4].name).to.equal('video_short2.webm name')
484 expect(videos[0].name === 'video_short3.webm name') 484 expect(videos[5].name).to.equal('video_short1.webm name')
485 485
486 done() 486 done()
487 }) 487 })
@@ -495,12 +495,12 @@ describe('Test a single pod', function () {
495 expect(res.body.total).to.equal(4) 495 expect(res.body.total).to.equal(4)
496 expect(videos.length).to.equal(4) 496 expect(videos.length).to.equal(4)
497 497
498 expect(videos[0].name === 'video_short.webm name') 498 expect(videos[0].name).to.equal('video_short1.webm name')
499 expect(videos[1].name === 'video_short1.webm name') 499 expect(videos[1].name).to.equal('video_short2.webm name')
500 expect(videos[2].name === 'video_short2.webm name') 500 expect(videos[2].name).to.equal('video_short3.webm name')
501 expect(videos[3].name === 'video_short3.webm name') 501 expect(videos[3].name).to.equal('video_short.webm name')
502 502
503 videoId = videos[3].id 503 videoId = videos[2].id
504 504
505 done() 505 done()
506 }) 506 })
@@ -535,8 +535,6 @@ describe('Test a single pod', function () {
535 if (err) throw err 535 if (err) throw err
536 expect(test).to.equal(true) 536 expect(test).to.equal(true)
537 537
538 videoId = video.id
539
540 webtorrent.add(video.magnetUri, function (torrent) { 538 webtorrent.add(video.magnetUri, function (torrent) {
541 expect(torrent.files).to.exist 539 expect(torrent.files).to.exist
542 expect(torrent.files.length).to.equal(1) 540 expect(torrent.files.length).to.equal(1)
diff --git a/server/tests/utils/videos.js b/server/tests/utils/videos.js
index beafd3cf5..f94368437 100644
--- a/server/tests/utils/videos.js
+++ b/server/tests/utils/videos.js
@@ -58,17 +58,25 @@ function getVideosList (url, end) {
58 .end(end) 58 .end(end)
59} 59}
60 60
61function getVideosListPagination (url, start, count, end) { 61function getVideosListPagination (url, start, count, sort, end) {
62 if (!end) {
63 end = sort
64 sort = null
65 }
66
62 const path = '/api/v1/videos' 67 const path = '/api/v1/videos'
63 68
64 request(url) 69 const req = request(url)
65 .get(path) 70 .get(path)
66 .query({ start: start }) 71 .query({ start: start })
67 .query({ count: count }) 72 .query({ count: count })
68 .set('Accept', 'application/json') 73
69 .expect(200) 74 if (sort) req.query({ sort })
70 .expect('Content-Type', /json/) 75
71 .end(end) 76 req.set('Accept', 'application/json')
77 .expect(200)
78 .expect('Content-Type', /json/)
79 .end(end)
72} 80}
73 81
74function getVideosListSort (url, sort, end) { 82function getVideosListSort (url, sort, end) {
@@ -116,18 +124,26 @@ function searchVideo (url, search, field, end) {
116 .end(end) 124 .end(end)
117} 125}
118 126
119function searchVideoWithPagination (url, search, field, start, count, end) { 127function searchVideoWithPagination (url, search, field, start, count, sort, end) {
128 if (!end) {
129 end = sort
130 sort = null
131 }
132
120 const path = '/api/v1/videos' 133 const path = '/api/v1/videos'
121 134
122 request(url) 135 const req = request(url)
123 .get(path + '/search/' + search) 136 .get(path + '/search/' + search)
124 .query({ start: start }) 137 .query({ start: start })
125 .query({ count: count }) 138 .query({ count: count })
126 .query({ field: field }) 139 .query({ field: field })
127 .set('Accept', 'application/json') 140
128 .expect(200) 141 if (sort) req.query({ sort })
129 .expect('Content-Type', /json/) 142
130 .end(end) 143 req.set('Accept', 'application/json')
144 .expect(200)
145 .expect('Content-Type', /json/)
146 .end(end)
131} 147}
132 148
133function searchVideoWithSort (url, search, sort, end) { 149function searchVideoWithSort (url, search, sort, end) {