diff options
author | Chocobozzz <me@florianbigard.com> | 2019-04-15 10:49:46 +0200 |
---|---|---|
committer | Chocobozzz <me@florianbigard.com> | 2019-04-15 14:39:52 +0200 |
commit | 1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a (patch) | |
tree | 91a10310cdf924779527525d39f8eb7e09e4ba49 /server/tests/api/users/users.ts | |
parent | 31b48aad478506d4214586f02792816efa968e4b (diff) | |
download | PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.gz PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.tar.zst PeerTube-1eddc9a74f9a80fa5d0cb25fceb3fc47a1a3c14a.zip |
Add user adminFlags
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r-- | server/tests/api/users/users.ts | 892 |
1 files changed, 476 insertions, 416 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts index 6e7de9c38..13511e070 100644 --- a/server/tests/api/users/users.ts +++ b/server/tests/api/users/users.ts | |||
@@ -37,6 +37,7 @@ import { | |||
37 | import { follow } from '../../../../shared/utils/server/follows' | 37 | import { follow } from '../../../../shared/utils/server/follows' |
38 | import { setAccessTokensToServers } from '../../../../shared/utils/users/login' | 38 | import { setAccessTokensToServers } from '../../../../shared/utils/users/login' |
39 | import { getMyVideos } from '../../../../shared/utils/videos/videos' | 39 | import { getMyVideos } from '../../../../shared/utils/videos/videos' |
40 | import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model' | ||
40 | 41 | ||
41 | const expect = chai.expect | 42 | const expect = chai.expect |
42 | 43 | ||
@@ -60,563 +61,622 @@ describe('Test users', function () { | |||
60 | await setAccessTokensToServers([ server ]) | 61 | await setAccessTokensToServers([ server ]) |
61 | }) | 62 | }) |
62 | 63 | ||
63 | it('Should create a new client') | 64 | describe('OAuth client', function () { |
65 | it('Should create a new client') | ||
64 | 66 | ||
65 | it('Should return the first client') | 67 | it('Should return the first client') |
66 | 68 | ||
67 | it('Should remove the last client') | 69 | it('Should remove the last client') |
68 | 70 | ||
69 | it('Should not login with an invalid client id', async function () { | 71 | it('Should not login with an invalid client id', async function () { |
70 | const client = { id: 'client', secret: server.client.secret } | 72 | const client = { id: 'client', secret: server.client.secret } |
71 | const res = await login(server.url, client, server.user, 400) | 73 | const res = await login(server.url, client, server.user, 400) |
72 | 74 | ||
73 | expect(res.body.error).to.contain('client is invalid') | 75 | expect(res.body.error).to.contain('client is invalid') |
74 | }) | 76 | }) |
75 | 77 | ||
76 | it('Should not login with an invalid client secret', async function () { | 78 | it('Should not login with an invalid client secret', async function () { |
77 | const client = { id: server.client.id, secret: 'coucou' } | 79 | const client = { id: server.client.id, secret: 'coucou' } |
78 | const res = await login(server.url, client, server.user, 400) | 80 | const res = await login(server.url, client, server.user, 400) |
79 | 81 | ||
80 | expect(res.body.error).to.contain('client is invalid') | 82 | expect(res.body.error).to.contain('client is invalid') |
83 | }) | ||
81 | }) | 84 | }) |
82 | 85 | ||
83 | it('Should not login with an invalid username', async function () { | 86 | describe('Login', function () { |
84 | const user = { username: 'captain crochet', password: server.user.password } | ||
85 | const res = await login(server.url, server.client, user, 400) | ||
86 | |||
87 | expect(res.body.error).to.contain('credentials are invalid') | ||
88 | }) | ||
89 | 87 | ||
90 | it('Should not login with an invalid password', async function () { | 88 | it('Should not login with an invalid username', async function () { |
91 | const user = { username: server.user.username, password: 'mew_three' } | 89 | const user = { username: 'captain crochet', password: server.user.password } |
92 | const res = await login(server.url, server.client, user, 400) | 90 | const res = await login(server.url, server.client, user, 400) |
93 | 91 | ||
94 | expect(res.body.error).to.contain('credentials are invalid') | 92 | expect(res.body.error).to.contain('credentials are invalid') |
95 | }) | 93 | }) |
96 | 94 | ||
97 | it('Should not be able to upload a video', async function () { | 95 | it('Should not login with an invalid password', async function () { |
98 | accessToken = 'my_super_token' | 96 | const user = { username: server.user.username, password: 'mew_three' } |
97 | const res = await login(server.url, server.client, user, 400) | ||
99 | 98 | ||
100 | const videoAttributes = {} | 99 | expect(res.body.error).to.contain('credentials are invalid') |
101 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | 100 | }) |
102 | }) | ||
103 | 101 | ||
104 | it('Should not be able to follow', async function () { | 102 | it('Should not be able to upload a video', async function () { |
105 | accessToken = 'my_super_token' | 103 | accessToken = 'my_super_token' |
106 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) | ||
107 | }) | ||
108 | 104 | ||
109 | it('Should not be able to unfollow') | 105 | const videoAttributes = {} |
106 | await uploadVideo(server.url, accessToken, videoAttributes, 401) | ||
107 | }) | ||
110 | 108 | ||
111 | it('Should be able to login', async function () { | 109 | it('Should not be able to follow', async function () { |
112 | const res = await login(server.url, server.client, server.user, 200) | 110 | accessToken = 'my_super_token' |
111 | await follow(server.url, [ 'http://example.com' ], accessToken, 401) | ||
112 | }) | ||
113 | 113 | ||
114 | accessToken = res.body.access_token | 114 | it('Should not be able to unfollow') |
115 | }) | ||
116 | 115 | ||
117 | it('Should upload the video with the correct token', async function () { | 116 | it('Should be able to login', async function () { |
118 | const videoAttributes = {} | 117 | const res = await login(server.url, server.client, server.user, 200) |
119 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
120 | const res = await getVideosList(server.url) | ||
121 | const video = res.body.data[ 0 ] | ||
122 | 118 | ||
123 | expect(video.account.name).to.equal('root') | 119 | accessToken = res.body.access_token |
124 | videoId = video.id | 120 | }) |
125 | }) | 121 | }) |
126 | 122 | ||
127 | it('Should upload the video again with the correct token', async function () { | 123 | describe('Upload', function () { |
128 | const videoAttributes = {} | ||
129 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
130 | }) | ||
131 | 124 | ||
132 | it('Should retrieve a video rating', async function () { | 125 | it('Should upload the video with the correct token', async function () { |
133 | await rateVideo(server.url, accessToken, videoId, 'like') | 126 | const videoAttributes = {} |
134 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | 127 | await uploadVideo(server.url, accessToken, videoAttributes) |
135 | const rating = res.body | 128 | const res = await getVideosList(server.url) |
129 | const video = res.body.data[ 0 ] | ||
136 | 130 | ||
137 | expect(rating.videoId).to.equal(videoId) | 131 | expect(video.account.name).to.equal('root') |
138 | expect(rating.rating).to.equal('like') | 132 | videoId = video.id |
133 | }) | ||
134 | |||
135 | it('Should upload the video again with the correct token', async function () { | ||
136 | const videoAttributes = {} | ||
137 | await uploadVideo(server.url, accessToken, videoAttributes) | ||
138 | }) | ||
139 | }) | 139 | }) |
140 | 140 | ||
141 | it('Should retrieve ratings list', async function () { | 141 | describe('Ratings', function () { |
142 | await rateVideo(server.url, accessToken, videoId, 'like') | ||
143 | 142 | ||
144 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) | 143 | it('Should retrieve a video rating', async function () { |
145 | const ratings = res.body | 144 | await rateVideo(server.url, accessToken, videoId, 'like') |
145 | const res = await getMyUserVideoRating(server.url, accessToken, videoId) | ||
146 | const rating = res.body | ||
146 | 147 | ||
147 | expect(ratings.total).to.equal(1) | 148 | expect(rating.videoId).to.equal(videoId) |
148 | expect(ratings.data[0].video.id).to.equal(videoId) | 149 | expect(rating.rating).to.equal('like') |
149 | expect(ratings.data[0].rating).to.equal('like') | 150 | }) |
150 | }) | ||
151 | 151 | ||
152 | it('Should retrieve ratings list by rating type', async function () { | 152 | it('Should retrieve ratings list', async function () { |
153 | { | 153 | await rateVideo(server.url, accessToken, videoId, 'like') |
154 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | ||
155 | const ratings = res.body | ||
156 | expect(ratings.data.length).to.equal(1) | ||
157 | } | ||
158 | 154 | ||
159 | { | 155 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, null, 200) |
160 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | ||
161 | const ratings = res.body | 156 | const ratings = res.body |
162 | expect(ratings.data.length).to.equal(0) | ||
163 | } | ||
164 | }) | ||
165 | |||
166 | it('Should not be able to remove the video with an incorrect token', async function () { | ||
167 | await removeVideo(server.url, 'bad_token', videoId, 401) | ||
168 | }) | ||
169 | 157 | ||
170 | it('Should not be able to remove the video with the token of another account') | 158 | expect(ratings.total).to.equal(1) |
159 | expect(ratings.data[ 0 ].video.id).to.equal(videoId) | ||
160 | expect(ratings.data[ 0 ].rating).to.equal('like') | ||
161 | }) | ||
171 | 162 | ||
172 | it('Should be able to remove the video with the correct token', async function () { | 163 | it('Should retrieve ratings list by rating type', async function () { |
173 | await removeVideo(server.url, accessToken, videoId) | 164 | { |
165 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'like') | ||
166 | const ratings = res.body | ||
167 | expect(ratings.data.length).to.equal(1) | ||
168 | } | ||
169 | |||
170 | { | ||
171 | const res = await getAccountRatings(server.url, server.user.username, server.accessToken, 'dislike') | ||
172 | const ratings = res.body | ||
173 | expect(ratings.data.length).to.equal(0) | ||
174 | } | ||
175 | }) | ||
174 | }) | 176 | }) |
175 | 177 | ||
176 | it('Should logout (revoke token)') | 178 | describe('Remove video', function () { |
177 | 179 | it('Should not be able to remove the video with an incorrect token', async function () { | |
178 | it('Should not be able to get the user information') | 180 | await removeVideo(server.url, 'bad_token', videoId, 401) |
179 | 181 | }) | |
180 | it('Should not be able to upload a video') | ||
181 | |||
182 | it('Should not be able to remove a video') | ||
183 | 182 | ||
184 | it('Should not be able to rate a video', async function () { | 183 | it('Should not be able to remove the video with the token of another account') |
185 | const path = '/api/v1/videos/' | ||
186 | const data = { | ||
187 | rating: 'likes' | ||
188 | } | ||
189 | 184 | ||
190 | const options = { | 185 | it('Should be able to remove the video with the correct token', async function () { |
191 | url: server.url, | 186 | await removeVideo(server.url, accessToken, videoId) |
192 | path: path + videoId, | 187 | }) |
193 | token: 'wrong token', | ||
194 | fields: data, | ||
195 | statusCodeExpected: 401 | ||
196 | } | ||
197 | await makePutBodyRequest(options) | ||
198 | }) | 188 | }) |
199 | 189 | ||
200 | it('Should be able to login again') | 190 | describe('Logout', function () { |
191 | it('Should logout (revoke token)') | ||
201 | 192 | ||
202 | it('Should have an expired access token') | 193 | it('Should not be able to get the user information') |
203 | 194 | ||
204 | it('Should refresh the token') | 195 | it('Should not be able to upload a video') |
205 | 196 | ||
206 | it('Should be able to upload a video again') | 197 | it('Should not be able to remove a video') |
207 | 198 | ||
208 | it('Should be able to create a new user', async function () { | 199 | it('Should not be able to rate a video', async function () { |
209 | await createUser(server.url, accessToken, user.username, user.password, 2 * 1024 * 1024) | 200 | const path = '/api/v1/videos/' |
210 | }) | 201 | const data = { |
202 | rating: 'likes' | ||
203 | } | ||
211 | 204 | ||
212 | it('Should be able to login with this user', async function () { | 205 | const options = { |
213 | accessTokenUser = await userLogin(server, user) | 206 | url: server.url, |
214 | }) | 207 | path: path + videoId, |
208 | token: 'wrong token', | ||
209 | fields: data, | ||
210 | statusCodeExpected: 401 | ||
211 | } | ||
212 | await makePutBodyRequest(options) | ||
213 | }) | ||
215 | 214 | ||
216 | it('Should be able to get the user information', async function () { | 215 | it('Should be able to login again') |
217 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
218 | const user = res.body | ||
219 | |||
220 | expect(user.username).to.equal('user_1') | ||
221 | expect(user.email).to.equal('user_1@example.com') | ||
222 | expect(user.nsfwPolicy).to.equal('display') | ||
223 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
224 | expect(user.roleLabel).to.equal('User') | ||
225 | expect(user.id).to.be.a('number') | ||
226 | expect(user.account.displayName).to.equal('user_1') | ||
227 | expect(user.account.description).to.be.null | ||
228 | }) | ||
229 | 216 | ||
230 | it('Should be able to upload a video with this user', async function () { | 217 | it('Should have an expired access token') |
231 | this.timeout(5000) | ||
232 | 218 | ||
233 | const videoAttributes = { | 219 | it('Should refresh the token') |
234 | name: 'super user video', | 220 | |
235 | fixture: 'video_short.webm' | 221 | it('Should be able to upload a video again') |
236 | } | ||
237 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | ||
238 | }) | 222 | }) |
239 | 223 | ||
240 | it('Should have video quota updated', async function () { | 224 | describe('Creating a user', function () { |
241 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) | ||
242 | const data = res.body | ||
243 | 225 | ||
244 | expect(data.videoQuotaUsed).to.equal(218910) | 226 | it('Should be able to create a new user', async function () { |
227 | await createUser({ | ||
228 | url: server.url, | ||
229 | accessToken: accessToken, | ||
230 | username: user.username, | ||
231 | password: user.password, | ||
232 | videoQuota: 2 * 1024 * 1024, | ||
233 | adminFlags: UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST | ||
234 | }) | ||
235 | }) | ||
245 | 236 | ||
246 | const resUsers = await getUsersList(server.url, server.accessToken) | 237 | it('Should be able to login with this user', async function () { |
238 | accessTokenUser = await userLogin(server, user) | ||
239 | }) | ||
247 | 240 | ||
248 | const users: User[] = resUsers.body.data | 241 | it('Should be able to get user information', async function () { |
249 | const tmpUser = users.find(u => u.username === user.username) | 242 | const res1 = await getMyUserInformation(server.url, accessTokenUser) |
250 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | 243 | const userMe: User = res1.body |
244 | |||
245 | const res2 = await getUserInformation(server.url, server.accessToken, userMe.id) | ||
246 | const userGet: User = res2.body | ||
247 | |||
248 | for (const user of [ userMe, userGet ]) { | ||
249 | expect(user.username).to.equal('user_1') | ||
250 | expect(user.email).to.equal('user_1@example.com') | ||
251 | expect(user.nsfwPolicy).to.equal('display') | ||
252 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
253 | expect(user.roleLabel).to.equal('User') | ||
254 | expect(user.id).to.be.a('number') | ||
255 | expect(user.account.displayName).to.equal('user_1') | ||
256 | expect(user.account.description).to.be.null | ||
257 | } | ||
258 | |||
259 | expect(userMe.adminFlags).to.be.undefined | ||
260 | expect(userGet.adminFlags).to.equal(UserAdminFlag.BY_PASS_VIDEO_AUTO_BLACKLIST) | ||
261 | }) | ||
251 | }) | 262 | }) |
252 | 263 | ||
253 | it('Should be able to list my videos', async function () { | 264 | describe('My videos & quotas', function () { |
254 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) | ||
255 | expect(res.body.total).to.equal(1) | ||
256 | |||
257 | const videos = res.body.data | ||
258 | expect(videos).to.have.lengthOf(1) | ||
259 | 265 | ||
260 | expect(videos[ 0 ].name).to.equal('super user video') | 266 | it('Should be able to upload a video with this user', async function () { |
261 | }) | 267 | this.timeout(5000) |
262 | |||
263 | it('Should list all the users', async function () { | ||
264 | const res = await getUsersList(server.url, server.accessToken) | ||
265 | const result = res.body | ||
266 | const total = result.total | ||
267 | const users = result.data | ||
268 | 268 | ||
269 | expect(total).to.equal(2) | 269 | const videoAttributes = { |
270 | expect(users).to.be.an('array') | 270 | name: 'super user video', |
271 | expect(users.length).to.equal(2) | 271 | fixture: 'video_short.webm' |
272 | } | ||
273 | await uploadVideo(server.url, accessTokenUser, videoAttributes) | ||
274 | }) | ||
272 | 275 | ||
273 | const user = users[ 0 ] | 276 | it('Should have video quota updated', async function () { |
274 | expect(user.username).to.equal('user_1') | 277 | const res = await getMyUserVideoQuotaUsed(server.url, accessTokenUser) |
275 | expect(user.email).to.equal('user_1@example.com') | 278 | const data = res.body |
276 | expect(user.nsfwPolicy).to.equal('display') | ||
277 | 279 | ||
278 | const rootUser = users[ 1 ] | 280 | expect(data.videoQuotaUsed).to.equal(218910) |
279 | expect(rootUser.username).to.equal('root') | ||
280 | expect(rootUser.email).to.equal('admin1@example.com') | ||
281 | expect(user.nsfwPolicy).to.equal('display') | ||
282 | 281 | ||
283 | userId = user.id | 282 | const resUsers = await getUsersList(server.url, server.accessToken) |
284 | }) | ||
285 | 283 | ||
286 | it('Should list only the first user by username asc', async function () { | 284 | const users: User[] = resUsers.body.data |
287 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') | 285 | const tmpUser = users.find(u => u.username === user.username) |
286 | expect(tmpUser.videoQuotaUsed).to.equal(218910) | ||
287 | }) | ||
288 | 288 | ||
289 | const result = res.body | 289 | it('Should be able to list my videos', async function () { |
290 | const total = result.total | 290 | const res = await getMyVideos(server.url, accessTokenUser, 0, 5) |
291 | const users = result.data | 291 | expect(res.body.total).to.equal(1) |
292 | 292 | ||
293 | expect(total).to.equal(2) | 293 | const videos = res.body.data |
294 | expect(users.length).to.equal(1) | 294 | expect(videos).to.have.lengthOf(1) |
295 | 295 | ||
296 | const user = users[ 0 ] | 296 | expect(videos[ 0 ].name).to.equal('super user video') |
297 | expect(user.username).to.equal('root') | 297 | }) |
298 | expect(user.email).to.equal('admin1@example.com') | ||
299 | expect(user.roleLabel).to.equal('Administrator') | ||
300 | expect(user.nsfwPolicy).to.equal('display') | ||
301 | }) | 298 | }) |
302 | 299 | ||
303 | it('Should list only the first user by username desc', async function () { | 300 | describe('Users listing', function () { |
304 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') | ||
305 | const result = res.body | ||
306 | const total = result.total | ||
307 | const users = result.data | ||
308 | 301 | ||
309 | expect(total).to.equal(2) | 302 | it('Should list all the users', async function () { |
310 | expect(users.length).to.equal(1) | 303 | const res = await getUsersList(server.url, server.accessToken) |
304 | const result = res.body | ||
305 | const total = result.total | ||
306 | const users = result.data | ||
311 | 307 | ||
312 | const user = users[ 0 ] | 308 | expect(total).to.equal(2) |
313 | expect(user.username).to.equal('user_1') | 309 | expect(users).to.be.an('array') |
314 | expect(user.email).to.equal('user_1@example.com') | 310 | expect(users.length).to.equal(2) |
315 | expect(user.nsfwPolicy).to.equal('display') | ||
316 | }) | ||
317 | 311 | ||
318 | it('Should list only the second user by createdAt desc', async function () { | 312 | const user = users[ 0 ] |
319 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') | 313 | expect(user.username).to.equal('user_1') |
320 | const result = res.body | 314 | expect(user.email).to.equal('user_1@example.com') |
321 | const total = result.total | 315 | expect(user.nsfwPolicy).to.equal('display') |
322 | const users = result.data | ||
323 | 316 | ||
324 | expect(total).to.equal(2) | 317 | const rootUser = users[ 1 ] |
325 | expect(users.length).to.equal(1) | 318 | expect(rootUser.username).to.equal('root') |
319 | expect(rootUser.email).to.equal('admin1@example.com') | ||
320 | expect(user.nsfwPolicy).to.equal('display') | ||
326 | 321 | ||
327 | const user = users[ 0 ] | 322 | userId = user.id |
328 | expect(user.username).to.equal('user_1') | 323 | }) |
329 | expect(user.email).to.equal('user_1@example.com') | ||
330 | expect(user.nsfwPolicy).to.equal('display') | ||
331 | }) | ||
332 | 324 | ||
333 | it('Should list all the users by createdAt asc', async function () { | 325 | it('Should list only the first user by username asc', async function () { |
334 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') | 326 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, 'username') |
335 | const result = res.body | ||
336 | const total = result.total | ||
337 | const users = result.data | ||
338 | 327 | ||
339 | expect(total).to.equal(2) | 328 | const result = res.body |
340 | expect(users.length).to.equal(2) | 329 | const total = result.total |
330 | const users = result.data | ||
341 | 331 | ||
342 | expect(users[ 0 ].username).to.equal('root') | 332 | expect(total).to.equal(2) |
343 | expect(users[ 0 ].email).to.equal('admin1@example.com') | 333 | expect(users.length).to.equal(1) |
344 | expect(users[ 0 ].nsfwPolicy).to.equal('display') | ||
345 | 334 | ||
346 | expect(users[ 1 ].username).to.equal('user_1') | 335 | const user = users[ 0 ] |
347 | expect(users[ 1 ].email).to.equal('user_1@example.com') | 336 | expect(user.username).to.equal('root') |
348 | expect(users[ 1 ].nsfwPolicy).to.equal('display') | 337 | expect(user.email).to.equal('admin1@example.com') |
349 | }) | 338 | expect(user.roleLabel).to.equal('Administrator') |
339 | expect(user.nsfwPolicy).to.equal('display') | ||
340 | }) | ||
350 | 341 | ||
351 | it('Should search user by username', async function () { | 342 | it('Should list only the first user by username desc', async function () { |
352 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') | 343 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-username') |
353 | const users = res.body.data as User[] | 344 | const result = res.body |
345 | const total = result.total | ||
346 | const users = result.data | ||
354 | 347 | ||
355 | expect(res.body.total).to.equal(1) | 348 | expect(total).to.equal(2) |
356 | expect(users.length).to.equal(1) | 349 | expect(users.length).to.equal(1) |
357 | 350 | ||
358 | expect(users[ 0 ].username).to.equal('root') | 351 | const user = users[ 0 ] |
359 | }) | 352 | expect(user.username).to.equal('user_1') |
353 | expect(user.email).to.equal('user_1@example.com') | ||
354 | expect(user.nsfwPolicy).to.equal('display') | ||
355 | }) | ||
360 | 356 | ||
361 | it('Should search user by email', async function () { | 357 | it('Should list only the second user by createdAt desc', async function () { |
362 | { | 358 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 1, '-createdAt') |
363 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | 359 | const result = res.body |
364 | const users = res.body.data as User[] | 360 | const total = result.total |
361 | const users = result.data | ||
365 | 362 | ||
366 | expect(res.body.total).to.equal(1) | 363 | expect(total).to.equal(2) |
367 | expect(users.length).to.equal(1) | 364 | expect(users.length).to.equal(1) |
368 | 365 | ||
369 | expect(users[ 0 ].username).to.equal('user_1') | 366 | const user = users[ 0 ] |
370 | expect(users[ 0 ].email).to.equal('user_1@example.com') | 367 | expect(user.username).to.equal('user_1') |
371 | } | 368 | expect(user.email).to.equal('user_1@example.com') |
369 | expect(user.nsfwPolicy).to.equal('display') | ||
370 | }) | ||
372 | 371 | ||
373 | { | 372 | it('Should list all the users by createdAt asc', async function () { |
374 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') | 373 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt') |
375 | const users = res.body.data as User[] | 374 | const result = res.body |
375 | const total = result.total | ||
376 | const users = result.data | ||
376 | 377 | ||
377 | expect(res.body.total).to.equal(2) | 378 | expect(total).to.equal(2) |
378 | expect(users.length).to.equal(2) | 379 | expect(users.length).to.equal(2) |
379 | 380 | ||
380 | expect(users[ 0 ].username).to.equal('root') | 381 | expect(users[ 0 ].username).to.equal('root') |
381 | expect(users[ 1 ].username).to.equal('user_1') | 382 | expect(users[ 0 ].email).to.equal('admin1@example.com') |
382 | } | 383 | expect(users[ 0 ].nsfwPolicy).to.equal('display') |
383 | }) | ||
384 | 384 | ||
385 | it('Should update my password', async function () { | 385 | expect(users[ 1 ].username).to.equal('user_1') |
386 | await updateMyUser({ | 386 | expect(users[ 1 ].email).to.equal('user_1@example.com') |
387 | url: server.url, | 387 | expect(users[ 1 ].nsfwPolicy).to.equal('display') |
388 | accessToken: accessTokenUser, | ||
389 | currentPassword: 'super password', | ||
390 | newPassword: 'new password' | ||
391 | }) | 388 | }) |
392 | user.password = 'new password' | ||
393 | 389 | ||
394 | await userLogin(server, user, 200) | 390 | it('Should search user by username', async function () { |
395 | }) | 391 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'oot') |
392 | const users = res.body.data as User[] | ||
393 | |||
394 | expect(res.body.total).to.equal(1) | ||
395 | expect(users.length).to.equal(1) | ||
396 | 396 | ||
397 | it('Should be able to change the NSFW display attribute', async function () { | 397 | expect(users[ 0 ].username).to.equal('root') |
398 | await updateMyUser({ | ||
399 | url: server.url, | ||
400 | accessToken: accessTokenUser, | ||
401 | nsfwPolicy: 'do_not_list' | ||
402 | }) | 398 | }) |
403 | 399 | ||
404 | const res = await getMyUserInformation(server.url, accessTokenUser) | 400 | it('Should search user by email', async function () { |
405 | const user = res.body | 401 | { |
402 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'r_1@exam') | ||
403 | const users = res.body.data as User[] | ||
406 | 404 | ||
407 | expect(user.username).to.equal('user_1') | 405 | expect(res.body.total).to.equal(1) |
408 | expect(user.email).to.equal('user_1@example.com') | 406 | expect(users.length).to.equal(1) |
409 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
410 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
411 | expect(user.id).to.be.a('number') | ||
412 | expect(user.account.displayName).to.equal('user_1') | ||
413 | expect(user.account.description).to.be.null | ||
414 | }) | ||
415 | 407 | ||
416 | it('Should be able to change the autoPlayVideo attribute', async function () { | 408 | expect(users[ 0 ].username).to.equal('user_1') |
417 | await updateMyUser({ | 409 | expect(users[ 0 ].email).to.equal('user_1@example.com') |
418 | url: server.url, | 410 | } |
419 | accessToken: accessTokenUser, | ||
420 | autoPlayVideo: false | ||
421 | }) | ||
422 | 411 | ||
423 | const res = await getMyUserInformation(server.url, accessTokenUser) | 412 | { |
424 | const user = res.body | 413 | const res = await getUsersListPaginationAndSort(server.url, server.accessToken, 0, 2, 'createdAt', 'example') |
414 | const users = res.body.data as User[] | ||
425 | 415 | ||
426 | expect(user.autoPlayVideo).to.be.false | 416 | expect(res.body.total).to.equal(2) |
427 | }) | 417 | expect(users.length).to.equal(2) |
428 | 418 | ||
429 | it('Should be able to change the email display attribute', async function () { | 419 | expect(users[ 0 ].username).to.equal('root') |
430 | await updateMyUser({ | 420 | expect(users[ 1 ].username).to.equal('user_1') |
431 | url: server.url, | 421 | } |
432 | accessToken: accessTokenUser, | ||
433 | email: 'updated@example.com' | ||
434 | }) | 422 | }) |
435 | |||
436 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
437 | const user = res.body | ||
438 | |||
439 | expect(user.username).to.equal('user_1') | ||
440 | expect(user.email).to.equal('updated@example.com') | ||
441 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
442 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
443 | expect(user.id).to.be.a('number') | ||
444 | expect(user.account.displayName).to.equal('user_1') | ||
445 | expect(user.account.description).to.be.null | ||
446 | }) | 423 | }) |
447 | 424 | ||
448 | it('Should be able to update my avatar', async function () { | 425 | describe('Update my account', function () { |
449 | const fixture = 'avatar.png' | 426 | it('Should update my password', async function () { |
427 | await updateMyUser({ | ||
428 | url: server.url, | ||
429 | accessToken: accessTokenUser, | ||
430 | currentPassword: 'super password', | ||
431 | newPassword: 'new password' | ||
432 | }) | ||
433 | user.password = 'new password' | ||
450 | 434 | ||
451 | await updateMyAvatar({ | 435 | await userLogin(server, user, 200) |
452 | url: server.url, | ||
453 | accessToken: accessTokenUser, | ||
454 | fixture | ||
455 | }) | 436 | }) |
456 | 437 | ||
457 | const res = await getMyUserInformation(server.url, accessTokenUser) | 438 | it('Should be able to change the NSFW display attribute', async function () { |
458 | const user = res.body | 439 | await updateMyUser({ |
440 | url: server.url, | ||
441 | accessToken: accessTokenUser, | ||
442 | nsfwPolicy: 'do_not_list' | ||
443 | }) | ||
444 | |||
445 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
446 | const user = res.body | ||
447 | |||
448 | expect(user.username).to.equal('user_1') | ||
449 | expect(user.email).to.equal('user_1@example.com') | ||
450 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
451 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
452 | expect(user.id).to.be.a('number') | ||
453 | expect(user.account.displayName).to.equal('user_1') | ||
454 | expect(user.account.description).to.be.null | ||
455 | }) | ||
459 | 456 | ||
460 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') | 457 | it('Should be able to change the autoPlayVideo attribute', async function () { |
461 | }) | 458 | await updateMyUser({ |
459 | url: server.url, | ||
460 | accessToken: accessTokenUser, | ||
461 | autoPlayVideo: false | ||
462 | }) | ||
462 | 463 | ||
463 | it('Should be able to update my display name', async function () { | 464 | const res = await getMyUserInformation(server.url, accessTokenUser) |
464 | await updateMyUser({ | 465 | const user = res.body |
465 | url: server.url, | 466 | |
466 | accessToken: accessTokenUser, | 467 | expect(user.autoPlayVideo).to.be.false |
467 | displayName: 'new display name' | ||
468 | }) | 468 | }) |
469 | 469 | ||
470 | const res = await getMyUserInformation(server.url, accessTokenUser) | 470 | it('Should be able to change the email display attribute', async function () { |
471 | const user = res.body | 471 | await updateMyUser({ |
472 | url: server.url, | ||
473 | accessToken: accessTokenUser, | ||
474 | email: 'updated@example.com' | ||
475 | }) | ||
476 | |||
477 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
478 | const user = res.body | ||
479 | |||
480 | expect(user.username).to.equal('user_1') | ||
481 | expect(user.email).to.equal('updated@example.com') | ||
482 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
483 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
484 | expect(user.id).to.be.a('number') | ||
485 | expect(user.account.displayName).to.equal('user_1') | ||
486 | expect(user.account.description).to.be.null | ||
487 | }) | ||
472 | 488 | ||
473 | expect(user.username).to.equal('user_1') | 489 | it('Should be able to update my avatar', async function () { |
474 | expect(user.email).to.equal('updated@example.com') | 490 | const fixture = 'avatar.png' |
475 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
476 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
477 | expect(user.id).to.be.a('number') | ||
478 | expect(user.account.displayName).to.equal('new display name') | ||
479 | expect(user.account.description).to.be.null | ||
480 | }) | ||
481 | 491 | ||
482 | it('Should be able to update my description', async function () { | 492 | await updateMyAvatar({ |
483 | await updateMyUser({ | 493 | url: server.url, |
484 | url: server.url, | 494 | accessToken: accessTokenUser, |
485 | accessToken: accessTokenUser, | 495 | fixture |
486 | description: 'my super description updated' | 496 | }) |
487 | }) | ||
488 | 497 | ||
489 | const res = await getMyUserInformation(server.url, accessTokenUser) | 498 | const res = await getMyUserInformation(server.url, accessTokenUser) |
490 | const user = res.body | 499 | const user = res.body |
491 | 500 | ||
492 | expect(user.username).to.equal('user_1') | 501 | await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.png') |
493 | expect(user.email).to.equal('updated@example.com') | 502 | }) |
494 | expect(user.nsfwPolicy).to.equal('do_not_list') | 503 | |
495 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | 504 | it('Should be able to update my display name', async function () { |
496 | expect(user.id).to.be.a('number') | 505 | await updateMyUser({ |
497 | expect(user.account.displayName).to.equal('new display name') | 506 | url: server.url, |
498 | expect(user.account.description).to.equal('my super description updated') | 507 | accessToken: accessTokenUser, |
499 | }) | 508 | displayName: 'new display name' |
509 | }) | ||
510 | |||
511 | const res = await getMyUserInformation(server.url, accessTokenUser) | ||
512 | const user = res.body | ||
513 | |||
514 | expect(user.username).to.equal('user_1') | ||
515 | expect(user.email).to.equal('updated@example.com') | ||
516 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
517 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | ||
518 | expect(user.id).to.be.a('number') | ||
519 | expect(user.account.displayName).to.equal('new display name') | ||
520 | expect(user.account.description).to.be.null | ||
521 | }) | ||
500 | 522 | ||
501 | it('Should be able to update another user', async function () { | 523 | it('Should be able to update my description', async function () { |
502 | await updateUser({ | 524 | await updateMyUser({ |
503 | url: server.url, | 525 | url: server.url, |
504 | userId, | 526 | accessToken: accessTokenUser, |
505 | accessToken, | 527 | description: 'my super description updated' |
506 | email: 'updated2@example.com', | 528 | }) |
507 | emailVerified: true, | 529 | |
508 | videoQuota: 42, | 530 | const res = await getMyUserInformation(server.url, accessTokenUser) |
509 | role: UserRole.MODERATOR | 531 | const user = res.body |
510 | }) | 532 | |
511 | 533 | expect(user.username).to.equal('user_1') | |
512 | const res = await getUserInformation(server.url, accessToken, userId) | 534 | expect(user.email).to.equal('updated@example.com') |
513 | const user = res.body | 535 | expect(user.nsfwPolicy).to.equal('do_not_list') |
514 | 536 | expect(user.videoQuota).to.equal(2 * 1024 * 1024) | |
515 | expect(user.username).to.equal('user_1') | 537 | expect(user.id).to.be.a('number') |
516 | expect(user.email).to.equal('updated2@example.com') | 538 | expect(user.account.displayName).to.equal('new display name') |
517 | expect(user.emailVerified).to.be.true | 539 | expect(user.account.description).to.equal('my super description updated') |
518 | expect(user.nsfwPolicy).to.equal('do_not_list') | 540 | }) |
519 | expect(user.videoQuota).to.equal(42) | ||
520 | expect(user.roleLabel).to.equal('Moderator') | ||
521 | expect(user.id).to.be.a('number') | ||
522 | }) | 541 | }) |
523 | 542 | ||
524 | it('Should have removed the user token', async function () { | 543 | describe('Updating another user', function () { |
525 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | 544 | |
545 | it('Should be able to update another user', async function () { | ||
546 | await updateUser({ | ||
547 | url: server.url, | ||
548 | userId, | ||
549 | accessToken, | ||
550 | email: 'updated2@example.com', | ||
551 | emailVerified: true, | ||
552 | videoQuota: 42, | ||
553 | role: UserRole.MODERATOR, | ||
554 | adminFlags: UserAdminFlag.NONE | ||
555 | }) | ||
556 | |||
557 | const res = await getUserInformation(server.url, accessToken, userId) | ||
558 | const user = res.body | ||
559 | |||
560 | expect(user.username).to.equal('user_1') | ||
561 | expect(user.email).to.equal('updated2@example.com') | ||
562 | expect(user.emailVerified).to.be.true | ||
563 | expect(user.nsfwPolicy).to.equal('do_not_list') | ||
564 | expect(user.videoQuota).to.equal(42) | ||
565 | expect(user.roleLabel).to.equal('Moderator') | ||
566 | expect(user.id).to.be.a('number') | ||
567 | expect(user.adminFlags).to.equal(UserAdminFlag.NONE) | ||
568 | }) | ||
526 | 569 | ||
527 | accessTokenUser = await userLogin(server, user) | 570 | it('Should have removed the user token', async function () { |
528 | }) | 571 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) |
529 | 572 | ||
530 | it('Should be able to update another user password', async function () { | 573 | accessTokenUser = await userLogin(server, user) |
531 | await updateUser({ | ||
532 | url: server.url, | ||
533 | userId, | ||
534 | accessToken, | ||
535 | password: 'password updated' | ||
536 | }) | 574 | }) |
537 | 575 | ||
538 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) | 576 | it('Should be able to update another user password', async function () { |
577 | await updateUser({ | ||
578 | url: server.url, | ||
579 | userId, | ||
580 | accessToken, | ||
581 | password: 'password updated' | ||
582 | }) | ||
539 | 583 | ||
540 | await userLogin(server, user, 400) | 584 | await getMyUserVideoQuotaUsed(server.url, accessTokenUser, 401) |
541 | 585 | ||
542 | user.password = 'password updated' | 586 | await userLogin(server, user, 400) |
543 | accessTokenUser = await userLogin(server, user) | ||
544 | }) | ||
545 | 587 | ||
546 | it('Should be able to list video blacklist by a moderator', async function () { | 588 | user.password = 'password updated' |
547 | await getBlacklistedVideosList(server.url, accessTokenUser) | 589 | accessTokenUser = await userLogin(server, user) |
590 | }) | ||
548 | }) | 591 | }) |
549 | 592 | ||
550 | it('Should be able to remove this user', async function () { | 593 | describe('Video blacklists', function () { |
551 | await removeUser(server.url, userId, accessToken) | 594 | it('Should be able to list video blacklist by a moderator', async function () { |
595 | await getBlacklistedVideosList({ url: server.url, token: accessTokenUser }) | ||
596 | }) | ||
552 | }) | 597 | }) |
553 | 598 | ||
554 | it('Should not be able to login with this user', async function () { | 599 | describe('Remove a user', function () { |
555 | await userLogin(server, user, 400) | 600 | it('Should be able to remove this user', async function () { |
556 | }) | 601 | await removeUser(server.url, userId, accessToken) |
602 | }) | ||
557 | 603 | ||
558 | it('Should not have videos of this user', async function () { | 604 | it('Should not be able to login with this user', async function () { |
559 | const res = await getVideosList(server.url) | 605 | await userLogin(server, user, 400) |
606 | }) | ||
560 | 607 | ||
561 | expect(res.body.total).to.equal(1) | 608 | it('Should not have videos of this user', async function () { |
609 | const res = await getVideosList(server.url) | ||
562 | 610 | ||
563 | const video = res.body.data[ 0 ] | 611 | expect(res.body.total).to.equal(1) |
564 | expect(video.account.name).to.equal('root') | ||
565 | }) | ||
566 | 612 | ||
567 | it('Should register a new user', async function () { | 613 | const video = res.body.data[ 0 ] |
568 | await registerUser(server.url, 'user_15', 'my super password') | 614 | expect(video.account.name).to.equal('root') |
615 | }) | ||
569 | }) | 616 | }) |
570 | 617 | ||
571 | it('Should be able to login with this registered user', async function () { | 618 | describe('Registering a new user', function () { |
572 | const user15 = { | 619 | it('Should register a new user', async function () { |
573 | username: 'user_15', | 620 | await registerUser(server.url, 'user_15', 'my super password') |
574 | password: 'my super password' | 621 | }) |
575 | } | ||
576 | 622 | ||
577 | accessToken = await userLogin(server, user15) | 623 | it('Should be able to login with this registered user', async function () { |
578 | }) | 624 | const user15 = { |
625 | username: 'user_15', | ||
626 | password: 'my super password' | ||
627 | } | ||
579 | 628 | ||
580 | it('Should have the correct video quota', async function () { | 629 | accessToken = await userLogin(server, user15) |
581 | const res = await getMyUserInformation(server.url, accessToken) | 630 | }) |
582 | const user = res.body | ||
583 | 631 | ||
584 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) | 632 | it('Should have the correct video quota', async function () { |
585 | }) | 633 | const res = await getMyUserInformation(server.url, accessToken) |
634 | const user = res.body | ||
586 | 635 | ||
587 | it('Should remove me', async function () { | 636 | expect(user.videoQuota).to.equal(5 * 1024 * 1024) |
588 | { | 637 | }) |
589 | const res = await getUsersList(server.url, server.accessToken) | ||
590 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | ||
591 | } | ||
592 | 638 | ||
593 | await deleteMe(server.url, accessToken) | 639 | it('Should remove me', async function () { |
640 | { | ||
641 | const res = await getUsersList(server.url, server.accessToken) | ||
642 | expect(res.body.data.find(u => u.username === 'user_15')).to.not.be.undefined | ||
643 | } | ||
594 | 644 | ||
595 | { | 645 | await deleteMe(server.url, accessToken) |
596 | const res = await getUsersList(server.url, server.accessToken) | 646 | |
597 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | 647 | { |
598 | } | 648 | const res = await getUsersList(server.url, server.accessToken) |
649 | expect(res.body.data.find(u => u.username === 'user_15')).to.be.undefined | ||
650 | } | ||
651 | }) | ||
599 | }) | 652 | }) |
600 | 653 | ||
601 | it('Should block and unblock a user', async function () { | 654 | describe('User blocking', function () { |
602 | const user16 = { | 655 | it('Should block and unblock a user', async function () { |
603 | username: 'user_16', | 656 | const user16 = { |
604 | password: 'my super password' | 657 | username: 'user_16', |
605 | } | 658 | password: 'my super password' |
606 | const resUser = await createUser(server.url, server.accessToken, user16.username, user16.password) | 659 | } |
607 | const user16Id = resUser.body.user.id | 660 | const resUser = await createUser({ |
661 | url: server.url, | ||
662 | accessToken: server.accessToken, | ||
663 | username: user16.username, | ||
664 | password: user16.password | ||
665 | }) | ||
666 | const user16Id = resUser.body.user.id | ||
608 | 667 | ||
609 | accessToken = await userLogin(server, user16) | 668 | accessToken = await userLogin(server, user16) |
610 | 669 | ||
611 | await getMyUserInformation(server.url, accessToken, 200) | 670 | await getMyUserInformation(server.url, accessToken, 200) |
612 | await blockUser(server.url, user16Id, server.accessToken) | 671 | await blockUser(server.url, user16Id, server.accessToken) |
613 | 672 | ||
614 | await getMyUserInformation(server.url, accessToken, 401) | 673 | await getMyUserInformation(server.url, accessToken, 401) |
615 | await userLogin(server, user16, 400) | 674 | await userLogin(server, user16, 400) |
616 | 675 | ||
617 | await unblockUser(server.url, user16Id, server.accessToken) | 676 | await unblockUser(server.url, user16Id, server.accessToken) |
618 | accessToken = await userLogin(server, user16) | 677 | accessToken = await userLogin(server, user16) |
619 | await getMyUserInformation(server.url, accessToken, 200) | 678 | await getMyUserInformation(server.url, accessToken, 200) |
679 | }) | ||
620 | }) | 680 | }) |
621 | 681 | ||
622 | after(async function () { | 682 | after(async function () { |