aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/checkParams.js34
-rw-r--r--server/tests/api/users.js13
-rw-r--r--server/tests/api/utils.js13
3 files changed, 53 insertions, 7 deletions
diff --git a/server/tests/api/checkParams.js b/server/tests/api/checkParams.js
index bd7227e9c..8b49f5f36 100644
--- a/server/tests/api/checkParams.js
+++ b/server/tests/api/checkParams.js
@@ -504,6 +504,8 @@ describe('Test parameters validator', function () {
504 504
505 describe('Of the users API', function () { 505 describe('Of the users API', function () {
506 const path = '/api/v1/users/' 506 const path = '/api/v1/users/'
507 let userId = null
508 let userAccessToken = null
507 509
508 describe('When adding a new user', function () { 510 describe('When adding a new user', function () {
509 it('Should fail with a too small username', function (done) { 511 it('Should fail with a too small username', function (done) {
@@ -580,19 +582,19 @@ describe('Test parameters validator', function () {
580 utils.loginAndGetAccessToken(server, function (err, accessToken) { 582 utils.loginAndGetAccessToken(server, function (err, accessToken) {
581 if (err) throw err 583 if (err) throw err
582 584
585 userAccessToken = accessToken
586
583 const data = { 587 const data = {
584 username: 'user2', 588 username: 'user2',
585 password: 'my super password' 589 password: 'my super password'
586 } 590 }
587 591
588 makePostBodyRequest(path, accessToken, data, done, 403) 592 makePostBodyRequest(path, userAccessToken, data, done, 403)
589 }) 593 })
590 }) 594 })
591 }) 595 })
592 596
593 describe('When updating a user', function () { 597 describe('When updating a user', function () {
594 let userId = null
595
596 before(function (done) { 598 before(function (done) {
597 utils.getUsersList(server.url, function (err, res) { 599 utils.getUsersList(server.url, function (err, res) {
598 if (err) throw err 600 if (err) throw err
@@ -607,7 +609,7 @@ describe('Test parameters validator', function () {
607 password: 'bla' 609 password: 'bla'
608 } 610 }
609 611
610 makePutBodyRequest(path + '/' + userId, server.accessToken, data, done) 612 makePutBodyRequest(path + userId, userAccessToken, data, done)
611 }) 613 })
612 614
613 it('Should fail with a too long password', function (done) { 615 it('Should fail with a too long password', function (done) {
@@ -617,7 +619,7 @@ describe('Test parameters validator', function () {
617 'very very very very very very very very very very very very very very very very very very very very long' 619 'very very very very very very very very very very very very very very very very very very very very long'
618 } 620 }
619 621
620 makePutBodyRequest(path + '/' + userId, server.accessToken, data, done) 622 makePutBodyRequest(path + userId, userAccessToken, data, done)
621 }) 623 })
622 624
623 it('Should fail with an non authenticated user', function (done) { 625 it('Should fail with an non authenticated user', function (done) {
@@ -625,7 +627,7 @@ describe('Test parameters validator', function () {
625 password: 'my super password' 627 password: 'my super password'
626 } 628 }
627 629
628 makePutBodyRequest(path + '/' + userId, 'super token', data, done, 401) 630 makePutBodyRequest(path + userId, 'super token', data, done, 401)
629 }) 631 })
630 632
631 it('Should succeed with the correct params', function (done) { 633 it('Should succeed with the correct params', function (done) {
@@ -633,7 +635,25 @@ describe('Test parameters validator', function () {
633 password: 'my super password' 635 password: 'my super password'
634 } 636 }
635 637
636 makePutBodyRequest(path + '/' + userId, server.accessToken, data, done, 204) 638 makePutBodyRequest(path + userId, userAccessToken, data, done, 204)
639 })
640 })
641
642 describe('When getting my information', function () {
643 it('Should fail with a non authenticated user', function (done) {
644 request(server.url)
645 .get(path + 'me')
646 .set('Authorization', 'Bearer faketoken')
647 .set('Accept', 'application/json')
648 .expect(401, done)
649 })
650
651 it('Should success with the correct parameters', function (done) {
652 request(server.url)
653 .get(path + 'me')
654 .set('Authorization', 'Bearer ' + userAccessToken)
655 .set('Accept', 'application/json')
656 .expect(200, done)
637 }) 657 })
638 }) 658 })
639 659
diff --git a/server/tests/api/users.js b/server/tests/api/users.js
index c711d6b64..e1d4a8cf4 100644
--- a/server/tests/api/users.js
+++ b/server/tests/api/users.js
@@ -179,6 +179,19 @@ describe('Test users', function () {
179 }) 179 })
180 }) 180 })
181 181
182 it('Should be able to get the user informations', function (done) {
183 utils.getUserInformation(server.url, accessTokenUser, function (err, res) {
184 if (err) throw err
185
186 const user = res.body
187
188 expect(user.username).to.equal('user_1')
189 expect(user.id).to.exist
190
191 done()
192 })
193 })
194
182 it('Should be able to upload a video with this user', function (done) { 195 it('Should be able to upload a video with this user', function (done) {
183 this.timeout(5000) 196 this.timeout(5000)
184 197
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js
index f34b81e4a..0dc309328 100644
--- a/server/tests/api/utils.js
+++ b/server/tests/api/utils.js
@@ -14,6 +14,7 @@ const testUtils = {
14 getAllVideosListBy: getAllVideosListBy, 14 getAllVideosListBy: getAllVideosListBy,
15 getClient: getClient, 15 getClient: getClient,
16 getFriendsList: getFriendsList, 16 getFriendsList: getFriendsList,
17 getUserInformation: getUserInformation,
17 getUsersList: getUsersList, 18 getUsersList: getUsersList,
18 getVideo: getVideo, 19 getVideo: getVideo,
19 getVideosList: getVideosList, 20 getVideosList: getVideosList,
@@ -93,6 +94,18 @@ function getClient (url, end) {
93 .end(end) 94 .end(end)
94} 95}
95 96
97function getUserInformation (url, accessToken, end) {
98 const path = '/api/v1/users/me'
99
100 request(url)
101 .get(path)
102 .set('Accept', 'application/json')
103 .set('Authorization', 'Bearer ' + accessToken)
104 .expect(200)
105 .expect('Content-Type', /json/)
106 .end(end)
107}
108
96function getUsersList (url, end) { 109function getUsersList (url, end) {
97 const path = '/api/v1/users' 110 const path = '/api/v1/users'
98 111