]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/utils/users.js
Add email to users
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users.js
1 'use strict'
2
3 const request = require('supertest')
4
5 const usersUtils = {
6 createUser,
7 getUserInformation,
8 getUsersList,
9 getUsersListPaginationAndSort,
10 removeUser,
11 updateUser
12 }
13
14 // ---------------------- Export functions --------------------
15
16 function 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 const body = {
24 username,
25 password,
26 email: username + '@example.com'
27 }
28
29 request(url)
30 .post(path)
31 .set('Accept', 'application/json')
32 .set('Authorization', 'Bearer ' + accessToken)
33 .send(body)
34 .expect(specialStatus)
35 .end(end)
36 }
37
38 function getUserInformation (url, accessToken, end) {
39 const path = '/api/v1/users/me'
40
41 request(url)
42 .get(path)
43 .set('Accept', 'application/json')
44 .set('Authorization', 'Bearer ' + accessToken)
45 .expect(200)
46 .expect('Content-Type', /json/)
47 .end(end)
48 }
49
50 function getUsersList (url, end) {
51 const path = '/api/v1/users'
52
53 request(url)
54 .get(path)
55 .set('Accept', 'application/json')
56 .expect(200)
57 .expect('Content-Type', /json/)
58 .end(end)
59 }
60
61 function getUsersListPaginationAndSort (url, start, count, sort, end) {
62 const path = '/api/v1/users'
63
64 request(url)
65 .get(path)
66 .query({ start: start })
67 .query({ count: count })
68 .query({ sort: sort })
69 .set('Accept', 'application/json')
70 .expect(200)
71 .expect('Content-Type', /json/)
72 .end(end)
73 }
74
75 function removeUser (url, userId, accessToken, expectedStatus, end) {
76 if (!end) {
77 end = expectedStatus
78 expectedStatus = 204
79 }
80
81 const path = '/api/v1/users'
82
83 request(url)
84 .delete(path + '/' + userId)
85 .set('Accept', 'application/json')
86 .set('Authorization', 'Bearer ' + accessToken)
87 .expect(expectedStatus)
88 .end(end)
89 }
90
91 function updateUser (url, userId, accessToken, newPassword, end) {
92 const path = '/api/v1/users/' + userId
93
94 request(url)
95 .put(path)
96 .set('Accept', 'application/json')
97 .set('Authorization', 'Bearer ' + accessToken)
98 .send({ password: newPassword })
99 .expect(204)
100 .end(end)
101 }
102
103 // ---------------------------------------------------------------------------
104
105 module.exports = usersUtils