From 91cc839af88730ba55f84997c56b85ea100070a7 Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Thu, 12 Jan 2017 13:08:47 +0100 Subject: Server: fix single pod tests --- server/models/video.js | 2 +- server/tests/api/single-pod.js | 52 +++++++++++++++++++--------------------- server/tests/utils/videos.js | 54 +++++++++++++++++++++++++++--------------- 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 () { author: this.Author.name, duration: this.duration, tags: map(this.Tags, 'name'), - thumbnailPath: constants.STATIC_PATHS.THUMBNAILS + '/' + this.getThumbnailName(), + thumbnailPath: pathUtils.join(constants.STATIC_PATHS.THUMBNAILS, this.getThumbnailName()), createdAt: this.createdAt, updatedAt: this.updatedAt } 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 () { }) it('Should list only the two first videos', function (done) { - videosUtils.getVideosListPagination(server.url, 0, 2, function (err, res) { + videosUtils.getVideosListPagination(server.url, 0, 2, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(2) - expect(videos[0].name === videosListBase[0].name) - expect(videos[1].name === videosListBase[1].name) + expect(videos[0].name).to.equal(videosListBase[0].name) + expect(videos[1].name).to.equal(videosListBase[1].name) done() }) }) it('Should list only the next three videos', function (done) { - videosUtils.getVideosListPagination(server.url, 2, 3, function (err, res) { + videosUtils.getVideosListPagination(server.url, 2, 3, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(3) - expect(videos[0].name === videosListBase[2].name) - expect(videos[1].name === videosListBase[3].name) - expect(videos[2].name === videosListBase[4].name) + expect(videos[0].name).to.equal(videosListBase[2].name) + expect(videos[1].name).to.equal(videosListBase[3].name) + expect(videos[2].name).to.equal(videosListBase[4].name) done() }) }) it('Should list the last video', function (done) { - videosUtils.getVideosListPagination(server.url, 5, 6, function (err, res) { + videosUtils.getVideosListPagination(server.url, 5, 6, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(1) - expect(videos[0].name === videosListBase[5].name) + expect(videos[0].name).to.equal(videosListBase[5].name) done() }) }) it('Should search the first video', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, function (err, res) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 0, 1, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(4) expect(videos.length).to.equal(1) - expect(videos[0].name === 'video_short.webm name') + expect(videos[0].name).to.equal('video_short1.webm name') done() }) }) it('Should search the last two videos', function (done) { - videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, function (err, res) { + videosUtils.searchVideoWithPagination(server.url, 'webm', 'name', 2, 2, 'name', function (err, res) { if (err) throw err const videos = res.body.data expect(res.body.total).to.equal(4) expect(videos.length).to.equal(2) - expect(videos[0].name === 'video_short2.webm name') - expect(videos[1].name === 'video_short3.webm name') + expect(videos[0].name).to.equal('video_short3.webm name') + expect(videos[1].name).to.equal('video_short.webm name') done() }) @@ -476,12 +476,12 @@ describe('Test a single pod', function () { const videos = res.body.data expect(res.body.total).to.equal(6) expect(videos.length).to.equal(6) - expect(videos[5].name === 'video_short.mp4 name') - expect(videos[4].name === 'video_short.ogv name') - expect(videos[3].name === 'video_short.webm name') - expect(videos[2].name === 'video_short1.webm name') - expect(videos[1].name === 'video_short2.webm name') - expect(videos[0].name === 'video_short3.webm name') + expect(videos[0].name).to.equal('video_short.webm name') + expect(videos[1].name).to.equal('video_short.ogv name') + expect(videos[2].name).to.equal('video_short.mp4 name') + expect(videos[3].name).to.equal('video_short3.webm name') + expect(videos[4].name).to.equal('video_short2.webm name') + expect(videos[5].name).to.equal('video_short1.webm name') done() }) @@ -495,12 +495,12 @@ describe('Test a single pod', function () { expect(res.body.total).to.equal(4) expect(videos.length).to.equal(4) - expect(videos[0].name === 'video_short.webm name') - expect(videos[1].name === 'video_short1.webm name') - expect(videos[2].name === 'video_short2.webm name') - expect(videos[3].name === 'video_short3.webm name') + expect(videos[0].name).to.equal('video_short1.webm name') + expect(videos[1].name).to.equal('video_short2.webm name') + expect(videos[2].name).to.equal('video_short3.webm name') + expect(videos[3].name).to.equal('video_short.webm name') - videoId = videos[3].id + videoId = videos[2].id done() }) @@ -535,8 +535,6 @@ describe('Test a single pod', function () { if (err) throw err expect(test).to.equal(true) - videoId = video.id - webtorrent.add(video.magnetUri, function (torrent) { expect(torrent.files).to.exist 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) { .end(end) } -function getVideosListPagination (url, start, count, end) { +function getVideosListPagination (url, start, count, sort, end) { + if (!end) { + end = sort + sort = null + } + const path = '/api/v1/videos' - request(url) - .get(path) - .query({ start: start }) - .query({ count: count }) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(end) + const req = request(url) + .get(path) + .query({ start: start }) + .query({ count: count }) + + if (sort) req.query({ sort }) + + req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) } function getVideosListSort (url, sort, end) { @@ -116,18 +124,26 @@ function searchVideo (url, search, field, end) { .end(end) } -function searchVideoWithPagination (url, search, field, start, count, end) { +function searchVideoWithPagination (url, search, field, start, count, sort, end) { + if (!end) { + end = sort + sort = null + } + const path = '/api/v1/videos' - request(url) - .get(path + '/search/' + search) - .query({ start: start }) - .query({ count: count }) - .query({ field: field }) - .set('Accept', 'application/json') - .expect(200) - .expect('Content-Type', /json/) - .end(end) + const req = request(url) + .get(path + '/search/' + search) + .query({ start: start }) + .query({ count: count }) + .query({ field: field }) + + if (sort) req.query({ sort }) + + req.set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) } function searchVideoWithSort (url, search, sort, end) { -- cgit v1.2.3