diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-16 22:31:45 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-16 22:31:45 +0200 |
commit | 5c39adb7313e0696aabb4b71196ab7b0b378c359 (patch) | |
tree | ac44b67890509338b984f8cbf11660dc77cdd0fd /server/tests/api | |
parent | 089ff2f2046fdbaf9531726eea1f8c6726ebf0c0 (diff) | |
download | PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.gz PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.zst PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.zip |
Server: add user list sort/pagination
Diffstat (limited to 'server/tests/api')
-rw-r--r-- | server/tests/api/check-params.js | 26 | ||||
-rw-r--r-- | server/tests/api/users.js | 83 |
2 files changed, 105 insertions, 4 deletions
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js index 882948fac..fc8b0a42a 100644 --- a/server/tests/api/check-params.js +++ b/server/tests/api/check-params.js | |||
@@ -459,6 +459,32 @@ describe('Test parameters validator', function () { | |||
459 | let userId = null | 459 | let userId = null |
460 | let userAccessToken = null | 460 | let userAccessToken = null |
461 | 461 | ||
462 | describe('When listing users', function () { | ||
463 | it('Should fail with a bad start pagination', function (done) { | ||
464 | request(server.url) | ||
465 | .get(path) | ||
466 | .query({ start: 'hello' }) | ||
467 | .set('Accept', 'application/json') | ||
468 | .expect(400, done) | ||
469 | }) | ||
470 | |||
471 | it('Should fail with a bad count pagination', function (done) { | ||
472 | request(server.url) | ||
473 | .get(path) | ||
474 | .query({ count: 'hello' }) | ||
475 | .set('Accept', 'application/json') | ||
476 | .expect(400, done) | ||
477 | }) | ||
478 | |||
479 | it('Should fail with an incorrect sort', function (done) { | ||
480 | request(server.url) | ||
481 | .get(path) | ||
482 | .query({ sort: 'hello' }) | ||
483 | .set('Accept', 'application/json') | ||
484 | .expect(400, done) | ||
485 | }) | ||
486 | }) | ||
487 | |||
462 | describe('When adding a new user', function () { | 488 | describe('When adding a new user', function () { |
463 | it('Should fail with a too small username', function (done) { | 489 | it('Should fail with a too small username', function (done) { |
464 | const data = { | 490 | const data = { |
diff --git a/server/tests/api/users.js b/server/tests/api/users.js index a2557d2ab..c6c892bf2 100644 --- a/server/tests/api/users.js +++ b/server/tests/api/users.js | |||
@@ -209,17 +209,92 @@ describe('Test users', function () { | |||
209 | usersUtils.getUsersList(server.url, function (err, res) { | 209 | usersUtils.getUsersList(server.url, function (err, res) { |
210 | if (err) throw err | 210 | if (err) throw err |
211 | 211 | ||
212 | const users = res.body.data | 212 | const result = res.body |
213 | const total = result.total | ||
214 | const users = result.data | ||
213 | 215 | ||
216 | expect(total).to.equal(2) | ||
214 | expect(users).to.be.an('array') | 217 | expect(users).to.be.an('array') |
215 | expect(users.length).to.equal(2) | 218 | expect(users.length).to.equal(2) |
216 | 219 | ||
217 | const rootUser = users[0] | 220 | const user = users[0] |
221 | expect(user.username).to.equal('user_1') | ||
222 | |||
223 | const rootUser = users[1] | ||
218 | expect(rootUser.username).to.equal('root') | 224 | expect(rootUser.username).to.equal('root') |
225 | userId = user.id | ||
226 | |||
227 | done() | ||
228 | }) | ||
229 | }) | ||
230 | |||
231 | it('Should list only the first user by username asc', function (done) { | ||
232 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, 'username', function (err, res) { | ||
233 | if (err) throw err | ||
234 | |||
235 | const result = res.body | ||
236 | const total = result.total | ||
237 | const users = result.data | ||
238 | |||
239 | expect(total).to.equal(2) | ||
240 | expect(users.length).to.equal(1) | ||
219 | 241 | ||
220 | const user = users[1] | 242 | const user = users[0] |
243 | expect(user.username).to.equal('root') | ||
244 | |||
245 | done() | ||
246 | }) | ||
247 | }) | ||
248 | |||
249 | it('Should list only the first user by username desc', function (done) { | ||
250 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-username', function (err, res) { | ||
251 | if (err) throw err | ||
252 | |||
253 | const result = res.body | ||
254 | const total = result.total | ||
255 | const users = result.data | ||
256 | |||
257 | expect(total).to.equal(2) | ||
258 | expect(users.length).to.equal(1) | ||
259 | |||
260 | const user = users[0] | ||
221 | expect(user.username).to.equal('user_1') | 261 | expect(user.username).to.equal('user_1') |
222 | userId = user.id | 262 | |
263 | done() | ||
264 | }) | ||
265 | }) | ||
266 | |||
267 | it('Should list only the second user by createdDate desc', function (done) { | ||
268 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 1, '-createdDate', function (err, res) { | ||
269 | if (err) throw err | ||
270 | |||
271 | const result = res.body | ||
272 | const total = result.total | ||
273 | const users = result.data | ||
274 | |||
275 | expect(total).to.equal(2) | ||
276 | expect(users.length).to.equal(1) | ||
277 | |||
278 | const user = users[0] | ||
279 | expect(user.username).to.equal('user_1') | ||
280 | |||
281 | done() | ||
282 | }) | ||
283 | }) | ||
284 | |||
285 | it('Should list all the users by createdDate asc', function (done) { | ||
286 | usersUtils.getUsersListPaginationAndSort(server.url, 0, 2, 'createdDate', function (err, res) { | ||
287 | if (err) throw err | ||
288 | |||
289 | const result = res.body | ||
290 | const total = result.total | ||
291 | const users = result.data | ||
292 | |||
293 | expect(total).to.equal(2) | ||
294 | expect(users.length).to.equal(2) | ||
295 | |||
296 | expect(users[0].username).to.equal('root') | ||
297 | expect(users[1].username).to.equal('user_1') | ||
223 | 298 | ||
224 | done() | 299 | done() |
225 | }) | 300 | }) |