aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-16 22:31:45 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-16 22:31:45 +0200
commit5c39adb7313e0696aabb4b71196ab7b0b378c359 (patch)
treeac44b67890509338b984f8cbf11660dc77cdd0fd /server/tests
parent089ff2f2046fdbaf9531726eea1f8c6726ebf0c0 (diff)
downloadPeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.gz
PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.tar.zst
PeerTube-5c39adb7313e0696aabb4b71196ab7b0b378c359.zip
Server: add user list sort/pagination
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params.js26
-rw-r--r--server/tests/api/users.js83
-rw-r--r--server/tests/utils/users.js15
3 files changed, 120 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 })
diff --git a/server/tests/utils/users.js b/server/tests/utils/users.js
index 3b560e409..0cf4e4adb 100644
--- a/server/tests/utils/users.js
+++ b/server/tests/utils/users.js
@@ -6,6 +6,7 @@ const usersUtils = {
6 createUser: createUser, 6 createUser: createUser,
7 getUserInformation: getUserInformation, 7 getUserInformation: getUserInformation,
8 getUsersList: getUsersList, 8 getUsersList: getUsersList,
9 getUsersListPaginationAndSort: getUsersListPaginationAndSort,
9 removeUser: removeUser, 10 removeUser: removeUser,
10 updateUser: updateUser 11 updateUser: updateUser
11} 12}
@@ -52,6 +53,20 @@ function getUsersList (url, end) {
52 .end(end) 53 .end(end)
53} 54}
54 55
56function getUsersListPaginationAndSort (url, start, count, sort, end) {
57 const path = '/api/v1/users'
58
59 request(url)
60 .get(path)
61 .query({ start: start })
62 .query({ count: count })
63 .query({ sort: sort })
64 .set('Accept', 'application/json')
65 .expect(200)
66 .expect('Content-Type', /json/)
67 .end(end)
68}
69
55function removeUser (url, userId, accessToken, expectedStatus, end) { 70function removeUser (url, userId, accessToken, expectedStatus, end) {
56 if (!end) { 71 if (!end) {
57 end = expectedStatus 72 end = expectedStatus