]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/users.js
Server: add video language attribute
[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,
d38b8281 8 getUserVideoRating,
c4403b29
C
9 getUsersList,
10 getUsersListPaginationAndSort,
11 removeUser,
12 updateUser
8d309058
C
13}
14
15// ---------------------- Export functions --------------------
16
17function createUser (url, accessToken, username, password, specialStatus, end) {
18 if (!end) {
19 end = specialStatus
20 specialStatus = 204
21 }
22
23 const path = '/api/v1/users'
ad4a8a1c
C
24 const body = {
25 username,
26 password,
27 email: username + '@example.com'
28 }
8d309058
C
29
30 request(url)
31 .post(path)
32 .set('Accept', 'application/json')
33 .set('Authorization', 'Bearer ' + accessToken)
ad4a8a1c 34 .send(body)
8d309058
C
35 .expect(specialStatus)
36 .end(end)
37}
38
39function getUserInformation (url, accessToken, end) {
40 const path = '/api/v1/users/me'
41
42 request(url)
43 .get(path)
44 .set('Accept', 'application/json')
45 .set('Authorization', 'Bearer ' + accessToken)
46 .expect(200)
47 .expect('Content-Type', /json/)
48 .end(end)
49}
50
d38b8281
C
51function getUserVideoRating (url, accessToken, videoId, end) {
52 const path = '/api/v1/users/me/videos/' + videoId + '/rating'
53
54 request(url)
55 .get(path)
56 .set('Accept', 'application/json')
57 .set('Authorization', 'Bearer ' + accessToken)
58 .expect(200)
59 .expect('Content-Type', /json/)
60 .end(end)
61}
62
8d309058
C
63function getUsersList (url, end) {
64 const path = '/api/v1/users'
65
66 request(url)
67 .get(path)
68 .set('Accept', 'application/json')
69 .expect(200)
70 .expect('Content-Type', /json/)
71 .end(end)
72}
73
5c39adb7
C
74function getUsersListPaginationAndSort (url, start, count, sort, end) {
75 const path = '/api/v1/users'
76
77 request(url)
78 .get(path)
79 .query({ start: start })
80 .query({ count: count })
81 .query({ sort: sort })
82 .set('Accept', 'application/json')
83 .expect(200)
84 .expect('Content-Type', /json/)
85 .end(end)
86}
87
68a3b9f2 88function removeUser (url, userId, accessToken, expectedStatus, end) {
8d309058
C
89 if (!end) {
90 end = expectedStatus
91 expectedStatus = 204
92 }
93
94 const path = '/api/v1/users'
95
96 request(url)
68a3b9f2 97 .delete(path + '/' + userId)
8d309058 98 .set('Accept', 'application/json')
68a3b9f2 99 .set('Authorization', 'Bearer ' + accessToken)
8d309058
C
100 .expect(expectedStatus)
101 .end(end)
102}
103
1d49e1e2 104function updateUser (url, userId, accessToken, newPassword, displayNSFW, end) {
8d309058
C
105 const path = '/api/v1/users/' + userId
106
1d49e1e2
C
107 const toSend = {}
108 if (newPassword !== undefined && newPassword !== null) toSend.password = newPassword
109 if (displayNSFW !== undefined && displayNSFW !== null) toSend.displayNSFW = displayNSFW
110
8d309058
C
111 request(url)
112 .put(path)
113 .set('Accept', 'application/json')
114 .set('Authorization', 'Bearer ' + accessToken)
1d49e1e2 115 .send(toSend)
8d309058
C
116 .expect(204)
117 .end(end)
118}
119
120// ---------------------------------------------------------------------------
121
122module.exports = usersUtils