diff options
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/singlePod.js | 80 | ||||
-rw-r--r-- | server/tests/api/utils.js | 28 |
2 files changed, 108 insertions, 0 deletions
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') | |||
15 | describe('Test a single pod', function () { | 15 | describe('Test a single pod', function () { |
16 | let server = null | 16 | let server = null |
17 | let videoId = -1 | 17 | let videoId = -1 |
18 | let videosListBase = null | ||
18 | 19 | ||
19 | before(function (done) { | 20 | before(function (done) { |
20 | this.timeout(20000) | 21 | this.timeout(20000) |
@@ -215,7 +216,11 @@ describe('Test a single pod', function () { | |||
215 | 216 | ||
216 | it('Should have the correct thumbnails', function (done) { | 217 | it('Should have the correct thumbnails', function (done) { |
217 | utils.getVideosList(server.url, function (err, res) { | 218 | utils.getVideosList(server.url, function (err, res) { |
219 | if (err) throw err | ||
220 | |||
218 | const videos = res.body | 221 | const videos = res.body |
222 | // For the next test | ||
223 | videosListBase = videos | ||
219 | 224 | ||
220 | async.each(videos, function (video, callbackEach) { | 225 | async.each(videos, function (video, callbackEach) { |
221 | if (err) throw err | 226 | if (err) throw err |
@@ -231,6 +236,81 @@ describe('Test a single pod', function () { | |||
231 | }) | 236 | }) |
232 | }) | 237 | }) |
233 | 238 | ||
239 | it('Should list only the two first videos', function (done) { | ||
240 | utils.getVideosListPagination(server.url, 0, 2, function (err, res) { | ||
241 | if (err) throw err | ||
242 | |||
243 | const videos = res.body | ||
244 | expect(videos.length).to.equal(2) | ||
245 | expect(videos[0].name === videosListBase[0].name) | ||
246 | expect(videos[1].name === videosListBase[1].name) | ||
247 | |||
248 | done() | ||
249 | }) | ||
250 | }) | ||
251 | |||
252 | it('Should list only the next three videos', function (done) { | ||
253 | utils.getVideosListPagination(server.url, 2, 3, function (err, res) { | ||
254 | if (err) throw err | ||
255 | |||
256 | const videos = res.body | ||
257 | expect(videos.length).to.equal(4) | ||
258 | expect(videos[0].name === videosListBase[2].name) | ||
259 | expect(videos[1].name === videosListBase[3].name) | ||
260 | expect(videos[2].name === videosListBase[4].name) | ||
261 | |||
262 | done() | ||
263 | }) | ||
264 | }) | ||
265 | |||
266 | it('Should list the last video', function (done) { | ||
267 | utils.getVideosListPagination(server.url, 5, 6, function (err, res) { | ||
268 | if (err) throw err | ||
269 | |||
270 | const videos = res.body | ||
271 | expect(videos.length).to.equal(1) | ||
272 | expect(videos[0].name === videosListBase[5].name) | ||
273 | |||
274 | done() | ||
275 | }) | ||
276 | }) | ||
277 | |||
278 | it('Should search the first video', function (done) { | ||
279 | utils.searchVideoWithPagination(server.url, 'webm', 0, 1, function (err, res) { | ||
280 | if (err) throw err | ||
281 | |||
282 | const videos = res.body | ||
283 | expect(videos.length).to.equal(1) | ||
284 | expect(videos[0].name === 'video_short.webm name') | ||
285 | |||
286 | done() | ||
287 | }) | ||
288 | }) | ||
289 | |||
290 | it('Should search the last two videos', function (done) { | ||
291 | utils.searchVideoWithPagination(server.url, 'webm', 2, 2, function (err, res) { | ||
292 | if (err) throw err | ||
293 | |||
294 | const videos = res.body | ||
295 | expect(videos.length).to.equal(2) | ||
296 | expect(videos[0].name === 'video_short2.webm name') | ||
297 | expect(videos[1].name === 'video_short3.webm name') | ||
298 | |||
299 | done() | ||
300 | }) | ||
301 | }) | ||
302 | |||
303 | it('Should search all the videos', function (done) { | ||
304 | utils.searchVideoWithPagination(server.url, 'webm', 0, 15, function (err, res) { | ||
305 | if (err) throw err | ||
306 | |||
307 | const videos = res.body | ||
308 | expect(videos.length).to.equal(4) | ||
309 | |||
310 | done() | ||
311 | }) | ||
312 | }) | ||
313 | |||
234 | after(function (done) { | 314 | after(function (done) { |
235 | process.kill(-server.app.pid) | 315 | process.kill(-server.app.pid) |
236 | process.kill(-webtorrent.app.pid) | 316 | 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 = { | |||
12 | getFriendsList: getFriendsList, | 12 | getFriendsList: getFriendsList, |
13 | getVideo: getVideo, | 13 | getVideo: getVideo, |
14 | getVideosList: getVideosList, | 14 | getVideosList: getVideosList, |
15 | getVideosListPagination: getVideosListPagination, | ||
15 | login: login, | 16 | login: login, |
16 | loginAndGetAccessToken: loginAndGetAccessToken, | 17 | loginAndGetAccessToken: loginAndGetAccessToken, |
17 | makeFriends: makeFriends, | 18 | makeFriends: makeFriends, |
@@ -20,6 +21,7 @@ const testUtils = { | |||
20 | flushAndRunMultipleServers: flushAndRunMultipleServers, | 21 | flushAndRunMultipleServers: flushAndRunMultipleServers, |
21 | runServer: runServer, | 22 | runServer: runServer, |
22 | searchVideo: searchVideo, | 23 | searchVideo: searchVideo, |
24 | searchVideoWithPagination: searchVideoWithPagination, | ||
23 | testImage: testImage, | 25 | testImage: testImage, |
24 | uploadVideo: uploadVideo | 26 | uploadVideo: uploadVideo |
25 | } | 27 | } |
@@ -63,6 +65,19 @@ function getVideosList (url, end) { | |||
63 | .end(end) | 65 | .end(end) |
64 | } | 66 | } |
65 | 67 | ||
68 | function getVideosListPagination (url, start, count, end) { | ||
69 | const path = '/api/v1/videos' | ||
70 | |||
71 | request(url) | ||
72 | .get(path) | ||
73 | .query({ start: start }) | ||
74 | .query({ count: count }) | ||
75 | .set('Accept', 'application/json') | ||
76 | .expect(200) | ||
77 | .expect('Content-Type', /json/) | ||
78 | .end(end) | ||
79 | } | ||
80 | |||
66 | function login (url, client, user, expectedStatus, end) { | 81 | function login (url, client, user, expectedStatus, end) { |
67 | if (!end) { | 82 | if (!end) { |
68 | end = expectedStatus | 83 | end = expectedStatus |
@@ -261,6 +276,19 @@ function searchVideo (url, search, end) { | |||
261 | .end(end) | 276 | .end(end) |
262 | } | 277 | } |
263 | 278 | ||
279 | function searchVideoWithPagination (url, search, start, count, end) { | ||
280 | const path = '/api/v1/videos' | ||
281 | |||
282 | request(url) | ||
283 | .get(path + '/search/' + search) | ||
284 | .query({ start: start }) | ||
285 | .query({ count: count }) | ||
286 | .set('Accept', 'application/json') | ||
287 | .expect(200) | ||
288 | .expect('Content-Type', /json/) | ||
289 | .end(end) | ||
290 | } | ||
291 | |||
264 | function testImage (url, videoName, imagePath, callback) { | 292 | function testImage (url, videoName, imagePath, callback) { |
265 | request(url) | 293 | request(url) |
266 | .get(imagePath) | 294 | .get(imagePath) |