aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/utils.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/utils.js')
-rw-r--r--server/tests/api/utils.js62
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')
8const request = require('supertest') 8const request = require('supertest')
9 9
10const testUtils = { 10const 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
40function 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
36function dateIsValid (dateString) { 57function 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
96function 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
75function getFriendsList (url, end) { 107function 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
244function 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
212function removeVideo (url, token, id, expectedStatus, end) { 260function 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
465function 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
419module.exports = testUtils 479module.exports = testUtils