]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/users.js
Video views is implemented. Closes https://github.com/Chocobozzz/PeerTube/issues/41
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users.js
CommitLineData
8d309058
C
1'use strict'
2
3const request = require('supertest')
4
5const usersUtils = {
c4403b29
C
6 createUser,
7 getUserInformation,
8 getUsersList,
9 getUsersListPaginationAndSort,
10 removeUser,
11 updateUser
8d309058
C
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'
ad4a8a1c
C
23 const body = {
24 username,
25 password,
26 email: username + '@example.com'
27 }
8d309058
C
28
29 request(url)
30 .post(path)
31 .set('Accept', 'application/json')
32 .set('Authorization', 'Bearer ' + accessToken)
ad4a8a1c 33 .send(body)
8d309058
C
34 .expect(specialStatus)
35 .end(end)
36}
37
38function 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
50function 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
5c39adb7
C
61function 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
68a3b9f2 75function removeUser (url, userId, accessToken, expectedStatus, end) {
8d309058
C
76 if (!end) {
77 end = expectedStatus
78 expectedStatus = 204
79 }
80
81 const path = '/api/v1/users'
82
83 request(url)
68a3b9f2 84 .delete(path + '/' + userId)
8d309058 85 .set('Accept', 'application/json')
68a3b9f2 86 .set('Authorization', 'Bearer ' + accessToken)
8d309058
C
87 .expect(expectedStatus)
88 .end(end)
89}
90
91function 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
105module.exports = usersUtils