aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/users.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/users.js')
-rw-r--r--server/tests/utils/users.js100
1 files changed, 100 insertions, 0 deletions
diff --git a/server/tests/utils/users.js b/server/tests/utils/users.js
new file mode 100644
index 000000000..2bf9c6e3e
--- /dev/null
+++ b/server/tests/utils/users.js
@@ -0,0 +1,100 @@
1'use strict'
2
3const request = require('supertest')
4
5const usersUtils = {
6 createUser,
7 getUserInformation,
8 getUsersList,
9 getUsersListPaginationAndSort,
10 removeUser,
11 updateUser
12}
13
14// ---------------------- Export functions --------------------
15
16function createUser (url, accessToken, username, password, specialStatus, end) {
17 if (!end) {
18 end = specialStatus
19 specialStatus = 204
20 }
21
22 const path = '/api/v1/users'
23
24 request(url)
25 .post(path)
26 .set('Accept', 'application/json')
27 .set('Authorization', 'Bearer ' + accessToken)
28 .send({ username: username, password: password })
29 .expect(specialStatus)
30 .end(end)
31}
32
33function getUserInformation (url, accessToken, end) {
34 const path = '/api/v1/users/me'
35
36 request(url)
37 .get(path)
38 .set('Accept', 'application/json')
39 .set('Authorization', 'Bearer ' + accessToken)
40 .expect(200)
41 .expect('Content-Type', /json/)
42 .end(end)
43}
44
45function getUsersList (url, end) {
46 const path = '/api/v1/users'
47
48 request(url)
49 .get(path)
50 .set('Accept', 'application/json')
51 .expect(200)
52 .expect('Content-Type', /json/)
53 .end(end)
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
70function removeUser (url, userId, accessToken, expectedStatus, end) {
71 if (!end) {
72 end = expectedStatus
73 expectedStatus = 204
74 }
75
76 const path = '/api/v1/users'
77
78 request(url)
79 .delete(path + '/' + userId)
80 .set('Accept', 'application/json')
81 .set('Authorization', 'Bearer ' + accessToken)
82 .expect(expectedStatus)
83 .end(end)
84}
85
86function updateUser (url, userId, accessToken, newPassword, end) {
87 const path = '/api/v1/users/' + userId
88
89 request(url)
90 .put(path)
91 .set('Accept', 'application/json')
92 .set('Authorization', 'Bearer ' + accessToken)
93 .send({ password: newPassword })
94 .expect(204)
95 .end(end)
96}
97
98// ---------------------------------------------------------------------------
99
100module.exports = usersUtils