]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/users.js
Server: fix single pod tests
[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'
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
5c39adb7
C
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
68a3b9f2 70function removeUser (url, userId, accessToken, expectedStatus, end) {
8d309058
C
71 if (!end) {
72 end = expectedStatus
73 expectedStatus = 204
74 }
75
76 const path = '/api/v1/users'
77
78 request(url)
68a3b9f2 79 .delete(path + '/' + userId)
8d309058 80 .set('Accept', 'application/json')
68a3b9f2 81 .set('Authorization', 'Bearer ' + accessToken)
8d309058
C
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