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