From fbf1134e3e6b386c9ec5a3946c61f3faf84397fb Mon Sep 17 00:00:00 2001 From: Chocobozzz Date: Fri, 13 May 2016 18:10:46 +0200 Subject: Introduce paginations in videos listing --- server/tests/api/singlePod.js | 80 +++++++++++++++++++++++++++++++++++++++++++ server/tests/api/utils.js | 28 +++++++++++++++ 2 files changed, 108 insertions(+) (limited to 'server/tests/api') diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js index 0d0e6a82e..d377bdf45 100644 --- a/server/tests/api/singlePod.js +++ b/server/tests/api/singlePod.js @@ -15,6 +15,7 @@ const utils = require('./utils') describe('Test a single pod', function () { let server = null let videoId = -1 + let videosListBase = null before(function (done) { this.timeout(20000) @@ -215,7 +216,11 @@ describe('Test a single pod', function () { it('Should have the correct thumbnails', function (done) { utils.getVideosList(server.url, function (err, res) { + if (err) throw err + const videos = res.body + // For the next test + videosListBase = videos async.each(videos, function (video, callbackEach) { if (err) throw err @@ -231,6 +236,81 @@ describe('Test a single pod', function () { }) }) + it('Should list only the two first videos', function (done) { + utils.getVideosListPagination(server.url, 0, 2, function (err, res) { + if (err) throw err + + const videos = res.body + expect(videos.length).to.equal(2) + expect(videos[0].name === videosListBase[0].name) + expect(videos[1].name === videosListBase[1].name) + + done() + }) + }) + + it('Should list only the next three videos', function (done) { + utils.getVideosListPagination(server.url, 2, 3, function (err, res) { + if (err) throw err + + const videos = res.body + expect(videos.length).to.equal(4) + expect(videos[0].name === videosListBase[2].name) + expect(videos[1].name === videosListBase[3].name) + expect(videos[2].name === videosListBase[4].name) + + done() + }) + }) + + it('Should list the last video', function (done) { + utils.getVideosListPagination(server.url, 5, 6, function (err, res) { + if (err) throw err + + const videos = res.body + expect(videos.length).to.equal(1) + expect(videos[0].name === videosListBase[5].name) + + done() + }) + }) + + it('Should search the first video', function (done) { + utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) { + if (err) throw err + + const videos = res.body + expect(videos.length).to.equal(1) + expect(videos[0].name === 'video_short.webm name') + + done() + }) + }) + + it('Should search the last two videos', function (done) { + utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) { + if (err) throw err + + const videos = res.body + expect(videos.length).to.equal(2) + expect(videos[0].name === 'video_short2.webm name') + expect(videos[1].name === 'video_short3.webm name') + + done() + }) + }) + + it('Should search all the videos', function (done) { + utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) { + if (err) throw err + + const videos = res.body + expect(videos.length).to.equal(4) + + done() + }) + }) + after(function (done) { process.kill(-server.app.pid) process.kill(-webtorrent.app.pid) diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index 9c5e4ee61..f0b1c3653 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js @@ -12,6 +12,7 @@ const testUtils = { getFriendsList: getFriendsList, getVideo: getVideo, getVideosList: getVideosList, + getVideosListPagination: getVideosListPagination, login: login, loginAndGetAccessToken: loginAndGetAccessToken, makeFriends: makeFriends, @@ -20,6 +21,7 @@ const testUtils = { flushAndRunMultipleServers: flushAndRunMultipleServers, runServer: runServer, searchVideo: searchVideo, + searchVideoWithPagination: searchVideoWithPagination, testImage: testImage, uploadVideo: uploadVideo } @@ -63,6 +65,19 @@ function getVideosList (url, end) { .end(end) } +function getVideosListPagination (url, start, count, end) { + 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) +} + function login (url, client, user, expectedStatus, end) { if (!end) { end = expectedStatus @@ -261,6 +276,19 @@ function searchVideo (url, search, end) { .end(end) } +function searchVideoWithPagination (url, search, start, count, end) { + const path = '/api/v1/videos' + + request(url) + .get(path + '/search/' + search) + .query({ start: start }) + .query({ count: count }) + .set('Accept', 'application/json') + .expect(200) + .expect('Content-Type', /json/) + .end(end) +} + function testImage (url, videoName, imagePath, callback) { request(url) .get(imagePath) -- cgit v1.2.3