aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/users.js
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-08-07 22:09:59 +0200
committerChocobozzz <florian.bigard@gmail.com>2016-08-07 22:09:59 +0200
commit8d30905858245f12a42fc327d2d57cbfe062d548 (patch)
tree9bd590872fbb753782f2ebbb9516db0414022d70 /server/tests/utils/users.js
parent58b2ba55a90f05f24661e664b1fb0a3486f037e8 (diff)
downloadPeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.tar.gz
PeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.tar.zst
PeerTube-8d30905858245f12a42fc327d2d57cbfe062d548.zip
Server: split tests utils in multiple files
Diffstat (limited to 'server/tests/utils/users.js')
-rw-r--r--server/tests/utils/users.js85
1 files changed, 85 insertions, 0 deletions
diff --git a/server/tests/utils/users.js b/server/tests/utils/users.js
new file mode 100644
index 000000000..ed7a9d672
--- /dev/null
+++ b/server/tests/utils/users.js
@@ -0,0 +1,85 @@
1'use strict'
2
3const request = require('supertest')
4
5const usersUtils = {
6 createUser: createUser,
7 getUserInformation: getUserInformation,
8 getUsersList: getUsersList,
9 removeUser: removeUser,
10 updateUser: updateUser
11}
12
13// ---------------------- Export functions --------------------
14
15function createUser (url, accessToken, username, password, specialStatus, end) {
16 if (!end) {
17 end = specialStatus
18 specialStatus = 204
19 }
20
21 const path = '/api/v1/users'
22
23 request(url)
24 .post(path)
25 .set('Accept', 'application/json')
26 .set('Authorization', 'Bearer ' + accessToken)
27 .send({ username: username, password: password })
28 .expect(specialStatus)
29 .end(end)
30}
31
32function getUserInformation (url, accessToken, end) {
33 const path = '/api/v1/users/me'
34
35 request(url)
36 .get(path)
37 .set('Accept', 'application/json')
38 .set('Authorization', 'Bearer ' + accessToken)
39 .expect(200)
40 .expect('Content-Type', /json/)
41 .end(end)
42}
43
44function getUsersList (url, end) {
45 const path = '/api/v1/users'
46
47 request(url)
48 .get(path)
49 .set('Accept', 'application/json')
50 .expect(200)
51 .expect('Content-Type', /json/)
52 .end(end)
53}
54
55function removeUser (url, token, username, expectedStatus, end) {
56 if (!end) {
57 end = expectedStatus
58 expectedStatus = 204
59 }
60
61 const path = '/api/v1/users'
62
63 request(url)
64 .delete(path + '/' + username)
65 .set('Accept', 'application/json')
66 .set('Authorization', 'Bearer ' + token)
67 .expect(expectedStatus)
68 .end(end)
69}
70
71function updateUser (url, userId, accessToken, newPassword, end) {
72 const path = '/api/v1/users/' + userId
73
74 request(url)
75 .put(path)
76 .set('Accept', 'application/json')
77 .set('Authorization', 'Bearer ' + accessToken)
78 .send({ password: newPassword })
79 .expect(204)
80 .end(end)
81}
82
83// ---------------------------------------------------------------------------
84
85module.exports = usersUtils