diff options
author | Chocobozzz <florian.bigard@gmail.com> | 2016-08-04 22:32:36 +0200 |
---|---|---|
committer | Chocobozzz <florian.bigard@gmail.com> | 2016-08-04 22:33:38 +0200 |
commit | 9bd2662976a75d3b03364cdbe6419e57c80f99a6 (patch) | |
tree | 0b5289660f843a8ba7f13aa79d458f53c94b36d9 /server/tests/api/utils.js | |
parent | e4c556196d7b31111f17596840d2e1d60caa7dcb (diff) | |
download | PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.gz PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.tar.zst PeerTube-9bd2662976a75d3b03364cdbe6419e57c80f99a6.zip |
Implement user API (create, update, remove, list)
Diffstat (limited to 'server/tests/api/utils.js')
-rw-r--r-- | server/tests/api/utils.js | 62 |
1 files changed, 61 insertions, 1 deletions
diff --git a/server/tests/api/utils.js b/server/tests/api/utils.js index 3cc769f26..f34b81e4a 100644 --- a/server/tests/api/utils.js +++ b/server/tests/api/utils.js | |||
@@ -8,11 +8,13 @@ const pathUtils = require('path') | |||
8 | const request = require('supertest') | 8 | const request = require('supertest') |
9 | 9 | ||
10 | const testUtils = { | 10 | const testUtils = { |
11 | createUser: createUser, | ||
11 | dateIsValid: dateIsValid, | 12 | dateIsValid: dateIsValid, |
12 | flushTests: flushTests, | 13 | flushTests: flushTests, |
13 | getAllVideosListBy: getAllVideosListBy, | 14 | getAllVideosListBy: getAllVideosListBy, |
14 | getClient: getClient, | 15 | getClient: getClient, |
15 | getFriendsList: getFriendsList, | 16 | getFriendsList: getFriendsList, |
17 | getUsersList: getUsersList, | ||
16 | getVideo: getVideo, | 18 | getVideo: getVideo, |
17 | getVideosList: getVideosList, | 19 | getVideosList: getVideosList, |
18 | getVideosListPagination: getVideosListPagination, | 20 | getVideosListPagination: getVideosListPagination, |
@@ -21,6 +23,7 @@ const testUtils = { | |||
21 | loginAndGetAccessToken: loginAndGetAccessToken, | 23 | loginAndGetAccessToken: loginAndGetAccessToken, |
22 | makeFriends: makeFriends, | 24 | makeFriends: makeFriends, |
23 | quitFriends: quitFriends, | 25 | quitFriends: quitFriends, |
26 | removeUser: removeUser, | ||
24 | removeVideo: removeVideo, | 27 | removeVideo: removeVideo, |
25 | flushAndRunMultipleServers: flushAndRunMultipleServers, | 28 | flushAndRunMultipleServers: flushAndRunMultipleServers, |
26 | runServer: runServer, | 29 | runServer: runServer, |
@@ -28,11 +31,29 @@ const testUtils = { | |||
28 | searchVideoWithPagination: searchVideoWithPagination, | 31 | searchVideoWithPagination: searchVideoWithPagination, |
29 | searchVideoWithSort: searchVideoWithSort, | 32 | searchVideoWithSort: searchVideoWithSort, |
30 | testImage: testImage, | 33 | testImage: testImage, |
31 | uploadVideo: uploadVideo | 34 | uploadVideo: uploadVideo, |
35 | updateUser: updateUser | ||
32 | } | 36 | } |
33 | 37 | ||
34 | // ---------------------- Export functions -------------------- | 38 | // ---------------------- Export functions -------------------- |
35 | 39 | ||
40 | function createUser (url, accessToken, username, password, specialStatus, end) { | ||
41 | if (!end) { | ||
42 | end = specialStatus | ||
43 | specialStatus = 204 | ||
44 | } | ||
45 | |||
46 | const path = '/api/v1/users' | ||
47 | |||
48 | request(url) | ||
49 | .post(path) | ||
50 | .set('Accept', 'application/json') | ||
51 | .set('Authorization', 'Bearer ' + accessToken) | ||
52 | .send({ username: username, password: password }) | ||
53 | .expect(specialStatus) | ||
54 | .end(end) | ||
55 | } | ||
56 | |||
36 | function dateIsValid (dateString) { | 57 | function dateIsValid (dateString) { |
37 | const dateToCheck = new Date(dateString) | 58 | const dateToCheck = new Date(dateString) |
38 | const now = new Date() | 59 | const now = new Date() |
@@ -72,6 +93,17 @@ function getClient (url, end) { | |||
72 | .end(end) | 93 | .end(end) |
73 | } | 94 | } |
74 | 95 | ||
96 | function getUsersList (url, end) { | ||
97 | const path = '/api/v1/users' | ||
98 | |||
99 | request(url) | ||
100 | .get(path) | ||
101 | .set('Accept', 'application/json') | ||
102 | .expect(200) | ||
103 | .expect('Content-Type', /json/) | ||
104 | .end(end) | ||
105 | } | ||
106 | |||
75 | function getFriendsList (url, end) { | 107 | function getFriendsList (url, end) { |
76 | const path = '/api/v1/pods/' | 108 | const path = '/api/v1/pods/' |
77 | 109 | ||
@@ -209,6 +241,22 @@ function quitFriends (url, accessToken, expectedStatus, callback) { | |||
209 | }) | 241 | }) |
210 | } | 242 | } |
211 | 243 | ||
244 | function removeUser (url, token, username, expectedStatus, end) { | ||
245 | if (!end) { | ||
246 | end = expectedStatus | ||
247 | expectedStatus = 204 | ||
248 | } | ||
249 | |||
250 | const path = '/api/v1/users' | ||
251 | |||
252 | request(url) | ||
253 | .delete(path + '/' + username) | ||
254 | .set('Accept', 'application/json') | ||
255 | .set('Authorization', 'Bearer ' + token) | ||
256 | .expect(expectedStatus) | ||
257 | .end(end) | ||
258 | } | ||
259 | |||
212 | function removeVideo (url, token, id, expectedStatus, end) { | 260 | function removeVideo (url, token, id, expectedStatus, end) { |
213 | if (!end) { | 261 | if (!end) { |
214 | end = expectedStatus | 262 | end = expectedStatus |
@@ -414,6 +462,18 @@ function uploadVideo (url, accessToken, name, description, tags, fixture, specia | |||
414 | .end(end) | 462 | .end(end) |
415 | } | 463 | } |
416 | 464 | ||
465 | function updateUser (url, userId, accessToken, newPassword, end) { | ||
466 | const path = '/api/v1/users/' + userId | ||
467 | |||
468 | request(url) | ||
469 | .put(path) | ||
470 | .set('Accept', 'application/json') | ||
471 | .set('Authorization', 'Bearer ' + accessToken) | ||
472 | .send({ password: newPassword }) | ||
473 | .expect(200) | ||
474 | .end(end) | ||
475 | } | ||
476 | |||
417 | // --------------------------------------------------------------------------- | 477 | // --------------------------------------------------------------------------- |
418 | 478 | ||
419 | module.exports = testUtils | 479 | module.exports = testUtils |