aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-05-17 21:03:00 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-05-17 21:03:00 +0200
commita877d5acc5c52b8667c65f725bbca9a52e40ec48 (patch)
tree20b5dd56f71c7572360807f894e85e0ab729629f /server/tests/api
parent479f229198bdfcfd3a63d02babdddaa8b2209ccb (diff)
downloadPeerTube-a877d5acc5c52b8667c65f725bbca9a52e40ec48.tar.gz
PeerTube-a877d5acc5c52b8667c65f725bbca9a52e40ec48.tar.zst
PeerTube-a877d5acc5c52b8667c65f725bbca9a52e40ec48.zip
Add ability to sort videos list
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/checkParams.js50
-rw-r--r--server/tests/api/singlePod.js33
-rw-r--r--server/tests/api/utils.js26
3 files changed, 109 insertions, 0 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
index b63091910..a109aba47 100644
--- a/server/tests/api/checkParams.js
+++ b/server/tests/api/checkParams.js
@@ -130,6 +130,32 @@ describe('Test parameters validator', function () {
130 describe('Of the videos API', function () { 130 describe('Of the videos API', function () {
131 const path = '/api/v1/videos/' 131 const path = '/api/v1/videos/'
132 132
133 describe('When listing a video', function () {
134 it('Should fail with a bad start pagination', function (done) {
135 request(server.url)
136 .get(path)
137 .query({ start: 'hello' })
138 .set('Accept', 'application/json')
139 .expect(400, done)
140 })
141
142 it('Should fail with a bad count pagination', function (done) {
143 request(server.url)
144 .get(path)
145 .query({ count: 'hello' })
146 .set('Accept', 'application/json')
147 .expect(400, done)
148 })
149
150 it('Should fail with an incorrect sort', function (done) {
151 request(server.url)
152 .get(path)
153 .query({ sort: 'hello' })
154 .set('Accept', 'application/json')
155 .expect(400, done)
156 })
157 })
158
133 describe('When searching a video', function () { 159 describe('When searching a video', function () {
134 it('Should fail with nothing', function (done) { 160 it('Should fail with nothing', function (done) {
135 request(server.url) 161 request(server.url)
@@ -137,6 +163,30 @@ describe('Test parameters validator', function () {
137 .set('Accept', 'application/json') 163 .set('Accept', 'application/json')
138 .expect(400, done) 164 .expect(400, done)
139 }) 165 })
166
167 it('Should fail with a bad start pagination', function (done) {
168 request(server.url)
169 .get(pathUtils.join(path, 'search', 'test'))
170 .query({ start: 'hello' })
171 .set('Accept', 'application/json')
172 .expect(400, done)
173 })
174
175 it('Should fail with a bad count pagination', function (done) {
176 request(server.url)
177 .get(pathUtils.join(path, 'search', 'test'))
178 .query({ count: 'hello' })
179 .set('Accept', 'application/json')
180 .expect(400, done)
181 })
182
183 it('Should fail with an incorrect sort', function (done) {
184 request(server.url)
185 .get(pathUtils.join(path, 'search', 'test'))
186 .query({ sort: 'hello' })
187 .set('Accept', 'application/json')
188 .expect(400, done)
189 })
140 }) 190 })
141 191
142 describe('When adding a video', function () { 192 describe('When adding a video', function () {
diff --git a/server/tests/api/singlePod.js b/server/tests/api/singlePod.js
index 72002b631..1a53ada3a 100644
--- a/server/tests/api/singlePod.js
+++ b/server/tests/api/singlePod.js
@@ -314,6 +314,39 @@ describe('Test a single pod', function () {
314 }) 314 })
315 }) 315 })
316 316
317 it('Should list and sort by name in descending order', function (done) {
318 utils.getVideosListSort(server.url, '-name', function (err, res) {
319 if (err) throw err
320
321 const videos = res.body
322 expect(videos.length).to.equal(6)
323 expect(videos[5].name === 'video_short.mp4 name')
324 expect(videos[4].name === 'video_short.ogv name')
325 expect(videos[3].name === 'video_short.webm name')
326 expect(videos[2].name === 'video_short1.webm name')
327 expect(videos[1].name === 'video_short2.webm name')
328 expect(videos[0].name === 'video_short3.webm name')
329
330 done()
331 })
332 })
333
334 it('Should search and sort by name in ascending order', function (done) {
335 utils.searchVideoWithSort(server.url, 'webm', 'name', function (err, res) {
336 if (err) throw err
337
338 const videos = res.body
339 expect(videos.length).to.equal(4)
340
341 expect(videos[0].name === 'video_short.webm name')
342 expect(videos[1].name === 'video_short1.webm name')
343 expect(videos[2].name === 'video_short2.webm name')
344 expect(videos[3].name === 'video_short3.webm name')
345
346 done()
347 })
348 })
349
317 after(function (done) { 350 after(function (done) {
318 process.kill(-server.app.pid) 351 process.kill(-server.app.pid)
319 process.kill(-webtorrent.app.pid) 352 process.kill(-webtorrent.app.pid)
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js
index d505cb5d9..ac43946cd 100644
--- a/server/tests/api/utils.js
+++ b/server/tests/api/utils.js
@@ -14,6 +14,7 @@ const testUtils = {
14 getVideo: getVideo, 14 getVideo: getVideo,
15 getVideosList: getVideosList, 15 getVideosList: getVideosList,
16 getVideosListPagination: getVideosListPagination, 16 getVideosListPagination: getVideosListPagination,
17 getVideosListSort: getVideosListSort,
17 login: login, 18 login: login,
18 loginAndGetAccessToken: loginAndGetAccessToken, 19 loginAndGetAccessToken: loginAndGetAccessToken,
19 makeFriends: makeFriends, 20 makeFriends: makeFriends,
@@ -23,6 +24,7 @@ const testUtils = {
23 runServer: runServer, 24 runServer: runServer,
24 searchVideo: searchVideo, 25 searchVideo: searchVideo,
25 searchVideoWithPagination: searchVideoWithPagination, 26 searchVideoWithPagination: searchVideoWithPagination,
27 searchVideoWithSort: searchVideoWithSort,
26 testImage: testImage, 28 testImage: testImage,
27 uploadVideo: uploadVideo 29 uploadVideo: uploadVideo
28} 30}
@@ -89,6 +91,18 @@ function getVideosListPagination (url, start, count, end) {
89 .end(end) 91 .end(end)
90} 92}
91 93
94function getVideosListSort (url, sort, end) {
95 const path = '/api/v1/videos'
96
97 request(url)
98 .get(path)
99 .query({ sort: sort })
100 .set('Accept', 'application/json')
101 .expect(200)
102 .expect('Content-Type', /json/)
103 .end(end)
104}
105
92function login (url, client, user, expectedStatus, end) { 106function login (url, client, user, expectedStatus, end) {
93 if (!end) { 107 if (!end) {
94 end = expectedStatus 108 end = expectedStatus
@@ -300,6 +314,18 @@ function searchVideoWithPagination (url, search, start, count, end) {
300 .end(end) 314 .end(end)
301} 315}
302 316
317function searchVideoWithSort (url, search, sort, end) {
318 const path = '/api/v1/videos'
319
320 request(url)
321 .get(path + '/search/' + search)
322 .query({ sort: sort })
323 .set('Accept', 'application/json')
324 .expect(200)
325 .expect('Content-Type', /json/)
326 .end(end)
327}
328
303function testImage (url, videoName, imagePath, callback) { 329function testImage (url, videoName, imagePath, callback) {
304 request(url) 330 request(url)
305 .get(imagePath) 331 .get(imagePath)