aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/users/users.ts
diff options
context:
space:
mode:
authorChocobozzz <me@florianbigard.com>2021-07-16 09:04:35 +0200
committerChocobozzz <me@florianbigard.com>2021-07-20 15:27:18 +0200
commit89d241a79c262b9775c233b73cff080043ebb5e6 (patch)
treecb3b6cb431d25d891ef4e02f66c61d252d17048f /server/tests/api/users/users.ts
parentd23dd9fbfc4d26026352c10f81d2795ceaf2908a (diff)
downloadPeerTube-89d241a79c262b9775c233b73cff080043ebb5e6.tar.gz
PeerTube-89d241a79c262b9775c233b73cff080043ebb5e6.tar.zst
PeerTube-89d241a79c262b9775c233b73cff080043ebb5e6.zip
Shorter server command names
Diffstat (limited to 'server/tests/api/users/users.ts')
-rw-r--r--server/tests/api/users/users.ts262
1 files changed, 131 insertions, 131 deletions
diff --git a/server/tests/api/users/users.ts b/server/tests/api/users/users.ts
index 6f3873939..310136a37 100644
--- a/server/tests/api/users/users.ts
+++ b/server/tests/api/users/users.ts
@@ -42,7 +42,7 @@ describe('Test users', function () {
42 42
43 await setAccessTokensToServers([ server ]) 43 await setAccessTokensToServers([ server ])
44 44
45 await server.pluginsCommand.install({ npmName: 'peertube-theme-background-red' }) 45 await server.plugins.install({ npmName: 'peertube-theme-background-red' })
46 }) 46 })
47 47
48 describe('OAuth client', function () { 48 describe('OAuth client', function () {
@@ -53,8 +53,8 @@ describe('Test users', function () {
53 it('Should remove the last client') 53 it('Should remove the last client')
54 54
55 it('Should not login with an invalid client id', async function () { 55 it('Should not login with an invalid client id', async function () {
56 const client = { id: 'client', secret: server.client.secret } 56 const client = { id: 'client', secret: server.store.client.secret }
57 const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 57 const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
58 58
59 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) 59 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
60 expect(body.error).to.contain('client is invalid') 60 expect(body.error).to.contain('client is invalid')
@@ -63,8 +63,8 @@ describe('Test users', function () {
63 }) 63 })
64 64
65 it('Should not login with an invalid client secret', async function () { 65 it('Should not login with an invalid client secret', async function () {
66 const client = { id: server.client.id, secret: 'coucou' } 66 const client = { id: server.store.client.id, secret: 'coucou' }
67 const body = await server.loginCommand.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 67 const body = await server.login.login({ client, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
68 68
69 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT) 69 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_CLIENT)
70 expect(body.error).to.contain('client is invalid') 70 expect(body.error).to.contain('client is invalid')
@@ -76,8 +76,8 @@ describe('Test users', function () {
76 describe('Login', function () { 76 describe('Login', function () {
77 77
78 it('Should not login with an invalid username', async function () { 78 it('Should not login with an invalid username', async function () {
79 const user = { username: 'captain crochet', password: server.user.password } 79 const user = { username: 'captain crochet', password: server.store.user.password }
80 const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 80 const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
81 81
82 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) 82 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
83 expect(body.error).to.contain('credentials are invalid') 83 expect(body.error).to.contain('credentials are invalid')
@@ -86,8 +86,8 @@ describe('Test users', function () {
86 }) 86 })
87 87
88 it('Should not login with an invalid password', async function () { 88 it('Should not login with an invalid password', async function () {
89 const user = { username: server.user.username, password: 'mew_three' } 89 const user = { username: server.store.user.username, password: 'mew_three' }
90 const body = await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 90 const body = await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
91 91
92 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT) 92 expect(body.code).to.equal(OAuth2ErrorCode.INVALID_GRANT)
93 expect(body.error).to.contain('credentials are invalid') 93 expect(body.error).to.contain('credentials are invalid')
@@ -98,13 +98,13 @@ describe('Test users', function () {
98 it('Should not be able to upload a video', async function () { 98 it('Should not be able to upload a video', async function () {
99 token = 'my_super_token' 99 token = 'my_super_token'
100 100
101 await server.videosCommand.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 101 await server.videos.upload({ token, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
102 }) 102 })
103 103
104 it('Should not be able to follow', async function () { 104 it('Should not be able to follow', async function () {
105 token = 'my_super_token' 105 token = 'my_super_token'
106 106
107 await server.followsCommand.follow({ 107 await server.follows.follow({
108 targets: [ 'http://example.com' ], 108 targets: [ 'http://example.com' ],
109 token, 109 token,
110 expectedStatus: HttpStatusCode.UNAUTHORIZED_401 110 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
@@ -114,28 +114,28 @@ describe('Test users', function () {
114 it('Should not be able to unfollow') 114 it('Should not be able to unfollow')
115 115
116 it('Should be able to login', async function () { 116 it('Should be able to login', async function () {
117 const body = await server.loginCommand.login({ expectedStatus: HttpStatusCode.OK_200 }) 117 const body = await server.login.login({ expectedStatus: HttpStatusCode.OK_200 })
118 118
119 token = body.access_token 119 token = body.access_token
120 }) 120 })
121 121
122 it('Should be able to login with an insensitive username', async function () { 122 it('Should be able to login with an insensitive username', async function () {
123 const user = { username: 'RoOt', password: server.user.password } 123 const user = { username: 'RoOt', password: server.store.user.password }
124 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.OK_200 }) 124 await server.login.login({ user, expectedStatus: HttpStatusCode.OK_200 })
125 125
126 const user2 = { username: 'rOoT', password: server.user.password } 126 const user2 = { username: 'rOoT', password: server.store.user.password }
127 await server.loginCommand.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 }) 127 await server.login.login({ user: user2, expectedStatus: HttpStatusCode.OK_200 })
128 128
129 const user3 = { username: 'ROOt', password: server.user.password } 129 const user3 = { username: 'ROOt', password: server.store.user.password }
130 await server.loginCommand.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 }) 130 await server.login.login({ user: user3, expectedStatus: HttpStatusCode.OK_200 })
131 }) 131 })
132 }) 132 })
133 133
134 describe('Upload', function () { 134 describe('Upload', function () {
135 135
136 it('Should upload the video with the correct token', async function () { 136 it('Should upload the video with the correct token', async function () {
137 await server.videosCommand.upload({ token }) 137 await server.videos.upload({ token })
138 const { data } = await server.videosCommand.list() 138 const { data } = await server.videos.list()
139 const video = data[0] 139 const video = data[0]
140 140
141 expect(video.account.name).to.equal('root') 141 expect(video.account.name).to.equal('root')
@@ -143,24 +143,24 @@ describe('Test users', function () {
143 }) 143 })
144 144
145 it('Should upload the video again with the correct token', async function () { 145 it('Should upload the video again with the correct token', async function () {
146 await server.videosCommand.upload({ token }) 146 await server.videos.upload({ token })
147 }) 147 })
148 }) 148 })
149 149
150 describe('Ratings', function () { 150 describe('Ratings', function () {
151 151
152 it('Should retrieve a video rating', async function () { 152 it('Should retrieve a video rating', async function () {
153 await server.videosCommand.rate({ id: videoId, rating: 'like' }) 153 await server.videos.rate({ id: videoId, rating: 'like' })
154 const rating = await server.usersCommand.getMyRating({ token, videoId }) 154 const rating = await server.users.getMyRating({ token, videoId })
155 155
156 expect(rating.videoId).to.equal(videoId) 156 expect(rating.videoId).to.equal(videoId)
157 expect(rating.rating).to.equal('like') 157 expect(rating.rating).to.equal('like')
158 }) 158 })
159 159
160 it('Should retrieve ratings list', async function () { 160 it('Should retrieve ratings list', async function () {
161 await server.videosCommand.rate({ id: videoId, rating: 'like' }) 161 await server.videos.rate({ id: videoId, rating: 'like' })
162 162
163 const body = await server.accountsCommand.listRatings({ accountName: server.user.username }) 163 const body = await server.accounts.listRatings({ accountName: server.store.user.username })
164 164
165 expect(body.total).to.equal(1) 165 expect(body.total).to.equal(1)
166 expect(body.data[0].video.id).to.equal(videoId) 166 expect(body.data[0].video.id).to.equal(videoId)
@@ -169,12 +169,12 @@ describe('Test users', function () {
169 169
170 it('Should retrieve ratings list by rating type', async function () { 170 it('Should retrieve ratings list by rating type', async function () {
171 { 171 {
172 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'like' }) 172 const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'like' })
173 expect(body.data.length).to.equal(1) 173 expect(body.data.length).to.equal(1)
174 } 174 }
175 175
176 { 176 {
177 const body = await server.accountsCommand.listRatings({ accountName: server.user.username, rating: 'dislike' }) 177 const body = await server.accounts.listRatings({ accountName: server.store.user.username, rating: 'dislike' })
178 expect(body.data.length).to.equal(0) 178 expect(body.data.length).to.equal(0)
179 } 179 }
180 }) 180 })
@@ -182,27 +182,27 @@ describe('Test users', function () {
182 182
183 describe('Remove video', function () { 183 describe('Remove video', function () {
184 it('Should not be able to remove the video with an incorrect token', async function () { 184 it('Should not be able to remove the video with an incorrect token', async function () {
185 await server.videosCommand.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 185 await server.videos.remove({ token: 'bad_token', id: videoId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
186 }) 186 })
187 187
188 it('Should not be able to remove the video with the token of another account') 188 it('Should not be able to remove the video with the token of another account')
189 189
190 it('Should be able to remove the video with the correct token', async function () { 190 it('Should be able to remove the video with the correct token', async function () {
191 await server.videosCommand.remove({ token, id: videoId }) 191 await server.videos.remove({ token, id: videoId })
192 }) 192 })
193 }) 193 })
194 194
195 describe('Logout', function () { 195 describe('Logout', function () {
196 it('Should logout (revoke token)', async function () { 196 it('Should logout (revoke token)', async function () {
197 await server.loginCommand.logout({ token: server.accessToken }) 197 await server.login.logout({ token: server.accessToken })
198 }) 198 })
199 199
200 it('Should not be able to get the user information', async function () { 200 it('Should not be able to get the user information', async function () {
201 await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 201 await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
202 }) 202 })
203 203
204 it('Should not be able to upload a video', async function () { 204 it('Should not be able to upload a video', async function () {
205 await server.videosCommand.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 205 await server.videos.upload({ attributes: { name: 'video' }, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
206 }) 206 })
207 207
208 it('Should not be able to rate a video', async function () { 208 it('Should not be able to rate a video', async function () {
@@ -222,64 +222,64 @@ describe('Test users', function () {
222 }) 222 })
223 223
224 it('Should be able to login again', async function () { 224 it('Should be able to login again', async function () {
225 const body = await server.loginCommand.login() 225 const body = await server.login.login()
226 server.accessToken = body.access_token 226 server.accessToken = body.access_token
227 server.refreshToken = body.refresh_token 227 server.refreshToken = body.refresh_token
228 }) 228 })
229 229
230 it('Should be able to get my user information again', async function () { 230 it('Should be able to get my user information again', async function () {
231 await server.usersCommand.getMyInfo() 231 await server.users.getMyInfo()
232 }) 232 })
233 233
234 it('Should have an expired access token', async function () { 234 it('Should have an expired access token', async function () {
235 this.timeout(15000) 235 this.timeout(15000)
236 236
237 await server.sqlCommand.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString()) 237 await server.sql.setTokenField(server.accessToken, 'accessTokenExpiresAt', new Date().toISOString())
238 await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString()) 238 await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', new Date().toISOString())
239 239
240 await killallServers([ server ]) 240 await killallServers([ server ])
241 await reRunServer(server) 241 await reRunServer(server)
242 242
243 await server.usersCommand.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 243 await server.users.getMyInfo({ expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
244 }) 244 })
245 245
246 it('Should not be able to refresh an access token with an expired refresh token', async function () { 246 it('Should not be able to refresh an access token with an expired refresh token', async function () {
247 await server.loginCommand.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 247 await server.login.refreshToken({ refreshToken: server.refreshToken, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
248 }) 248 })
249 249
250 it('Should refresh the token', async function () { 250 it('Should refresh the token', async function () {
251 this.timeout(15000) 251 this.timeout(15000)
252 252
253 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString() 253 const futureDate = new Date(new Date().getTime() + 1000 * 60).toISOString()
254 await server.sqlCommand.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate) 254 await server.sql.setTokenField(server.accessToken, 'refreshTokenExpiresAt', futureDate)
255 255
256 await killallServers([ server ]) 256 await killallServers([ server ])
257 await reRunServer(server) 257 await reRunServer(server)
258 258
259 const res = await server.loginCommand.refreshToken({ refreshToken: server.refreshToken }) 259 const res = await server.login.refreshToken({ refreshToken: server.refreshToken })
260 server.accessToken = res.body.access_token 260 server.accessToken = res.body.access_token
261 server.refreshToken = res.body.refresh_token 261 server.refreshToken = res.body.refresh_token
262 }) 262 })
263 263
264 it('Should be able to get my user information again', async function () { 264 it('Should be able to get my user information again', async function () {
265 await server.usersCommand.getMyInfo() 265 await server.users.getMyInfo()
266 }) 266 })
267 }) 267 })
268 268
269 describe('Creating a user', function () { 269 describe('Creating a user', function () {
270 270
271 it('Should be able to create a new user', async function () { 271 it('Should be able to create a new user', async function () {
272 await server.usersCommand.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST }) 272 await server.users.create({ ...user, videoQuota: 2 * 1024 * 1024, adminFlags: UserAdminFlag.BYPASS_VIDEO_AUTO_BLACKLIST })
273 }) 273 })
274 274
275 it('Should be able to login with this user', async function () { 275 it('Should be able to login with this user', async function () {
276 userToken = await server.loginCommand.getAccessToken(user) 276 userToken = await server.login.getAccessToken(user)
277 }) 277 })
278 278
279 it('Should be able to get user information', async function () { 279 it('Should be able to get user information', async function () {
280 const userMe = await server.usersCommand.getMyInfo({ token: userToken }) 280 const userMe = await server.users.getMyInfo({ token: userToken })
281 281
282 const userGet = await server.usersCommand.get({ userId: userMe.id, withStats: true }) 282 const userGet = await server.users.get({ userId: userMe.id, withStats: true })
283 283
284 for (const user of [ userMe, userGet ]) { 284 for (const user of [ userMe, userGet ]) {
285 expect(user.username).to.equal('user_1') 285 expect(user.username).to.equal('user_1')
@@ -319,20 +319,20 @@ describe('Test users', function () {
319 name: 'super user video', 319 name: 'super user video',
320 fixture: 'video_short.webm' 320 fixture: 'video_short.webm'
321 } 321 }
322 await server.videosCommand.upload({ token: userToken, attributes }) 322 await server.videos.upload({ token: userToken, attributes })
323 }) 323 })
324 324
325 it('Should have video quota updated', async function () { 325 it('Should have video quota updated', async function () {
326 const quota = await server.usersCommand.getMyQuotaUsed({ token: userToken }) 326 const quota = await server.users.getMyQuotaUsed({ token: userToken })
327 expect(quota.videoQuotaUsed).to.equal(218910) 327 expect(quota.videoQuotaUsed).to.equal(218910)
328 328
329 const { data } = await server.usersCommand.list() 329 const { data } = await server.users.list()
330 const tmpUser = data.find(u => u.username === user.username) 330 const tmpUser = data.find(u => u.username === user.username)
331 expect(tmpUser.videoQuotaUsed).to.equal(218910) 331 expect(tmpUser.videoQuotaUsed).to.equal(218910)
332 }) 332 })
333 333
334 it('Should be able to list my videos', async function () { 334 it('Should be able to list my videos', async function () {
335 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken }) 335 const { total, data } = await server.videos.listMyVideos({ token: userToken })
336 expect(total).to.equal(1) 336 expect(total).to.equal(1)
337 expect(data).to.have.lengthOf(1) 337 expect(data).to.have.lengthOf(1)
338 338
@@ -344,13 +344,13 @@ describe('Test users', function () {
344 344
345 it('Should be able to search in my videos', async function () { 345 it('Should be able to search in my videos', async function () {
346 { 346 {
347 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' }) 347 const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'user video' })
348 expect(total).to.equal(1) 348 expect(total).to.equal(1)
349 expect(data).to.have.lengthOf(1) 349 expect(data).to.have.lengthOf(1)
350 } 350 }
351 351
352 { 352 {
353 const { total, data } = await server.videosCommand.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' }) 353 const { total, data } = await server.videos.listMyVideos({ token: userToken, sort: '-createdAt', search: 'toto' })
354 expect(total).to.equal(0) 354 expect(total).to.equal(0)
355 expect(data).to.have.lengthOf(0) 355 expect(data).to.have.lengthOf(0)
356 } 356 }
@@ -360,11 +360,11 @@ describe('Test users', function () {
360 this.timeout(60000) 360 this.timeout(60000)
361 361
362 { 362 {
363 const config = await server.configCommand.getCustomConfig() 363 const config = await server.config.getCustomConfig()
364 config.transcoding.webtorrent.enabled = false 364 config.transcoding.webtorrent.enabled = false
365 config.transcoding.hls.enabled = true 365 config.transcoding.hls.enabled = true
366 config.transcoding.enabled = true 366 config.transcoding.enabled = true
367 await server.configCommand.updateCustomSubConfig({ newConfig: config }) 367 await server.config.updateCustomSubConfig({ newConfig: config })
368 } 368 }
369 369
370 { 370 {
@@ -372,13 +372,13 @@ describe('Test users', function () {
372 name: 'super user video 2', 372 name: 'super user video 2',
373 fixture: 'video_short.webm' 373 fixture: 'video_short.webm'
374 } 374 }
375 await server.videosCommand.upload({ token: userToken, attributes }) 375 await server.videos.upload({ token: userToken, attributes })
376 376
377 await waitJobs([ server ]) 377 await waitJobs([ server ])
378 } 378 }
379 379
380 { 380 {
381 const data = await server.usersCommand.getMyQuotaUsed({ token: userToken }) 381 const data = await server.users.getMyQuotaUsed({ token: userToken })
382 expect(data.videoQuotaUsed).to.be.greaterThan(220000) 382 expect(data.videoQuotaUsed).to.be.greaterThan(220000)
383 } 383 }
384 }) 384 })
@@ -387,7 +387,7 @@ describe('Test users', function () {
387 describe('Users listing', function () { 387 describe('Users listing', function () {
388 388
389 it('Should list all the users', async function () { 389 it('Should list all the users', async function () {
390 const { data, total } = await server.usersCommand.list() 390 const { data, total } = await server.users.list()
391 391
392 expect(total).to.equal(2) 392 expect(total).to.equal(2)
393 expect(data).to.be.an('array') 393 expect(data).to.be.an('array')
@@ -410,7 +410,7 @@ describe('Test users', function () {
410 }) 410 })
411 411
412 it('Should list only the first user by username asc', async function () { 412 it('Should list only the first user by username asc', async function () {
413 const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: 'username' }) 413 const { total, data } = await server.users.list({ start: 0, count: 1, sort: 'username' })
414 414
415 expect(total).to.equal(2) 415 expect(total).to.equal(2)
416 expect(data.length).to.equal(1) 416 expect(data.length).to.equal(1)
@@ -423,7 +423,7 @@ describe('Test users', function () {
423 }) 423 })
424 424
425 it('Should list only the first user by username desc', async function () { 425 it('Should list only the first user by username desc', async function () {
426 const { total, data } = await server.usersCommand.list({ start: 0, count: 1, sort: '-username' }) 426 const { total, data } = await server.users.list({ start: 0, count: 1, sort: '-username' })
427 427
428 expect(total).to.equal(2) 428 expect(total).to.equal(2)
429 expect(data.length).to.equal(1) 429 expect(data.length).to.equal(1)
@@ -435,7 +435,7 @@ describe('Test users', function () {
435 }) 435 })
436 436
437 it('Should list only the second user by createdAt desc', async function () { 437 it('Should list only the second user by createdAt desc', async function () {
438 const { data, total } = await server.usersCommand.list({ start: 0, count: 1, sort: '-createdAt' }) 438 const { data, total } = await server.users.list({ start: 0, count: 1, sort: '-createdAt' })
439 expect(total).to.equal(2) 439 expect(total).to.equal(2)
440 440
441 expect(data.length).to.equal(1) 441 expect(data.length).to.equal(1)
@@ -447,7 +447,7 @@ describe('Test users', function () {
447 }) 447 })
448 448
449 it('Should list all the users by createdAt asc', async function () { 449 it('Should list all the users by createdAt asc', async function () {
450 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt' }) 450 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt' })
451 451
452 expect(total).to.equal(2) 452 expect(total).to.equal(2)
453 expect(data.length).to.equal(2) 453 expect(data.length).to.equal(2)
@@ -462,7 +462,7 @@ describe('Test users', function () {
462 }) 462 })
463 463
464 it('Should search user by username', async function () { 464 it('Should search user by username', async function () {
465 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' }) 465 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'oot' })
466 expect(total).to.equal(1) 466 expect(total).to.equal(1)
467 expect(data.length).to.equal(1) 467 expect(data.length).to.equal(1)
468 expect(data[0].username).to.equal('root') 468 expect(data[0].username).to.equal('root')
@@ -470,7 +470,7 @@ describe('Test users', function () {
470 470
471 it('Should search user by email', async function () { 471 it('Should search user by email', async function () {
472 { 472 {
473 const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' }) 473 const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'r_1@exam' })
474 expect(total).to.equal(1) 474 expect(total).to.equal(1)
475 expect(data.length).to.equal(1) 475 expect(data.length).to.equal(1)
476 expect(data[0].username).to.equal('user_1') 476 expect(data[0].username).to.equal('user_1')
@@ -478,7 +478,7 @@ describe('Test users', function () {
478 } 478 }
479 479
480 { 480 {
481 const { total, data } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' }) 481 const { total, data } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', search: 'example' })
482 expect(total).to.equal(2) 482 expect(total).to.equal(2)
483 expect(data.length).to.equal(2) 483 expect(data.length).to.equal(2)
484 expect(data[0].username).to.equal('root') 484 expect(data[0].username).to.equal('root')
@@ -490,23 +490,23 @@ describe('Test users', function () {
490 describe('Update my account', function () { 490 describe('Update my account', function () {
491 491
492 it('Should update my password', async function () { 492 it('Should update my password', async function () {
493 await server.usersCommand.updateMe({ 493 await server.users.updateMe({
494 token: userToken, 494 token: userToken,
495 currentPassword: 'super password', 495 currentPassword: 'super password',
496 password: 'new password' 496 password: 'new password'
497 }) 497 })
498 user.password = 'new password' 498 user.password = 'new password'
499 499
500 await server.loginCommand.login({ user }) 500 await server.login.login({ user })
501 }) 501 })
502 502
503 it('Should be able to change the NSFW display attribute', async function () { 503 it('Should be able to change the NSFW display attribute', async function () {
504 await server.usersCommand.updateMe({ 504 await server.users.updateMe({
505 token: userToken, 505 token: userToken,
506 nsfwPolicy: 'do_not_list' 506 nsfwPolicy: 'do_not_list'
507 }) 507 })
508 508
509 const user = await server.usersCommand.getMyInfo({ token: userToken }) 509 const user = await server.users.getMyInfo({ token: userToken })
510 expect(user.username).to.equal('user_1') 510 expect(user.username).to.equal('user_1')
511 expect(user.email).to.equal('user_1@example.com') 511 expect(user.email).to.equal('user_1@example.com')
512 expect(user.nsfwPolicy).to.equal('do_not_list') 512 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -517,33 +517,33 @@ describe('Test users', function () {
517 }) 517 })
518 518
519 it('Should be able to change the autoPlayVideo attribute', async function () { 519 it('Should be able to change the autoPlayVideo attribute', async function () {
520 await server.usersCommand.updateMe({ 520 await server.users.updateMe({
521 token: userToken, 521 token: userToken,
522 autoPlayVideo: false 522 autoPlayVideo: false
523 }) 523 })
524 524
525 const user = await server.usersCommand.getMyInfo({ token: userToken }) 525 const user = await server.users.getMyInfo({ token: userToken })
526 expect(user.autoPlayVideo).to.be.false 526 expect(user.autoPlayVideo).to.be.false
527 }) 527 })
528 528
529 it('Should be able to change the autoPlayNextVideo attribute', async function () { 529 it('Should be able to change the autoPlayNextVideo attribute', async function () {
530 await server.usersCommand.updateMe({ 530 await server.users.updateMe({
531 token: userToken, 531 token: userToken,
532 autoPlayNextVideo: true 532 autoPlayNextVideo: true
533 }) 533 })
534 534
535 const user = await server.usersCommand.getMyInfo({ token: userToken }) 535 const user = await server.users.getMyInfo({ token: userToken })
536 expect(user.autoPlayNextVideo).to.be.true 536 expect(user.autoPlayNextVideo).to.be.true
537 }) 537 })
538 538
539 it('Should be able to change the email attribute', async function () { 539 it('Should be able to change the email attribute', async function () {
540 await server.usersCommand.updateMe({ 540 await server.users.updateMe({
541 token: userToken, 541 token: userToken,
542 currentPassword: 'new password', 542 currentPassword: 'new password',
543 email: 'updated@example.com' 543 email: 'updated@example.com'
544 }) 544 })
545 545
546 const user = await server.usersCommand.getMyInfo({ token: userToken }) 546 const user = await server.users.getMyInfo({ token: userToken })
547 expect(user.username).to.equal('user_1') 547 expect(user.username).to.equal('user_1')
548 expect(user.email).to.equal('updated@example.com') 548 expect(user.email).to.equal('updated@example.com')
549 expect(user.nsfwPolicy).to.equal('do_not_list') 549 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -556,9 +556,9 @@ describe('Test users', function () {
556 it('Should be able to update my avatar with a gif', async function () { 556 it('Should be able to update my avatar with a gif', async function () {
557 const fixture = 'avatar.gif' 557 const fixture = 'avatar.gif'
558 558
559 await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) 559 await server.users.updateMyAvatar({ token: userToken, fixture })
560 560
561 const user = await server.usersCommand.getMyInfo({ token: userToken }) 561 const user = await server.users.getMyInfo({ token: userToken })
562 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif') 562 await testImage(server.url, 'avatar-resized', user.account.avatar.path, '.gif')
563 }) 563 })
564 564
@@ -566,17 +566,17 @@ describe('Test users', function () {
566 for (const extension of [ '.png', '.gif' ]) { 566 for (const extension of [ '.png', '.gif' ]) {
567 const fixture = 'avatar' + extension 567 const fixture = 'avatar' + extension
568 568
569 await server.usersCommand.updateMyAvatar({ token: userToken, fixture }) 569 await server.users.updateMyAvatar({ token: userToken, fixture })
570 570
571 const user = await server.usersCommand.getMyInfo({ token: userToken }) 571 const user = await server.users.getMyInfo({ token: userToken })
572 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension) 572 await testImage(server.url, 'avatar-resized', user.account.avatar.path, extension)
573 } 573 }
574 }) 574 })
575 575
576 it('Should be able to update my display name', async function () { 576 it('Should be able to update my display name', async function () {
577 await server.usersCommand.updateMe({ token: userToken, displayName: 'new display name' }) 577 await server.users.updateMe({ token: userToken, displayName: 'new display name' })
578 578
579 const user = await server.usersCommand.getMyInfo({ token: userToken }) 579 const user = await server.users.getMyInfo({ token: userToken })
580 expect(user.username).to.equal('user_1') 580 expect(user.username).to.equal('user_1')
581 expect(user.email).to.equal('updated@example.com') 581 expect(user.email).to.equal('updated@example.com')
582 expect(user.nsfwPolicy).to.equal('do_not_list') 582 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -587,9 +587,9 @@ describe('Test users', function () {
587 }) 587 })
588 588
589 it('Should be able to update my description', async function () { 589 it('Should be able to update my description', async function () {
590 await server.usersCommand.updateMe({ token: userToken, description: 'my super description updated' }) 590 await server.users.updateMe({ token: userToken, description: 'my super description updated' })
591 591
592 const user = await server.usersCommand.getMyInfo({ token: userToken }) 592 const user = await server.users.getMyInfo({ token: userToken })
593 expect(user.username).to.equal('user_1') 593 expect(user.username).to.equal('user_1')
594 expect(user.email).to.equal('updated@example.com') 594 expect(user.email).to.equal('updated@example.com')
595 expect(user.nsfwPolicy).to.equal('do_not_list') 595 expect(user.nsfwPolicy).to.equal('do_not_list')
@@ -603,21 +603,21 @@ describe('Test users', function () {
603 603
604 it('Should be able to update my theme', async function () { 604 it('Should be able to update my theme', async function () {
605 for (const theme of [ 'background-red', 'default', 'instance-default' ]) { 605 for (const theme of [ 'background-red', 'default', 'instance-default' ]) {
606 await server.usersCommand.updateMe({ token: userToken, theme }) 606 await server.users.updateMe({ token: userToken, theme })
607 607
608 const user = await server.usersCommand.getMyInfo({ token: userToken }) 608 const user = await server.users.getMyInfo({ token: userToken })
609 expect(user.theme).to.equal(theme) 609 expect(user.theme).to.equal(theme)
610 } 610 }
611 }) 611 })
612 612
613 it('Should be able to update my modal preferences', async function () { 613 it('Should be able to update my modal preferences', async function () {
614 await server.usersCommand.updateMe({ 614 await server.users.updateMe({
615 token: userToken, 615 token: userToken,
616 noInstanceConfigWarningModal: true, 616 noInstanceConfigWarningModal: true,
617 noWelcomeModal: true 617 noWelcomeModal: true
618 }) 618 })
619 619
620 const user = await server.usersCommand.getMyInfo({ token: userToken }) 620 const user = await server.users.getMyInfo({ token: userToken })
621 expect(user.noWelcomeModal).to.be.true 621 expect(user.noWelcomeModal).to.be.true
622 expect(user.noInstanceConfigWarningModal).to.be.true 622 expect(user.noInstanceConfigWarningModal).to.be.true
623 }) 623 })
@@ -625,7 +625,7 @@ describe('Test users', function () {
625 625
626 describe('Updating another user', function () { 626 describe('Updating another user', function () {
627 it('Should be able to update another user', async function () { 627 it('Should be able to update another user', async function () {
628 await server.usersCommand.update({ 628 await server.users.update({
629 userId, 629 userId,
630 token, 630 token,
631 email: 'updated2@example.com', 631 email: 'updated2@example.com',
@@ -636,7 +636,7 @@ describe('Test users', function () {
636 pluginAuth: 'toto' 636 pluginAuth: 'toto'
637 }) 637 })
638 638
639 const user = await server.usersCommand.get({ token, userId }) 639 const user = await server.users.get({ token, userId })
640 640
641 expect(user.username).to.equal('user_1') 641 expect(user.username).to.equal('user_1')
642 expect(user.email).to.equal('updated2@example.com') 642 expect(user.email).to.equal('updated2@example.com')
@@ -650,47 +650,47 @@ describe('Test users', function () {
650 }) 650 })
651 651
652 it('Should reset the auth plugin', async function () { 652 it('Should reset the auth plugin', async function () {
653 await server.usersCommand.update({ userId, token, pluginAuth: null }) 653 await server.users.update({ userId, token, pluginAuth: null })
654 654
655 const user = await server.usersCommand.get({ token, userId }) 655 const user = await server.users.get({ token, userId })
656 expect(user.pluginAuth).to.be.null 656 expect(user.pluginAuth).to.be.null
657 }) 657 })
658 658
659 it('Should have removed the user token', async function () { 659 it('Should have removed the user token', async function () {
660 await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 660 await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
661 661
662 userToken = await server.loginCommand.getAccessToken(user) 662 userToken = await server.login.getAccessToken(user)
663 }) 663 })
664 664
665 it('Should be able to update another user password', async function () { 665 it('Should be able to update another user password', async function () {
666 await server.usersCommand.update({ userId, token, password: 'password updated' }) 666 await server.users.update({ userId, token, password: 'password updated' })
667 667
668 await server.usersCommand.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 668 await server.users.getMyQuotaUsed({ token: userToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
669 669
670 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 670 await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
671 671
672 user.password = 'password updated' 672 user.password = 'password updated'
673 userToken = await server.loginCommand.getAccessToken(user) 673 userToken = await server.login.getAccessToken(user)
674 }) 674 })
675 }) 675 })
676 676
677 describe('Video blacklists', function () { 677 describe('Video blacklists', function () {
678 it('Should be able to list video blacklist by a moderator', async function () { 678 it('Should be able to list video blacklist by a moderator', async function () {
679 await server.blacklistCommand.list({ token: userToken }) 679 await server.blacklist.list({ token: userToken })
680 }) 680 })
681 }) 681 })
682 682
683 describe('Remove a user', function () { 683 describe('Remove a user', function () {
684 it('Should be able to remove this user', async function () { 684 it('Should be able to remove this user', async function () {
685 await server.usersCommand.remove({ userId, token }) 685 await server.users.remove({ userId, token })
686 }) 686 })
687 687
688 it('Should not be able to login with this user', async function () { 688 it('Should not be able to login with this user', async function () {
689 await server.loginCommand.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 689 await server.login.login({ user, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
690 }) 690 })
691 691
692 it('Should not have videos of this user', async function () { 692 it('Should not have videos of this user', async function () {
693 const { data, total } = await server.videosCommand.list() 693 const { data, total } = await server.videos.list()
694 expect(total).to.equal(1) 694 expect(total).to.equal(1)
695 695
696 const video = data[0] 696 const video = data[0]
@@ -705,7 +705,7 @@ describe('Test users', function () {
705 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' } 705 const user = { displayName: 'super user 15', username: 'user_15', password: 'my super password' }
706 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' } 706 const channel = { name: 'my_user_15_channel', displayName: 'my channel rocks' }
707 707
708 await server.usersCommand.register({ ...user, channel }) 708 await server.users.register({ ...user, channel })
709 }) 709 })
710 710
711 it('Should be able to login with this registered user', async function () { 711 it('Should be able to login with this registered user', async function () {
@@ -714,35 +714,35 @@ describe('Test users', function () {
714 password: 'my super password' 714 password: 'my super password'
715 } 715 }
716 716
717 user15AccessToken = await server.loginCommand.getAccessToken(user15) 717 user15AccessToken = await server.login.getAccessToken(user15)
718 }) 718 })
719 719
720 it('Should have the correct display name', async function () { 720 it('Should have the correct display name', async function () {
721 const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) 721 const user = await server.users.getMyInfo({ token: user15AccessToken })
722 expect(user.account.displayName).to.equal('super user 15') 722 expect(user.account.displayName).to.equal('super user 15')
723 }) 723 })
724 724
725 it('Should have the correct video quota', async function () { 725 it('Should have the correct video quota', async function () {
726 const user = await server.usersCommand.getMyInfo({ token: user15AccessToken }) 726 const user = await server.users.getMyInfo({ token: user15AccessToken })
727 expect(user.videoQuota).to.equal(5 * 1024 * 1024) 727 expect(user.videoQuota).to.equal(5 * 1024 * 1024)
728 }) 728 })
729 729
730 it('Should have created the channel', async function () { 730 it('Should have created the channel', async function () {
731 const { displayName } = await server.channelsCommand.get({ channelName: 'my_user_15_channel' }) 731 const { displayName } = await server.channels.get({ channelName: 'my_user_15_channel' })
732 732
733 expect(displayName).to.equal('my channel rocks') 733 expect(displayName).to.equal('my channel rocks')
734 }) 734 })
735 735
736 it('Should remove me', async function () { 736 it('Should remove me', async function () {
737 { 737 {
738 const { data } = await server.usersCommand.list() 738 const { data } = await server.users.list()
739 expect(data.find(u => u.username === 'user_15')).to.not.be.undefined 739 expect(data.find(u => u.username === 'user_15')).to.not.be.undefined
740 } 740 }
741 741
742 await server.usersCommand.deleteMe({ token: user15AccessToken }) 742 await server.users.deleteMe({ token: user15AccessToken })
743 743
744 { 744 {
745 const { data } = await server.usersCommand.list() 745 const { data } = await server.users.list()
746 expect(data.find(u => u.username === 'user_15')).to.be.undefined 746 expect(data.find(u => u.username === 'user_15')).to.be.undefined
747 } 747 }
748 }) 748 })
@@ -757,21 +757,21 @@ describe('Test users', function () {
757 } 757 }
758 758
759 it('Should block a user', async function () { 759 it('Should block a user', async function () {
760 const user = await server.usersCommand.create({ ...user16 }) 760 const user = await server.users.create({ ...user16 })
761 user16Id = user.id 761 user16Id = user.id
762 762
763 user16AccessToken = await server.loginCommand.getAccessToken(user16) 763 user16AccessToken = await server.login.getAccessToken(user16)
764 764
765 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) 765 await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
766 await server.usersCommand.banUser({ userId: user16Id }) 766 await server.users.banUser({ userId: user16Id })
767 767
768 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 768 await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
769 await server.loginCommand.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }) 769 await server.login.login({ user: user16, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
770 }) 770 })
771 771
772 it('Should search user by banned status', async function () { 772 it('Should search user by banned status', async function () {
773 { 773 {
774 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: true }) 774 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: true })
775 expect(total).to.equal(1) 775 expect(total).to.equal(1)
776 expect(data.length).to.equal(1) 776 expect(data.length).to.equal(1)
777 777
@@ -779,7 +779,7 @@ describe('Test users', function () {
779 } 779 }
780 780
781 { 781 {
782 const { data, total } = await server.usersCommand.list({ start: 0, count: 2, sort: 'createdAt', blocked: false }) 782 const { data, total } = await server.users.list({ start: 0, count: 2, sort: 'createdAt', blocked: false })
783 expect(total).to.equal(1) 783 expect(total).to.equal(1)
784 expect(data.length).to.equal(1) 784 expect(data.length).to.equal(1)
785 785
@@ -788,9 +788,9 @@ describe('Test users', function () {
788 }) 788 })
789 789
790 it('Should unblock a user', async function () { 790 it('Should unblock a user', async function () {
791 await server.usersCommand.unbanUser({ userId: user16Id }) 791 await server.users.unbanUser({ userId: user16Id })
792 user16AccessToken = await server.loginCommand.getAccessToken(user16) 792 user16AccessToken = await server.login.getAccessToken(user16)
793 await server.usersCommand.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 }) 793 await server.users.getMyInfo({ token: user16AccessToken, expectedStatus: HttpStatusCode.OK_200 })
794 }) 794 })
795 }) 795 })
796 796
@@ -803,12 +803,12 @@ describe('Test users', function () {
803 username: 'user_17', 803 username: 'user_17',
804 password: 'my super password' 804 password: 'my super password'
805 } 805 }
806 const created = await server.usersCommand.create({ ...user17 }) 806 const created = await server.users.create({ ...user17 })
807 807
808 user17Id = created.id 808 user17Id = created.id
809 user17AccessToken = await server.loginCommand.getAccessToken(user17) 809 user17AccessToken = await server.login.getAccessToken(user17)
810 810
811 const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) 811 const user = await server.users.get({ userId: user17Id, withStats: true })
812 expect(user.videosCount).to.equal(0) 812 expect(user.videosCount).to.equal(0)
813 expect(user.videoCommentsCount).to.equal(0) 813 expect(user.videoCommentsCount).to.equal(0)
814 expect(user.abusesCount).to.equal(0) 814 expect(user.abusesCount).to.equal(0)
@@ -818,37 +818,37 @@ describe('Test users', function () {
818 818
819 it('Should report correct videos count', async function () { 819 it('Should report correct videos count', async function () {
820 const attributes = { name: 'video to test user stats' } 820 const attributes = { name: 'video to test user stats' }
821 await server.videosCommand.upload({ token: user17AccessToken, attributes }) 821 await server.videos.upload({ token: user17AccessToken, attributes })
822 822
823 const { data } = await server.videosCommand.list() 823 const { data } = await server.videos.list()
824 videoId = data.find(video => video.name === attributes.name).id 824 videoId = data.find(video => video.name === attributes.name).id
825 825
826 const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) 826 const user = await server.users.get({ userId: user17Id, withStats: true })
827 expect(user.videosCount).to.equal(1) 827 expect(user.videosCount).to.equal(1)
828 }) 828 })
829 829
830 it('Should report correct video comments for user', async function () { 830 it('Should report correct video comments for user', async function () {
831 const text = 'super comment' 831 const text = 'super comment'
832 await server.commentsCommand.createThread({ token: user17AccessToken, videoId, text }) 832 await server.comments.createThread({ token: user17AccessToken, videoId, text })
833 833
834 const user = await server.usersCommand.get({ userId: user17Id, withStats: true }) 834 const user = await server.users.get({ userId: user17Id, withStats: true })
835 expect(user.videoCommentsCount).to.equal(1) 835 expect(user.videoCommentsCount).to.equal(1)
836 }) 836 })
837 837
838 it('Should report correct abuses counts', async function () { 838 it('Should report correct abuses counts', async function () {
839 const reason = 'my super bad reason' 839 const reason = 'my super bad reason'
840 await server.abusesCommand.report({ token: user17AccessToken, videoId, reason }) 840 await server.abuses.report({ token: user17AccessToken, videoId, reason })
841 841
842 const body1 = await server.abusesCommand.getAdminList() 842 const body1 = await server.abuses.getAdminList()
843 const abuseId = body1.data[0].id 843 const abuseId = body1.data[0].id
844 844
845 const user2 = await server.usersCommand.get({ userId: user17Id, withStats: true }) 845 const user2 = await server.users.get({ userId: user17Id, withStats: true })
846 expect(user2.abusesCount).to.equal(1) // number of incriminations 846 expect(user2.abusesCount).to.equal(1) // number of incriminations
847 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created 847 expect(user2.abusesCreatedCount).to.equal(1) // number of reports created
848 848
849 await server.abusesCommand.update({ abuseId, body: { state: AbuseState.ACCEPTED } }) 849 await server.abuses.update({ abuseId, body: { state: AbuseState.ACCEPTED } })
850 850
851 const user3 = await server.usersCommand.get({ userId: user17Id, withStats: true }) 851 const user3 = await server.users.get({ userId: user17Id, withStats: true })
852 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted 852 expect(user3.abusesAcceptedCount).to.equal(1) // number of reports created accepted
853 }) 853 })
854 }) 854 })