]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/users.js
Server: delete user with the id and not the username
[github/Chocobozzz/PeerTube.git] / server / tests / utils / users.js
CommitLineData
8d309058
C
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
68a3b9f2 55function removeUser (url, userId, accessToken, expectedStatus, end) {
8d309058
C
56 if (!end) {
57 end = expectedStatus
58 expectedStatus = 204
59 }
60
61 const path = '/api/v1/users'
62
63 request(url)
68a3b9f2 64 .delete(path + '/' + userId)
8d309058 65 .set('Accept', 'application/json')
68a3b9f2 66 .set('Authorization', 'Bearer ' + accessToken)
8d309058
C
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