aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/check-params
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/check-params')
-rw-r--r--server/tests/api/check-params/abuses.ts205
-rw-r--r--server/tests/api/check-params/accounts.ts19
-rw-r--r--server/tests/api/check-params/blocklist.ts107
-rw-r--r--server/tests/api/check-params/bulk.ts30
-rw-r--r--server/tests/api/check-params/config.ts65
-rw-r--r--server/tests/api/check-params/contact-form.ts84
-rw-r--r--server/tests/api/check-params/custom-pages.ts31
-rw-r--r--server/tests/api/check-params/debug.ts27
-rw-r--r--server/tests/api/check-params/follows.ts112
-rw-r--r--server/tests/api/check-params/jobs.ts33
-rw-r--r--server/tests/api/check-params/live.ts225
-rw-r--r--server/tests/api/check-params/logs.ts35
-rw-r--r--server/tests/api/check-params/plugins.ts95
-rw-r--r--server/tests/api/check-params/redundancy.ts60
-rw-r--r--server/tests/api/check-params/search.ts152
-rw-r--r--server/tests/api/check-params/services.ts49
-rw-r--r--server/tests/api/check-params/upload-quota.ts97
-rw-r--r--server/tests/api/check-params/user-notifications.ts57
-rw-r--r--server/tests/api/check-params/user-subscriptions.ts80
-rw-r--r--server/tests/api/check-params/users.ts425
-rw-r--r--server/tests/api/check-params/video-blacklist.ts132
-rw-r--r--server/tests/api/check-params/video-captions.ts60
-rw-r--r--server/tests/api/check-params/video-channels.ts88
-rw-r--r--server/tests/api/check-params/video-comments.ts107
-rw-r--r--server/tests/api/check-params/video-imports.ts124
-rw-r--r--server/tests/api/check-params/video-playlists.ts394
-rw-r--r--server/tests/api/check-params/videos-filter.ts44
-rw-r--r--server/tests/api/check-params/videos-history.ts43
-rw-r--r--server/tests/api/check-params/videos-overviews.ts13
-rw-r--r--server/tests/api/check-params/videos.ts243
30 files changed, 1512 insertions, 1724 deletions
diff --git a/server/tests/api/check-params/abuses.ts b/server/tests/api/check-params/abuses.ts
index 2054776cc..72f2cbd8f 100644
--- a/server/tests/api/check-params/abuses.ts
+++ b/server/tests/api/check-params/abuses.ts
@@ -1,66 +1,49 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { AbuseCreate, AbuseState } from '@shared/models'
5import { 4import {
6 addAbuseMessage, 5 AbusesCommand,
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
7 cleanupTests, 9 cleanupTests,
8 createUser, 10 createSingleServer,
9 deleteAbuse,
10 deleteAbuseMessage,
11 doubleFollow, 11 doubleFollow,
12 flushAndRunServer,
13 generateUserAccessToken,
14 getAdminAbusesList,
15 getVideoIdFromUUID,
16 listAbuseMessages,
17 makeGetRequest, 12 makeGetRequest,
18 makePostBodyRequest, 13 makePostBodyRequest,
19 reportAbuse, 14 PeerTubeServer,
20 ServerInfo,
21 setAccessTokensToServers, 15 setAccessTokensToServers,
22 updateAbuse,
23 uploadVideo,
24 userLogin,
25 waitJobs 16 waitJobs
26} from '../../../../shared/extra-utils' 17} from '@shared/extra-utils'
27import { 18import { AbuseCreate, AbuseState, HttpStatusCode } from '@shared/models'
28 checkBadCountPagination,
29 checkBadSortPagination,
30 checkBadStartPagination
31} from '../../../../shared/extra-utils/requests/check-api-params'
32import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
33 19
34describe('Test abuses API validators', function () { 20describe('Test abuses API validators', function () {
35 const basePath = '/api/v1/abuses/' 21 const basePath = '/api/v1/abuses/'
36 22
37 let server: ServerInfo 23 let server: PeerTubeServer
38 24
39 let userAccessToken = '' 25 let userToken = ''
40 let userAccessToken2 = '' 26 let userToken2 = ''
41 let abuseId: number 27 let abuseId: number
42 let messageId: number 28 let messageId: number
43 29
30 let command: AbusesCommand
31
44 // --------------------------------------------------------------- 32 // ---------------------------------------------------------------
45 33
46 before(async function () { 34 before(async function () {
47 this.timeout(30000) 35 this.timeout(30000)
48 36
49 server = await flushAndRunServer(1) 37 server = await createSingleServer(1)
50 38
51 await setAccessTokensToServers([ server ]) 39 await setAccessTokensToServers([ server ])
52 40
53 const username = 'user1' 41 userToken = await server.users.generateUserAndToken('user_1')
54 const password = 'my super password' 42 userToken2 = await server.users.generateUserAndToken('user_2')
55 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
56 userAccessToken = await userLogin(server, { username, password })
57 43
58 { 44 server.store.video = await server.videos.upload()
59 userAccessToken2 = await generateUserAccessToken(server, 'user_2')
60 }
61 45
62 const res = await uploadVideo(server.url, server.accessToken, {}) 46 command = server.abuses
63 server.video = res.body.video
64 }) 47 })
65 48
66 describe('When listing abuses for admins', function () { 49 describe('When listing abuses for admins', function () {
@@ -82,7 +65,7 @@ describe('Test abuses API validators', function () {
82 await makeGetRequest({ 65 await makeGetRequest({
83 url: server.url, 66 url: server.url,
84 path, 67 path,
85 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 68 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
86 }) 69 })
87 }) 70 })
88 71
@@ -90,8 +73,8 @@ describe('Test abuses API validators', function () {
90 await makeGetRequest({ 73 await makeGetRequest({
91 url: server.url, 74 url: server.url,
92 path, 75 path,
93 token: userAccessToken, 76 token: userToken,
94 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 77 expectedStatus: HttpStatusCode.FORBIDDEN_403
95 }) 78 })
96 }) 79 })
97 80
@@ -126,7 +109,7 @@ describe('Test abuses API validators', function () {
126 videoIs: 'deleted' 109 videoIs: 'deleted'
127 } 110 }
128 111
129 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) 112 await makeGetRequest({ url: server.url, path, token: server.accessToken, query, expectedStatus: HttpStatusCode.OK_200 })
130 }) 113 })
131 }) 114 })
132 115
@@ -134,32 +117,32 @@ describe('Test abuses API validators', function () {
134 const path = '/api/v1/users/me/abuses' 117 const path = '/api/v1/users/me/abuses'
135 118
136 it('Should fail with a bad start pagination', async function () { 119 it('Should fail with a bad start pagination', async function () {
137 await checkBadStartPagination(server.url, path, userAccessToken) 120 await checkBadStartPagination(server.url, path, userToken)
138 }) 121 })
139 122
140 it('Should fail with a bad count pagination', async function () { 123 it('Should fail with a bad count pagination', async function () {
141 await checkBadCountPagination(server.url, path, userAccessToken) 124 await checkBadCountPagination(server.url, path, userToken)
142 }) 125 })
143 126
144 it('Should fail with an incorrect sort', async function () { 127 it('Should fail with an incorrect sort', async function () {
145 await checkBadSortPagination(server.url, path, userAccessToken) 128 await checkBadSortPagination(server.url, path, userToken)
146 }) 129 })
147 130
148 it('Should fail with a non authenticated user', async function () { 131 it('Should fail with a non authenticated user', async function () {
149 await makeGetRequest({ 132 await makeGetRequest({
150 url: server.url, 133 url: server.url,
151 path, 134 path,
152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 135 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
153 }) 136 })
154 }) 137 })
155 138
156 it('Should fail with a bad id filter', async function () { 139 it('Should fail with a bad id filter', async function () {
157 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { id: 'toto' } }) 140 await makeGetRequest({ url: server.url, path, token: userToken, query: { id: 'toto' } })
158 }) 141 })
159 142
160 it('Should fail with a bad state filter', async function () { 143 it('Should fail with a bad state filter', async function () {
161 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 'toto' } }) 144 await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 'toto' } })
162 await makeGetRequest({ url: server.url, path, token: userAccessToken, query: { state: 0 } }) 145 await makeGetRequest({ url: server.url, path, token: userToken, query: { state: 0 } })
163 }) 146 })
164 147
165 it('Should succeed with the correct params', async function () { 148 it('Should succeed with the correct params', async function () {
@@ -168,7 +151,7 @@ describe('Test abuses API validators', function () {
168 state: 2 151 state: 2
169 } 152 }
170 153
171 await makeGetRequest({ url: server.url, path, token: userAccessToken, query, statusCodeExpected: HttpStatusCode.OK_200 }) 154 await makeGetRequest({ url: server.url, path, token: userToken, query, expectedStatus: HttpStatusCode.OK_200 })
172 }) 155 })
173 }) 156 })
174 157
@@ -177,12 +160,12 @@ describe('Test abuses API validators', function () {
177 160
178 it('Should fail with nothing', async function () { 161 it('Should fail with nothing', async function () {
179 const fields = {} 162 const fields = {}
180 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 163 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
181 }) 164 })
182 165
183 it('Should fail with a wrong video', async function () { 166 it('Should fail with a wrong video', async function () {
184 const fields = { video: { id: 'blabla' }, reason: 'my super reason' } 167 const fields = { video: { id: 'blabla' }, reason: 'my super reason' }
185 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) 168 await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
186 }) 169 })
187 170
188 it('Should fail with an unknown video', async function () { 171 it('Should fail with an unknown video', async function () {
@@ -190,15 +173,15 @@ describe('Test abuses API validators', function () {
190 await makePostBodyRequest({ 173 await makePostBodyRequest({
191 url: server.url, 174 url: server.url,
192 path, 175 path,
193 token: userAccessToken, 176 token: userToken,
194 fields, 177 fields,
195 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 178 expectedStatus: HttpStatusCode.NOT_FOUND_404
196 }) 179 })
197 }) 180 })
198 181
199 it('Should fail with a wrong comment', async function () { 182 it('Should fail with a wrong comment', async function () {
200 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' } 183 const fields = { comment: { id: 'blabla' }, reason: 'my super reason' }
201 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) 184 await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
202 }) 185 })
203 186
204 it('Should fail with an unknown comment', async function () { 187 it('Should fail with an unknown comment', async function () {
@@ -206,15 +189,15 @@ describe('Test abuses API validators', function () {
206 await makePostBodyRequest({ 189 await makePostBodyRequest({
207 url: server.url, 190 url: server.url,
208 path, 191 path,
209 token: userAccessToken, 192 token: userToken,
210 fields, 193 fields,
211 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 194 expectedStatus: HttpStatusCode.NOT_FOUND_404
212 }) 195 })
213 }) 196 })
214 197
215 it('Should fail with a wrong account', async function () { 198 it('Should fail with a wrong account', async function () {
216 const fields = { account: { id: 'blabla' }, reason: 'my super reason' } 199 const fields = { account: { id: 'blabla' }, reason: 'my super reason' }
217 await makePostBodyRequest({ url: server.url, path: path, token: userAccessToken, fields }) 200 await makePostBodyRequest({ url: server.url, path: path, token: userToken, fields })
218 }) 201 })
219 202
220 it('Should fail with an unknown account', async function () { 203 it('Should fail with an unknown account', async function () {
@@ -222,9 +205,9 @@ describe('Test abuses API validators', function () {
222 await makePostBodyRequest({ 205 await makePostBodyRequest({
223 url: server.url, 206 url: server.url,
224 path, 207 path,
225 token: userAccessToken, 208 token: userToken,
226 fields, 209 fields,
227 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 210 expectedStatus: HttpStatusCode.NOT_FOUND_404
228 }) 211 })
229 }) 212 })
230 213
@@ -233,65 +216,65 @@ describe('Test abuses API validators', function () {
233 await makePostBodyRequest({ 216 await makePostBodyRequest({
234 url: server.url, 217 url: server.url,
235 path, 218 path,
236 token: userAccessToken, 219 token: userToken,
237 fields, 220 fields,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 221 expectedStatus: HttpStatusCode.BAD_REQUEST_400
239 }) 222 })
240 }) 223 })
241 224
242 it('Should fail with a non authenticated user', async function () { 225 it('Should fail with a non authenticated user', async function () {
243 const fields = { video: { id: server.video.id }, reason: 'my super reason' } 226 const fields = { video: { id: server.store.video.id }, reason: 'my super reason' }
244 227
245 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 228 await makePostBodyRequest({ url: server.url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
246 }) 229 })
247 230
248 it('Should fail with a reason too short', async function () { 231 it('Should fail with a reason too short', async function () {
249 const fields = { video: { id: server.video.id }, reason: 'h' } 232 const fields = { video: { id: server.store.video.id }, reason: 'h' }
250 233
251 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 234 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
252 }) 235 })
253 236
254 it('Should fail with a too big reason', async function () { 237 it('Should fail with a too big reason', async function () {
255 const fields = { video: { id: server.video.id }, reason: 'super'.repeat(605) } 238 const fields = { video: { id: server.store.video.id }, reason: 'super'.repeat(605) }
256 239
257 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 240 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
258 }) 241 })
259 242
260 it('Should succeed with the correct parameters (basic)', async function () { 243 it('Should succeed with the correct parameters (basic)', async function () {
261 const fields: AbuseCreate = { video: { id: server.video.shortUUID }, reason: 'my super reason' } 244 const fields: AbuseCreate = { video: { id: server.store.video.shortUUID }, reason: 'my super reason' }
262 245
263 const res = await makePostBodyRequest({ 246 const res = await makePostBodyRequest({
264 url: server.url, 247 url: server.url,
265 path, 248 path,
266 token: userAccessToken, 249 token: userToken,
267 fields, 250 fields,
268 statusCodeExpected: HttpStatusCode.OK_200 251 expectedStatus: HttpStatusCode.OK_200
269 }) 252 })
270 abuseId = res.body.abuse.id 253 abuseId = res.body.abuse.id
271 }) 254 })
272 255
273 it('Should fail with a wrong predefined reason', async function () { 256 it('Should fail with a wrong predefined reason', async function () {
274 const fields = { video: { id: server.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] } 257 const fields = { video: { id: server.store.video.id }, reason: 'my super reason', predefinedReasons: [ 'wrongPredefinedReason' ] }
275 258
276 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 259 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
277 }) 260 })
278 261
279 it('Should fail with negative timestamps', async function () { 262 it('Should fail with negative timestamps', async function () {
280 const fields = { video: { id: server.video.id, startAt: -1 }, reason: 'my super reason' } 263 const fields = { video: { id: server.store.video.id, startAt: -1 }, reason: 'my super reason' }
281 264
282 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 265 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
283 }) 266 })
284 267
285 it('Should fail mith misordered startAt/endAt', async function () { 268 it('Should fail mith misordered startAt/endAt', async function () {
286 const fields = { video: { id: server.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' } 269 const fields = { video: { id: server.store.video.id, startAt: 5, endAt: 1 }, reason: 'my super reason' }
287 270
288 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: userToken, fields })
289 }) 272 })
290 273
291 it('Should succeed with the corret parameters (advanced)', async function () { 274 it('Should succeed with the corret parameters (advanced)', async function () {
292 const fields: AbuseCreate = { 275 const fields: AbuseCreate = {
293 video: { 276 video: {
294 id: server.video.id, 277 id: server.store.video.id,
295 startAt: 1, 278 startAt: 1,
296 endAt: 5 279 endAt: 5
297 }, 280 },
@@ -299,37 +282,37 @@ describe('Test abuses API validators', function () {
299 predefinedReasons: [ 'serverRules' ] 282 predefinedReasons: [ 'serverRules' ]
300 } 283 }
301 284
302 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.OK_200 }) 285 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.OK_200 })
303 }) 286 })
304 }) 287 })
305 288
306 describe('When updating an abuse', function () { 289 describe('When updating an abuse', function () {
307 290
308 it('Should fail with a non authenticated user', async function () { 291 it('Should fail with a non authenticated user', async function () {
309 await updateAbuse(server.url, 'blabla', abuseId, {}, HttpStatusCode.UNAUTHORIZED_401) 292 await command.update({ token: 'blabla', abuseId, body: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
310 }) 293 })
311 294
312 it('Should fail with a non admin user', async function () { 295 it('Should fail with a non admin user', async function () {
313 await updateAbuse(server.url, userAccessToken, abuseId, {}, HttpStatusCode.FORBIDDEN_403) 296 await command.update({ token: userToken, abuseId, body: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
314 }) 297 })
315 298
316 it('Should fail with a bad abuse id', async function () { 299 it('Should fail with a bad abuse id', async function () {
317 await updateAbuse(server.url, server.accessToken, 45, {}, HttpStatusCode.NOT_FOUND_404) 300 await command.update({ abuseId: 45, body: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
318 }) 301 })
319 302
320 it('Should fail with a bad state', async function () { 303 it('Should fail with a bad state', async function () {
321 const body = { state: 5 } 304 const body = { state: 5 }
322 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) 305 await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
323 }) 306 })
324 307
325 it('Should fail with a bad moderation comment', async function () { 308 it('Should fail with a bad moderation comment', async function () {
326 const body = { moderationComment: 'b'.repeat(3001) } 309 const body = { moderationComment: 'b'.repeat(3001) }
327 await updateAbuse(server.url, server.accessToken, abuseId, body, HttpStatusCode.BAD_REQUEST_400) 310 await command.update({ abuseId, body, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
328 }) 311 })
329 312
330 it('Should succeed with the correct params', async function () { 313 it('Should succeed with the correct params', async function () {
331 const body = { state: AbuseState.ACCEPTED } 314 const body = { state: AbuseState.ACCEPTED }
332 await updateAbuse(server.url, server.accessToken, abuseId, body) 315 await command.update({ abuseId, body })
333 }) 316 })
334 }) 317 })
335 318
@@ -337,23 +320,23 @@ describe('Test abuses API validators', function () {
337 const message = 'my super message' 320 const message = 'my super message'
338 321
339 it('Should fail with an invalid abuse id', async function () { 322 it('Should fail with an invalid abuse id', async function () {
340 await addAbuseMessage(server.url, userAccessToken2, 888, message, HttpStatusCode.NOT_FOUND_404) 323 await command.addMessage({ token: userToken2, abuseId: 888, message, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
341 }) 324 })
342 325
343 it('Should fail with a non authenticated user', async function () { 326 it('Should fail with a non authenticated user', async function () {
344 await addAbuseMessage(server.url, 'fake_token', abuseId, message, HttpStatusCode.UNAUTHORIZED_401) 327 await command.addMessage({ token: 'fake_token', abuseId, message, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
345 }) 328 })
346 329
347 it('Should fail with an invalid logged in user', async function () { 330 it('Should fail with an invalid logged in user', async function () {
348 await addAbuseMessage(server.url, userAccessToken2, abuseId, message, HttpStatusCode.FORBIDDEN_403) 331 await command.addMessage({ token: userToken2, abuseId, message, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
349 }) 332 })
350 333
351 it('Should fail with an invalid message', async function () { 334 it('Should fail with an invalid message', async function () {
352 await addAbuseMessage(server.url, userAccessToken, abuseId, 'a'.repeat(5000), HttpStatusCode.BAD_REQUEST_400) 335 await command.addMessage({ token: userToken, abuseId, message: 'a'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
353 }) 336 })
354 337
355 it('Should suceed with the correct params', async function () { 338 it('Should suceed with the correct params', async function () {
356 const res = await addAbuseMessage(server.url, userAccessToken, abuseId, message) 339 const res = await command.addMessage({ token: userToken, abuseId, message })
357 messageId = res.body.abuseMessage.id 340 messageId = res.body.abuseMessage.id
358 }) 341 })
359 }) 342 })
@@ -361,96 +344,90 @@ describe('Test abuses API validators', function () {
361 describe('When listing abuse messages', function () { 344 describe('When listing abuse messages', function () {
362 345
363 it('Should fail with an invalid abuse id', async function () { 346 it('Should fail with an invalid abuse id', async function () {
364 await listAbuseMessages(server.url, userAccessToken, 888, HttpStatusCode.NOT_FOUND_404) 347 await command.listMessages({ token: userToken, abuseId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
365 }) 348 })
366 349
367 it('Should fail with a non authenticated user', async function () { 350 it('Should fail with a non authenticated user', async function () {
368 await listAbuseMessages(server.url, 'fake_token', abuseId, HttpStatusCode.UNAUTHORIZED_401) 351 await command.listMessages({ token: 'fake_token', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
369 }) 352 })
370 353
371 it('Should fail with an invalid logged in user', async function () { 354 it('Should fail with an invalid logged in user', async function () {
372 await listAbuseMessages(server.url, userAccessToken2, abuseId, HttpStatusCode.FORBIDDEN_403) 355 await command.listMessages({ token: userToken2, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
373 }) 356 })
374 357
375 it('Should succeed with the correct params', async function () { 358 it('Should succeed with the correct params', async function () {
376 await listAbuseMessages(server.url, userAccessToken, abuseId) 359 await command.listMessages({ token: userToken, abuseId })
377 }) 360 })
378 }) 361 })
379 362
380 describe('When deleting an abuse message', function () { 363 describe('When deleting an abuse message', function () {
381
382 it('Should fail with an invalid abuse id', async function () { 364 it('Should fail with an invalid abuse id', async function () {
383 await deleteAbuseMessage(server.url, userAccessToken, 888, messageId, HttpStatusCode.NOT_FOUND_404) 365 await command.deleteMessage({ token: userToken, abuseId: 888, messageId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
384 }) 366 })
385 367
386 it('Should fail with an invalid message id', async function () { 368 it('Should fail with an invalid message id', async function () {
387 await deleteAbuseMessage(server.url, userAccessToken, abuseId, 888, HttpStatusCode.NOT_FOUND_404) 369 await command.deleteMessage({ token: userToken, abuseId, messageId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
388 }) 370 })
389 371
390 it('Should fail with a non authenticated user', async function () { 372 it('Should fail with a non authenticated user', async function () {
391 await deleteAbuseMessage(server.url, 'fake_token', abuseId, messageId, HttpStatusCode.UNAUTHORIZED_401) 373 await command.deleteMessage({ token: 'fake_token', abuseId, messageId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
392 }) 374 })
393 375
394 it('Should fail with an invalid logged in user', async function () { 376 it('Should fail with an invalid logged in user', async function () {
395 await deleteAbuseMessage(server.url, userAccessToken2, abuseId, messageId, HttpStatusCode.FORBIDDEN_403) 377 await command.deleteMessage({ token: userToken2, abuseId, messageId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
396 }) 378 })
397 379
398 it('Should succeed with the correct params', async function () { 380 it('Should succeed with the correct params', async function () {
399 await deleteAbuseMessage(server.url, userAccessToken, abuseId, messageId) 381 await command.deleteMessage({ token: userToken, abuseId, messageId })
400 }) 382 })
401 }) 383 })
402 384
403 describe('When deleting a video abuse', function () { 385 describe('When deleting a video abuse', function () {
404 386
405 it('Should fail with a non authenticated user', async function () { 387 it('Should fail with a non authenticated user', async function () {
406 await deleteAbuse(server.url, 'blabla', abuseId, HttpStatusCode.UNAUTHORIZED_401) 388 await command.delete({ token: 'blabla', abuseId, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
407 }) 389 })
408 390
409 it('Should fail with a non admin user', async function () { 391 it('Should fail with a non admin user', async function () {
410 await deleteAbuse(server.url, userAccessToken, abuseId, HttpStatusCode.FORBIDDEN_403) 392 await command.delete({ token: userToken, abuseId, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
411 }) 393 })
412 394
413 it('Should fail with a bad abuse id', async function () { 395 it('Should fail with a bad abuse id', async function () {
414 await deleteAbuse(server.url, server.accessToken, 45, HttpStatusCode.NOT_FOUND_404) 396 await command.delete({ abuseId: 45, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
415 }) 397 })
416 398
417 it('Should succeed with the correct params', async function () { 399 it('Should succeed with the correct params', async function () {
418 await deleteAbuse(server.url, server.accessToken, abuseId) 400 await command.delete({ abuseId })
419 }) 401 })
420 }) 402 })
421 403
422 describe('When trying to manage messages of a remote abuse', function () { 404 describe('When trying to manage messages of a remote abuse', function () {
423 let remoteAbuseId: number 405 let remoteAbuseId: number
424 let anotherServer: ServerInfo 406 let anotherServer: PeerTubeServer
425 407
426 before(async function () { 408 before(async function () {
427 this.timeout(50000) 409 this.timeout(50000)
428 410
429 anotherServer = await flushAndRunServer(2) 411 anotherServer = await createSingleServer(2)
430 await setAccessTokensToServers([ anotherServer ]) 412 await setAccessTokensToServers([ anotherServer ])
431 413
432 await doubleFollow(anotherServer, server) 414 await doubleFollow(anotherServer, server)
433 415
434 const server2VideoId = await getVideoIdFromUUID(anotherServer.url, server.video.uuid) 416 const server2VideoId = await anotherServer.videos.getId({ uuid: server.store.video.uuid })
435 await reportAbuse({ 417 await anotherServer.abuses.report({ reason: 'remote server', videoId: server2VideoId })
436 url: anotherServer.url,
437 token: anotherServer.accessToken,
438 reason: 'remote server',
439 videoId: server2VideoId
440 })
441 418
442 await waitJobs([ server, anotherServer ]) 419 await waitJobs([ server, anotherServer ])
443 420
444 const res = await getAdminAbusesList({ url: server.url, token: server.accessToken, sort: '-createdAt' }) 421 const body = await command.getAdminList({ sort: '-createdAt' })
445 remoteAbuseId = res.body.data[0].id 422 remoteAbuseId = body.data[0].id
446 }) 423 })
447 424
448 it('Should fail when listing abuse messages of a remote abuse', async function () { 425 it('Should fail when listing abuse messages of a remote abuse', async function () {
449 await listAbuseMessages(server.url, server.accessToken, remoteAbuseId, HttpStatusCode.BAD_REQUEST_400) 426 await command.listMessages({ abuseId: remoteAbuseId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
450 }) 427 })
451 428
452 it('Should fail when creating abuse message of a remote abuse', async function () { 429 it('Should fail when creating abuse message of a remote abuse', async function () {
453 await addAbuseMessage(server.url, server.accessToken, remoteAbuseId, 'message', HttpStatusCode.BAD_REQUEST_400) 430 await command.addMessage({ abuseId: remoteAbuseId, message: 'message', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
454 }) 431 })
455 432
456 after(async function () { 433 after(async function () {
diff --git a/server/tests/api/check-params/accounts.ts b/server/tests/api/check-params/accounts.ts
index d1712cff6..141d869b7 100644
--- a/server/tests/api/check-params/accounts.ts
+++ b/server/tests/api/check-params/accounts.ts
@@ -1,26 +1,26 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils'
6import { 4import {
7 checkBadCountPagination, 5 checkBadCountPagination,
8 checkBadSortPagination, 6 checkBadSortPagination,
9 checkBadStartPagination 7 checkBadStartPagination,
10} from '../../../../shared/extra-utils/requests/check-api-params' 8 cleanupTests,
11import { getAccount } from '../../../../shared/extra-utils/users/accounts' 9 createSingleServer,
12import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 10 PeerTubeServer
11} from '@shared/extra-utils'
12import { HttpStatusCode } from '@shared/models'
13 13
14describe('Test accounts API validators', function () { 14describe('Test accounts API validators', function () {
15 const path = '/api/v1/accounts/' 15 const path = '/api/v1/accounts/'
16 let server: ServerInfo 16 let server: PeerTubeServer
17 17
18 // --------------------------------------------------------------- 18 // ---------------------------------------------------------------
19 19
20 before(async function () { 20 before(async function () {
21 this.timeout(30000) 21 this.timeout(30000)
22 22
23 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
24 }) 24 })
25 25
26 describe('When listing accounts', function () { 26 describe('When listing accounts', function () {
@@ -38,8 +38,9 @@ describe('Test accounts API validators', function () {
38 }) 38 })
39 39
40 describe('When getting an account', function () { 40 describe('When getting an account', function () {
41
41 it('Should return 404 with a non existing name', async function () { 42 it('Should return 404 with a non existing name', async function () {
42 await getAccount(server.url, 'arfaze', HttpStatusCode.NOT_FOUND_404) 43 await server.accounts.get({ accountName: 'arfaze', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
43 }) 44 })
44 }) 45 })
45 46
diff --git a/server/tests/api/check-params/blocklist.ts b/server/tests/api/check-params/blocklist.ts
index 5ed8810ce..7d5fae5cf 100644
--- a/server/tests/api/check-params/blocklist.ts
+++ b/server/tests/api/check-params/blocklist.ts
@@ -1,43 +1,38 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import { 4import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
6 cleanupTests, 8 cleanupTests,
7 createUser, 9 createMultipleServers,
8 doubleFollow, 10 doubleFollow,
9 flushAndRunMultipleServers,
10 makeDeleteRequest, 11 makeDeleteRequest,
11 makeGetRequest, 12 makeGetRequest,
12 makePostBodyRequest, 13 makePostBodyRequest,
13 ServerInfo, 14 PeerTubeServer,
14 setAccessTokensToServers, 15 setAccessTokensToServers
15 userLogin 16} from '@shared/extra-utils'
16} from '../../../../shared/extra-utils' 17import { HttpStatusCode } from '@shared/models'
17import {
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
23 18
24describe('Test blocklist API validators', function () { 19describe('Test blocklist API validators', function () {
25 let servers: ServerInfo[] 20 let servers: PeerTubeServer[]
26 let server: ServerInfo 21 let server: PeerTubeServer
27 let userAccessToken: string 22 let userAccessToken: string
28 23
29 before(async function () { 24 before(async function () {
30 this.timeout(60000) 25 this.timeout(60000)
31 26
32 servers = await flushAndRunMultipleServers(2) 27 servers = await createMultipleServers(2)
33 await setAccessTokensToServers(servers) 28 await setAccessTokensToServers(servers)
34 29
35 server = servers[0] 30 server = servers[0]
36 31
37 const user = { username: 'user1', password: 'password' } 32 const user = { username: 'user1', password: 'password' }
38 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 33 await server.users.create({ username: user.username, password: user.password })
39 34
40 userAccessToken = await userLogin(server, user) 35 userAccessToken = await server.login.getAccessToken(user)
41 36
42 await doubleFollow(servers[0], servers[1]) 37 await doubleFollow(servers[0], servers[1])
43 }) 38 })
@@ -54,7 +49,7 @@ describe('Test blocklist API validators', function () {
54 await makeGetRequest({ 49 await makeGetRequest({
55 url: server.url, 50 url: server.url,
56 path, 51 path,
57 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 52 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
58 }) 53 })
59 }) 54 })
60 55
@@ -77,7 +72,7 @@ describe('Test blocklist API validators', function () {
77 url: server.url, 72 url: server.url,
78 path, 73 path,
79 fields: { accountName: 'user1' }, 74 fields: { accountName: 'user1' },
80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 75 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
81 }) 76 })
82 }) 77 })
83 78
@@ -87,7 +82,7 @@ describe('Test blocklist API validators', function () {
87 token: server.accessToken, 82 token: server.accessToken,
88 path, 83 path,
89 fields: { accountName: 'user2' }, 84 fields: { accountName: 'user2' },
90 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 85 expectedStatus: HttpStatusCode.NOT_FOUND_404
91 }) 86 })
92 }) 87 })
93 88
@@ -97,7 +92,7 @@ describe('Test blocklist API validators', function () {
97 token: server.accessToken, 92 token: server.accessToken,
98 path, 93 path,
99 fields: { accountName: 'root' }, 94 fields: { accountName: 'root' },
100 statusCodeExpected: HttpStatusCode.CONFLICT_409 95 expectedStatus: HttpStatusCode.CONFLICT_409
101 }) 96 })
102 }) 97 })
103 98
@@ -107,7 +102,7 @@ describe('Test blocklist API validators', function () {
107 token: server.accessToken, 102 token: server.accessToken,
108 path, 103 path,
109 fields: { accountName: 'user1' }, 104 fields: { accountName: 'user1' },
110 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 105 expectedStatus: HttpStatusCode.NO_CONTENT_204
111 }) 106 })
112 }) 107 })
113 }) 108 })
@@ -117,7 +112,7 @@ describe('Test blocklist API validators', function () {
117 await makeDeleteRequest({ 112 await makeDeleteRequest({
118 url: server.url, 113 url: server.url,
119 path: path + '/user1', 114 path: path + '/user1',
120 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 115 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
121 }) 116 })
122 }) 117 })
123 118
@@ -126,7 +121,7 @@ describe('Test blocklist API validators', function () {
126 url: server.url, 121 url: server.url,
127 path: path + '/user2', 122 path: path + '/user2',
128 token: server.accessToken, 123 token: server.accessToken,
129 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 124 expectedStatus: HttpStatusCode.NOT_FOUND_404
130 }) 125 })
131 }) 126 })
132 127
@@ -135,7 +130,7 @@ describe('Test blocklist API validators', function () {
135 url: server.url, 130 url: server.url,
136 path: path + '/user1', 131 path: path + '/user1',
137 token: server.accessToken, 132 token: server.accessToken,
138 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 133 expectedStatus: HttpStatusCode.NO_CONTENT_204
139 }) 134 })
140 }) 135 })
141 }) 136 })
@@ -149,7 +144,7 @@ describe('Test blocklist API validators', function () {
149 await makeGetRequest({ 144 await makeGetRequest({
150 url: server.url, 145 url: server.url,
151 path, 146 path,
152 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 147 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
153 }) 148 })
154 }) 149 })
155 150
@@ -172,7 +167,7 @@ describe('Test blocklist API validators', function () {
172 url: server.url, 167 url: server.url,
173 path, 168 path,
174 fields: { host: 'localhost:9002' }, 169 fields: { host: 'localhost:9002' },
175 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 170 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
176 }) 171 })
177 }) 172 })
178 173
@@ -182,7 +177,7 @@ describe('Test blocklist API validators', function () {
182 token: server.accessToken, 177 token: server.accessToken,
183 path, 178 path,
184 fields: { host: 'localhost:9003' }, 179 fields: { host: 'localhost:9003' },
185 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 180 expectedStatus: HttpStatusCode.NO_CONTENT_204
186 }) 181 })
187 }) 182 })
188 183
@@ -192,7 +187,7 @@ describe('Test blocklist API validators', function () {
192 token: server.accessToken, 187 token: server.accessToken,
193 path, 188 path,
194 fields: { host: 'localhost:' + server.port }, 189 fields: { host: 'localhost:' + server.port },
195 statusCodeExpected: HttpStatusCode.CONFLICT_409 190 expectedStatus: HttpStatusCode.CONFLICT_409
196 }) 191 })
197 }) 192 })
198 193
@@ -202,7 +197,7 @@ describe('Test blocklist API validators', function () {
202 token: server.accessToken, 197 token: server.accessToken,
203 path, 198 path,
204 fields: { host: 'localhost:' + servers[1].port }, 199 fields: { host: 'localhost:' + servers[1].port },
205 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 200 expectedStatus: HttpStatusCode.NO_CONTENT_204
206 }) 201 })
207 }) 202 })
208 }) 203 })
@@ -212,7 +207,7 @@ describe('Test blocklist API validators', function () {
212 await makeDeleteRequest({ 207 await makeDeleteRequest({
213 url: server.url, 208 url: server.url,
214 path: path + '/localhost:' + servers[1].port, 209 path: path + '/localhost:' + servers[1].port,
215 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 210 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
216 }) 211 })
217 }) 212 })
218 213
@@ -221,7 +216,7 @@ describe('Test blocklist API validators', function () {
221 url: server.url, 216 url: server.url,
222 path: path + '/localhost:9004', 217 path: path + '/localhost:9004',
223 token: server.accessToken, 218 token: server.accessToken,
224 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 219 expectedStatus: HttpStatusCode.NOT_FOUND_404
225 }) 220 })
226 }) 221 })
227 222
@@ -230,7 +225,7 @@ describe('Test blocklist API validators', function () {
230 url: server.url, 225 url: server.url,
231 path: path + '/localhost:' + servers[1].port, 226 path: path + '/localhost:' + servers[1].port,
232 token: server.accessToken, 227 token: server.accessToken,
233 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 228 expectedStatus: HttpStatusCode.NO_CONTENT_204
234 }) 229 })
235 }) 230 })
236 }) 231 })
@@ -247,7 +242,7 @@ describe('Test blocklist API validators', function () {
247 await makeGetRequest({ 242 await makeGetRequest({
248 url: server.url, 243 url: server.url,
249 path, 244 path,
250 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 245 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
251 }) 246 })
252 }) 247 })
253 248
@@ -256,7 +251,7 @@ describe('Test blocklist API validators', function () {
256 url: server.url, 251 url: server.url,
257 token: userAccessToken, 252 token: userAccessToken,
258 path, 253 path,
259 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 254 expectedStatus: HttpStatusCode.FORBIDDEN_403
260 }) 255 })
261 }) 256 })
262 257
@@ -279,7 +274,7 @@ describe('Test blocklist API validators', function () {
279 url: server.url, 274 url: server.url,
280 path, 275 path,
281 fields: { accountName: 'user1' }, 276 fields: { accountName: 'user1' },
282 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 277 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
283 }) 278 })
284 }) 279 })
285 280
@@ -289,7 +284,7 @@ describe('Test blocklist API validators', function () {
289 token: userAccessToken, 284 token: userAccessToken,
290 path, 285 path,
291 fields: { accountName: 'user1' }, 286 fields: { accountName: 'user1' },
292 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 287 expectedStatus: HttpStatusCode.FORBIDDEN_403
293 }) 288 })
294 }) 289 })
295 290
@@ -299,7 +294,7 @@ describe('Test blocklist API validators', function () {
299 token: server.accessToken, 294 token: server.accessToken,
300 path, 295 path,
301 fields: { accountName: 'user2' }, 296 fields: { accountName: 'user2' },
302 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 297 expectedStatus: HttpStatusCode.NOT_FOUND_404
303 }) 298 })
304 }) 299 })
305 300
@@ -309,7 +304,7 @@ describe('Test blocklist API validators', function () {
309 token: server.accessToken, 304 token: server.accessToken,
310 path, 305 path,
311 fields: { accountName: 'root' }, 306 fields: { accountName: 'root' },
312 statusCodeExpected: HttpStatusCode.CONFLICT_409 307 expectedStatus: HttpStatusCode.CONFLICT_409
313 }) 308 })
314 }) 309 })
315 310
@@ -319,7 +314,7 @@ describe('Test blocklist API validators', function () {
319 token: server.accessToken, 314 token: server.accessToken,
320 path, 315 path,
321 fields: { accountName: 'user1' }, 316 fields: { accountName: 'user1' },
322 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 317 expectedStatus: HttpStatusCode.NO_CONTENT_204
323 }) 318 })
324 }) 319 })
325 }) 320 })
@@ -329,7 +324,7 @@ describe('Test blocklist API validators', function () {
329 await makeDeleteRequest({ 324 await makeDeleteRequest({
330 url: server.url, 325 url: server.url,
331 path: path + '/user1', 326 path: path + '/user1',
332 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 327 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
333 }) 328 })
334 }) 329 })
335 330
@@ -338,7 +333,7 @@ describe('Test blocklist API validators', function () {
338 url: server.url, 333 url: server.url,
339 path: path + '/user1', 334 path: path + '/user1',
340 token: userAccessToken, 335 token: userAccessToken,
341 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 336 expectedStatus: HttpStatusCode.FORBIDDEN_403
342 }) 337 })
343 }) 338 })
344 339
@@ -347,7 +342,7 @@ describe('Test blocklist API validators', function () {
347 url: server.url, 342 url: server.url,
348 path: path + '/user2', 343 path: path + '/user2',
349 token: server.accessToken, 344 token: server.accessToken,
350 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 345 expectedStatus: HttpStatusCode.NOT_FOUND_404
351 }) 346 })
352 }) 347 })
353 348
@@ -356,7 +351,7 @@ describe('Test blocklist API validators', function () {
356 url: server.url, 351 url: server.url,
357 path: path + '/user1', 352 path: path + '/user1',
358 token: server.accessToken, 353 token: server.accessToken,
359 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 354 expectedStatus: HttpStatusCode.NO_CONTENT_204
360 }) 355 })
361 }) 356 })
362 }) 357 })
@@ -370,7 +365,7 @@ describe('Test blocklist API validators', function () {
370 await makeGetRequest({ 365 await makeGetRequest({
371 url: server.url, 366 url: server.url,
372 path, 367 path,
373 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 368 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
374 }) 369 })
375 }) 370 })
376 371
@@ -379,7 +374,7 @@ describe('Test blocklist API validators', function () {
379 url: server.url, 374 url: server.url,
380 token: userAccessToken, 375 token: userAccessToken,
381 path, 376 path,
382 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 377 expectedStatus: HttpStatusCode.FORBIDDEN_403
383 }) 378 })
384 }) 379 })
385 380
@@ -402,7 +397,7 @@ describe('Test blocklist API validators', function () {
402 url: server.url, 397 url: server.url,
403 path, 398 path,
404 fields: { host: 'localhost:' + servers[1].port }, 399 fields: { host: 'localhost:' + servers[1].port },
405 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 400 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
406 }) 401 })
407 }) 402 })
408 403
@@ -412,7 +407,7 @@ describe('Test blocklist API validators', function () {
412 token: userAccessToken, 407 token: userAccessToken,
413 path, 408 path,
414 fields: { host: 'localhost:' + servers[1].port }, 409 fields: { host: 'localhost:' + servers[1].port },
415 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 410 expectedStatus: HttpStatusCode.FORBIDDEN_403
416 }) 411 })
417 }) 412 })
418 413
@@ -422,7 +417,7 @@ describe('Test blocklist API validators', function () {
422 token: server.accessToken, 417 token: server.accessToken,
423 path, 418 path,
424 fields: { host: 'localhost:9003' }, 419 fields: { host: 'localhost:9003' },
425 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 420 expectedStatus: HttpStatusCode.NO_CONTENT_204
426 }) 421 })
427 }) 422 })
428 423
@@ -432,7 +427,7 @@ describe('Test blocklist API validators', function () {
432 token: server.accessToken, 427 token: server.accessToken,
433 path, 428 path,
434 fields: { host: 'localhost:' + server.port }, 429 fields: { host: 'localhost:' + server.port },
435 statusCodeExpected: HttpStatusCode.CONFLICT_409 430 expectedStatus: HttpStatusCode.CONFLICT_409
436 }) 431 })
437 }) 432 })
438 433
@@ -442,7 +437,7 @@ describe('Test blocklist API validators', function () {
442 token: server.accessToken, 437 token: server.accessToken,
443 path, 438 path,
444 fields: { host: 'localhost:' + servers[1].port }, 439 fields: { host: 'localhost:' + servers[1].port },
445 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 440 expectedStatus: HttpStatusCode.NO_CONTENT_204
446 }) 441 })
447 }) 442 })
448 }) 443 })
@@ -452,7 +447,7 @@ describe('Test blocklist API validators', function () {
452 await makeDeleteRequest({ 447 await makeDeleteRequest({
453 url: server.url, 448 url: server.url,
454 path: path + '/localhost:' + servers[1].port, 449 path: path + '/localhost:' + servers[1].port,
455 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 450 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
456 }) 451 })
457 }) 452 })
458 453
@@ -461,7 +456,7 @@ describe('Test blocklist API validators', function () {
461 url: server.url, 456 url: server.url,
462 path: path + '/localhost:' + servers[1].port, 457 path: path + '/localhost:' + servers[1].port,
463 token: userAccessToken, 458 token: userAccessToken,
464 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 459 expectedStatus: HttpStatusCode.FORBIDDEN_403
465 }) 460 })
466 }) 461 })
467 462
@@ -470,7 +465,7 @@ describe('Test blocklist API validators', function () {
470 url: server.url, 465 url: server.url,
471 path: path + '/localhost:9004', 466 path: path + '/localhost:9004',
472 token: server.accessToken, 467 token: server.accessToken,
473 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 468 expectedStatus: HttpStatusCode.NOT_FOUND_404
474 }) 469 })
475 }) 470 })
476 471
@@ -479,7 +474,7 @@ describe('Test blocklist API validators', function () {
479 url: server.url, 474 url: server.url,
480 path: path + '/localhost:' + servers[1].port, 475 path: path + '/localhost:' + servers[1].port,
481 token: server.accessToken, 476 token: server.accessToken,
482 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 477 expectedStatus: HttpStatusCode.NO_CONTENT_204
483 }) 478 })
484 }) 479 })
485 }) 480 })
diff --git a/server/tests/api/check-params/bulk.ts b/server/tests/api/check-params/bulk.ts
index 07b920ba7..bc9d7784d 100644
--- a/server/tests/api/check-params/bulk.ts
+++ b/server/tests/api/check-params/bulk.ts
@@ -1,19 +1,11 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { 4import { cleanupTests, createSingleServer, makePostBodyRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
5 cleanupTests, 5import { HttpStatusCode } from '@shared/models'
6 createUser,
7 flushAndRunServer,
8 ServerInfo,
9 setAccessTokensToServers,
10 userLogin
11} from '../../../../shared/extra-utils'
12import { makePostBodyRequest } from '../../../../shared/extra-utils/requests/requests'
13import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
14 6
15describe('Test bulk API validators', function () { 7describe('Test bulk API validators', function () {
16 let server: ServerInfo 8 let server: PeerTubeServer
17 let userAccessToken: string 9 let userAccessToken: string
18 10
19 // --------------------------------------------------------------- 11 // ---------------------------------------------------------------
@@ -21,13 +13,13 @@ describe('Test bulk API validators', function () {
21 before(async function () { 13 before(async function () {
22 this.timeout(120000) 14 this.timeout(120000)
23 15
24 server = await flushAndRunServer(1) 16 server = await createSingleServer(1)
25 await setAccessTokensToServers([ server ]) 17 await setAccessTokensToServers([ server ])
26 18
27 const user = { username: 'user1', password: 'password' } 19 const user = { username: 'user1', password: 'password' }
28 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 20 await server.users.create({ username: user.username, password: user.password })
29 21
30 userAccessToken = await userLogin(server, user) 22 userAccessToken = await server.login.getAccessToken(user)
31 }) 23 })
32 24
33 describe('When removing comments of', function () { 25 describe('When removing comments of', function () {
@@ -38,7 +30,7 @@ describe('Test bulk API validators', function () {
38 url: server.url, 30 url: server.url,
39 path, 31 path,
40 fields: { accountName: 'user1', scope: 'my-videos' }, 32 fields: { accountName: 'user1', scope: 'my-videos' },
41 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 33 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
42 }) 34 })
43 }) 35 })
44 36
@@ -48,7 +40,7 @@ describe('Test bulk API validators', function () {
48 token: server.accessToken, 40 token: server.accessToken,
49 path, 41 path,
50 fields: { accountName: 'user2', scope: 'my-videos' }, 42 fields: { accountName: 'user2', scope: 'my-videos' },
51 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 43 expectedStatus: HttpStatusCode.NOT_FOUND_404
52 }) 44 })
53 }) 45 })
54 46
@@ -58,7 +50,7 @@ describe('Test bulk API validators', function () {
58 token: server.accessToken, 50 token: server.accessToken,
59 path, 51 path,
60 fields: { accountName: 'user1', scope: 'my-videoss' }, 52 fields: { accountName: 'user1', scope: 'my-videoss' },
61 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 53 expectedStatus: HttpStatusCode.BAD_REQUEST_400
62 }) 54 })
63 }) 55 })
64 56
@@ -68,7 +60,7 @@ describe('Test bulk API validators', function () {
68 token: userAccessToken, 60 token: userAccessToken,
69 path, 61 path,
70 fields: { accountName: 'user1', scope: 'instance' }, 62 fields: { accountName: 'user1', scope: 'instance' },
71 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 63 expectedStatus: HttpStatusCode.FORBIDDEN_403
72 }) 64 })
73 }) 65 })
74 66
@@ -78,7 +70,7 @@ describe('Test bulk API validators', function () {
78 token: server.accessToken, 70 token: server.accessToken,
79 path, 71 path,
80 fields: { accountName: 'user1', scope: 'instance' }, 72 fields: { accountName: 'user1', scope: 'instance' },
81 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 73 expectedStatus: HttpStatusCode.NO_CONTENT_204
82 }) 74 })
83 }) 75 })
84 }) 76 })
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 9549070ef..87cb2287e 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -1,26 +1,21 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import { omit } from 'lodash'
4import 'mocha' 3import 'mocha'
5import { CustomConfig } from '../../../../shared/models/server/custom-config.model' 4import { omit } from 'lodash'
6
7import { 5import {
8 cleanupTests, 6 cleanupTests,
9 createUser, 7 createSingleServer,
10 flushAndRunServer,
11 immutableAssign,
12 makeDeleteRequest, 8 makeDeleteRequest,
13 makeGetRequest, 9 makeGetRequest,
14 makePutBodyRequest, 10 makePutBodyRequest,
15 ServerInfo, 11 PeerTubeServer,
16 setAccessTokensToServers, 12 setAccessTokensToServers
17 userLogin 13} from '@shared/extra-utils'
18} from '../../../../shared/extra-utils' 14import { CustomConfig, HttpStatusCode } from '@shared/models'
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
20 15
21describe('Test config API validators', function () { 16describe('Test config API validators', function () {
22 const path = '/api/v1/config/custom' 17 const path = '/api/v1/config/custom'
23 let server: ServerInfo 18 let server: PeerTubeServer
24 let userAccessToken: string 19 let userAccessToken: string
25 const updateParams: CustomConfig = { 20 const updateParams: CustomConfig = {
26 instance: { 21 instance: {
@@ -201,7 +196,7 @@ describe('Test config API validators', function () {
201 before(async function () { 196 before(async function () {
202 this.timeout(30000) 197 this.timeout(30000)
203 198
204 server = await flushAndRunServer(1) 199 server = await createSingleServer(1)
205 200
206 await setAccessTokensToServers([ server ]) 201 await setAccessTokensToServers([ server ])
207 202
@@ -209,8 +204,8 @@ describe('Test config API validators', function () {
209 username: 'user1', 204 username: 'user1',
210 password: 'password' 205 password: 'password'
211 } 206 }
212 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 207 await server.users.create({ username: user.username, password: user.password })
213 userAccessToken = await userLogin(server, user) 208 userAccessToken = await server.login.getAccessToken(user)
214 }) 209 })
215 210
216 describe('When getting the configuration', function () { 211 describe('When getting the configuration', function () {
@@ -218,7 +213,7 @@ describe('Test config API validators', function () {
218 await makeGetRequest({ 213 await makeGetRequest({
219 url: server.url, 214 url: server.url,
220 path, 215 path,
221 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 216 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
222 }) 217 })
223 }) 218 })
224 219
@@ -227,7 +222,7 @@ describe('Test config API validators', function () {
227 url: server.url, 222 url: server.url,
228 path, 223 path,
229 token: userAccessToken, 224 token: userAccessToken,
230 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 225 expectedStatus: HttpStatusCode.FORBIDDEN_403
231 }) 226 })
232 }) 227 })
233 }) 228 })
@@ -238,7 +233,7 @@ describe('Test config API validators', function () {
238 url: server.url, 233 url: server.url,
239 path, 234 path,
240 fields: updateParams, 235 fields: updateParams,
241 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 236 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
242 }) 237 })
243 }) 238 })
244 239
@@ -248,7 +243,7 @@ describe('Test config API validators', function () {
248 path, 243 path,
249 fields: updateParams, 244 fields: updateParams,
250 token: userAccessToken, 245 token: userAccessToken,
251 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 246 expectedStatus: HttpStatusCode.FORBIDDEN_403
252 }) 247 })
253 }) 248 })
254 249
@@ -260,47 +255,53 @@ describe('Test config API validators', function () {
260 path, 255 path,
261 fields: newUpdateParams, 256 fields: newUpdateParams,
262 token: server.accessToken, 257 token: server.accessToken,
263 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 258 expectedStatus: HttpStatusCode.BAD_REQUEST_400
264 }) 259 })
265 }) 260 })
266 261
267 it('Should fail with a bad default NSFW policy', async function () { 262 it('Should fail with a bad default NSFW policy', async function () {
268 const newUpdateParams = immutableAssign(updateParams, { 263 const newUpdateParams = {
264 ...updateParams,
265
269 instance: { 266 instance: {
270 defaultNSFWPolicy: 'hello' 267 defaultNSFWPolicy: 'hello'
271 } 268 }
272 }) 269 }
273 270
274 await makePutBodyRequest({ 271 await makePutBodyRequest({
275 url: server.url, 272 url: server.url,
276 path, 273 path,
277 fields: newUpdateParams, 274 fields: newUpdateParams,
278 token: server.accessToken, 275 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 276 expectedStatus: HttpStatusCode.BAD_REQUEST_400
280 }) 277 })
281 }) 278 })
282 279
283 it('Should fail if email disabled and signup requires email verification', async function () { 280 it('Should fail if email disabled and signup requires email verification', async function () {
284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts 281 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
285 const newUpdateParams = immutableAssign(updateParams, { 282 const newUpdateParams = {
283 ...updateParams,
284
286 signup: { 285 signup: {
287 enabled: true, 286 enabled: true,
288 limit: 5, 287 limit: 5,
289 requiresEmailVerification: true 288 requiresEmailVerification: true
290 } 289 }
291 }) 290 }
292 291
293 await makePutBodyRequest({ 292 await makePutBodyRequest({
294 url: server.url, 293 url: server.url,
295 path, 294 path,
296 fields: newUpdateParams, 295 fields: newUpdateParams,
297 token: server.accessToken, 296 token: server.accessToken,
298 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 297 expectedStatus: HttpStatusCode.BAD_REQUEST_400
299 }) 298 })
300 }) 299 })
301 300
302 it('Should fail with a disabled webtorrent & hls transcoding', async function () { 301 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
303 const newUpdateParams = immutableAssign(updateParams, { 302 const newUpdateParams = {
303 ...updateParams,
304
304 transcoding: { 305 transcoding: {
305 hls: { 306 hls: {
306 enabled: false 307 enabled: false
@@ -309,14 +310,14 @@ describe('Test config API validators', function () {
309 enabled: false 310 enabled: false
310 } 311 }
311 } 312 }
312 }) 313 }
313 314
314 await makePutBodyRequest({ 315 await makePutBodyRequest({
315 url: server.url, 316 url: server.url,
316 path, 317 path,
317 fields: newUpdateParams, 318 fields: newUpdateParams,
318 token: server.accessToken, 319 token: server.accessToken,
319 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 320 expectedStatus: HttpStatusCode.BAD_REQUEST_400
320 }) 321 })
321 }) 322 })
322 323
@@ -326,7 +327,7 @@ describe('Test config API validators', function () {
326 path, 327 path,
327 fields: updateParams, 328 fields: updateParams,
328 token: server.accessToken, 329 token: server.accessToken,
329 statusCodeExpected: HttpStatusCode.OK_200 330 expectedStatus: HttpStatusCode.OK_200
330 }) 331 })
331 }) 332 })
332 }) 333 })
@@ -336,7 +337,7 @@ describe('Test config API validators', function () {
336 await makeDeleteRequest({ 337 await makeDeleteRequest({
337 url: server.url, 338 url: server.url,
338 path, 339 path,
339 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 340 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
340 }) 341 })
341 }) 342 })
342 343
@@ -345,7 +346,7 @@ describe('Test config API validators', function () {
345 url: server.url, 346 url: server.url,
346 path, 347 path,
347 token: userAccessToken, 348 token: userAccessToken,
348 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 349 expectedStatus: HttpStatusCode.FORBIDDEN_403
349 }) 350 })
350 }) 351 })
351 }) 352 })
diff --git a/server/tests/api/check-params/contact-form.ts b/server/tests/api/check-params/contact-form.ts
index c7f9c1b47..1df9993da 100644
--- a/server/tests/api/check-params/contact-form.ts
+++ b/server/tests/api/check-params/contact-form.ts
@@ -1,14 +1,12 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { cleanupTests, createSingleServer, killallServers, MockSmtpServer, PeerTubeServer } from '@shared/extra-utils'
5import { cleanupTests, flushAndRunServer, immutableAssign, killallServers, reRunServer, ServerInfo } from '../../../../shared/extra-utils' 5import { ContactFormCommand } from '@shared/extra-utils/server'
6import { sendContactForm } from '../../../../shared/extra-utils/server/contact-form' 6import { HttpStatusCode } from '@shared/models'
7import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
8import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
9 7
10describe('Test contact form API validators', function () { 8describe('Test contact form API validators', function () {
11 let server: ServerInfo 9 let server: PeerTubeServer
12 const emails: object[] = [] 10 const emails: object[] = []
13 const defaultBody = { 11 const defaultBody = {
14 fromName: 'super name', 12 fromName: 'super name',
@@ -17,6 +15,7 @@ describe('Test contact form API validators', function () {
17 body: 'Hello, how are you?' 15 body: 'Hello, how are you?'
18 } 16 }
19 let emailPort: number 17 let emailPort: number
18 let command: ContactFormCommand
20 19
21 // --------------------------------------------------------------- 20 // ---------------------------------------------------------------
22 21
@@ -26,86 +25,51 @@ describe('Test contact form API validators', function () {
26 emailPort = await MockSmtpServer.Instance.collectEmails(emails) 25 emailPort = await MockSmtpServer.Instance.collectEmails(emails)
27 26
28 // Email is disabled 27 // Email is disabled
29 server = await flushAndRunServer(1) 28 server = await createSingleServer(1)
29 command = server.contactForm
30 }) 30 })
31 31
32 it('Should not accept a contact form if emails are disabled', async function () { 32 it('Should not accept a contact form if emails are disabled', async function () {
33 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) 33 await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
34 }) 34 })
35 35
36 it('Should not accept a contact form if it is disabled in the configuration', async function () { 36 it('Should not accept a contact form if it is disabled in the configuration', async function () {
37 this.timeout(10000) 37 this.timeout(10000)
38 38
39 killallServers([ server ]) 39 await killallServers([ server ])
40 40
41 // Contact form is disabled 41 // Contact form is disabled
42 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } }) 42 await server.run({ smtp: { hostname: 'localhost', port: emailPort }, contact_form: { enabled: false } })
43 await sendContactForm(immutableAssign(defaultBody, { url: server.url, expectedStatus: HttpStatusCode.CONFLICT_409 })) 43 await command.send({ ...defaultBody, expectedStatus: HttpStatusCode.CONFLICT_409 })
44 }) 44 })
45 45
46 it('Should not accept a contact form if from email is invalid', async function () { 46 it('Should not accept a contact form if from email is invalid', async function () {
47 this.timeout(10000) 47 this.timeout(10000)
48 48
49 killallServers([ server ]) 49 await killallServers([ server ])
50 50
51 // Email & contact form enabled 51 // Email & contact form enabled
52 await reRunServer(server, { smtp: { hostname: 'localhost', port: emailPort } }) 52 await server.run({ smtp: { hostname: 'localhost', port: emailPort } })
53 53
54 await sendContactForm(immutableAssign(defaultBody, { 54 await command.send({ ...defaultBody, fromEmail: 'badEmail', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
55 url: server.url, 55 await command.send({ ...defaultBody, fromEmail: 'badEmail@', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
56 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 56 await command.send({ ...defaultBody, fromEmail: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
57 fromEmail: 'badEmail'
58 }))
59 await sendContactForm(immutableAssign(defaultBody, {
60 url: server.url,
61 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
62 fromEmail: 'badEmail@'
63 }))
64 await sendContactForm(immutableAssign(defaultBody, {
65 url: server.url,
66 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
67 fromEmail: undefined
68 }))
69 }) 57 })
70 58
71 it('Should not accept a contact form if from name is invalid', async function () { 59 it('Should not accept a contact form if from name is invalid', async function () {
72 await sendContactForm(immutableAssign(defaultBody, { 60 await command.send({ ...defaultBody, fromName: 'name'.repeat(100), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
73 url: server.url, 61 await command.send({ ...defaultBody, fromName: '', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
74 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 62 await command.send({ ...defaultBody, fromName: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
75 fromName: 'name'.repeat(100)
76 }))
77 await sendContactForm(immutableAssign(defaultBody, {
78 url: server.url,
79 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
80 fromName: ''
81 }))
82 await sendContactForm(immutableAssign(defaultBody, {
83 url: server.url,
84 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
85 fromName: undefined
86 }))
87 }) 63 })
88 64
89 it('Should not accept a contact form if body is invalid', async function () { 65 it('Should not accept a contact form if body is invalid', async function () {
90 await sendContactForm(immutableAssign(defaultBody, { 66 await command.send({ ...defaultBody, body: 'body'.repeat(5000), expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
91 url: server.url, 67 await command.send({ ...defaultBody, body: 'a', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
92 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 68 await command.send({ ...defaultBody, body: undefined, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
93 body: 'body'.repeat(5000)
94 }))
95 await sendContactForm(immutableAssign(defaultBody, {
96 url: server.url,
97 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
98 body: 'a'
99 }))
100 await sendContactForm(immutableAssign(defaultBody, {
101 url: server.url,
102 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
103 body: undefined
104 }))
105 }) 69 })
106 70
107 it('Should accept a contact form with the correct parameters', async function () { 71 it('Should accept a contact form with the correct parameters', async function () {
108 await sendContactForm(immutableAssign(defaultBody, { url: server.url })) 72 await command.send(defaultBody)
109 }) 73 })
110 74
111 after(async function () { 75 after(async function () {
diff --git a/server/tests/api/check-params/custom-pages.ts b/server/tests/api/check-params/custom-pages.ts
index 74ca3384c..9fbbea315 100644
--- a/server/tests/api/check-params/custom-pages.ts
+++ b/server/tests/api/check-params/custom-pages.ts
@@ -1,21 +1,20 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
5import { 4import {
6 cleanupTests, 5 cleanupTests,
7 createUser, 6 createSingleServer,
8 flushAndRunServer, 7 makeGetRequest,
9 ServerInfo, 8 makePutBodyRequest,
10 setAccessTokensToServers, 9 PeerTubeServer,
11 userLogin 10 setAccessTokensToServers
12} from '../../../../shared/extra-utils' 11} from '@shared/extra-utils'
13import { makeGetRequest, makePutBodyRequest } from '../../../../shared/extra-utils/requests/requests' 12import { HttpStatusCode } from '@shared/models'
14 13
15describe('Test custom pages validators', function () { 14describe('Test custom pages validators', function () {
16 const path = '/api/v1/custom-pages/homepage/instance' 15 const path = '/api/v1/custom-pages/homepage/instance'
17 16
18 let server: ServerInfo 17 let server: PeerTubeServer
19 let userAccessToken: string 18 let userAccessToken: string
20 19
21 // --------------------------------------------------------------- 20 // ---------------------------------------------------------------
@@ -23,13 +22,13 @@ describe('Test custom pages validators', function () {
23 before(async function () { 22 before(async function () {
24 this.timeout(120000) 23 this.timeout(120000)
25 24
26 server = await flushAndRunServer(1) 25 server = await createSingleServer(1)
27 await setAccessTokensToServers([ server ]) 26 await setAccessTokensToServers([ server ])
28 27
29 const user = { username: 'user1', password: 'password' } 28 const user = { username: 'user1', password: 'password' }
30 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 29 await server.users.create({ username: user.username, password: user.password })
31 30
32 userAccessToken = await userLogin(server, user) 31 userAccessToken = await server.login.getAccessToken(user)
33 }) 32 })
34 33
35 describe('When updating instance homepage', function () { 34 describe('When updating instance homepage', function () {
@@ -39,7 +38,7 @@ describe('Test custom pages validators', function () {
39 url: server.url, 38 url: server.url,
40 path, 39 path,
41 fields: { content: 'super content' }, 40 fields: { content: 'super content' },
42 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 41 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
43 }) 42 })
44 }) 43 })
45 44
@@ -49,7 +48,7 @@ describe('Test custom pages validators', function () {
49 path, 48 path,
50 token: userAccessToken, 49 token: userAccessToken,
51 fields: { content: 'super content' }, 50 fields: { content: 'super content' },
52 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 51 expectedStatus: HttpStatusCode.FORBIDDEN_403
53 }) 52 })
54 }) 53 })
55 54
@@ -59,7 +58,7 @@ describe('Test custom pages validators', function () {
59 path, 58 path,
60 token: server.accessToken, 59 token: server.accessToken,
61 fields: { content: 'super content' }, 60 fields: { content: 'super content' },
62 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 61 expectedStatus: HttpStatusCode.NO_CONTENT_204
63 }) 62 })
64 }) 63 })
65 }) 64 })
@@ -70,7 +69,7 @@ describe('Test custom pages validators', function () {
70 await makeGetRequest({ 69 await makeGetRequest({
71 url: server.url, 70 url: server.url,
72 path, 71 path,
73 statusCodeExpected: HttpStatusCode.OK_200 72 expectedStatus: HttpStatusCode.OK_200
74 }) 73 })
75 }) 74 })
76 }) 75 })
diff --git a/server/tests/api/check-params/debug.ts b/server/tests/api/check-params/debug.ts
index 37bf0f99b..a55786359 100644
--- a/server/tests/api/check-params/debug.ts
+++ b/server/tests/api/check-params/debug.ts
@@ -1,21 +1,12 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
5import { 5import { HttpStatusCode } from '@shared/models'
6 cleanupTests,
7 createUser,
8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers,
11 userLogin
12} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
15 6
16describe('Test debug API validators', function () { 7describe('Test debug API validators', function () {
17 const path = '/api/v1/server/debug' 8 const path = '/api/v1/server/debug'
18 let server: ServerInfo 9 let server: PeerTubeServer
19 let userAccessToken = '' 10 let userAccessToken = ''
20 11
21 // --------------------------------------------------------------- 12 // ---------------------------------------------------------------
@@ -23,7 +14,7 @@ describe('Test debug API validators', function () {
23 before(async function () { 14 before(async function () {
24 this.timeout(120000) 15 this.timeout(120000)
25 16
26 server = await flushAndRunServer(1) 17 server = await createSingleServer(1)
27 18
28 await setAccessTokensToServers([ server ]) 19 await setAccessTokensToServers([ server ])
29 20
@@ -31,8 +22,8 @@ describe('Test debug API validators', function () {
31 username: 'user1', 22 username: 'user1',
32 password: 'my super password' 23 password: 'my super password'
33 } 24 }
34 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 25 await server.users.create({ username: user.username, password: user.password })
35 userAccessToken = await userLogin(server, user) 26 userAccessToken = await server.login.getAccessToken(user)
36 }) 27 })
37 28
38 describe('When getting debug endpoint', function () { 29 describe('When getting debug endpoint', function () {
@@ -41,7 +32,7 @@ describe('Test debug API validators', function () {
41 await makeGetRequest({ 32 await makeGetRequest({
42 url: server.url, 33 url: server.url,
43 path, 34 path,
44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 35 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
45 }) 36 })
46 }) 37 })
47 38
@@ -50,7 +41,7 @@ describe('Test debug API validators', function () {
50 url: server.url, 41 url: server.url,
51 path, 42 path,
52 token: userAccessToken, 43 token: userAccessToken,
53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 44 expectedStatus: HttpStatusCode.FORBIDDEN_403
54 }) 45 })
55 }) 46 })
56 47
@@ -60,7 +51,7 @@ describe('Test debug API validators', function () {
60 path, 51 path,
61 token: server.accessToken, 52 token: server.accessToken,
62 query: { startDate: new Date().toISOString() }, 53 query: { startDate: new Date().toISOString() },
63 statusCodeExpected: HttpStatusCode.OK_200 54 expectedStatus: HttpStatusCode.OK_200
64 }) 55 })
65 }) 56 })
66 }) 57 })
diff --git a/server/tests/api/check-params/follows.ts b/server/tests/api/check-params/follows.ts
index c03dd5c9c..2bc9f6b96 100644
--- a/server/tests/api/check-params/follows.ts
+++ b/server/tests/api/check-params/follows.ts
@@ -1,33 +1,29 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import {
6 cleanupTests,
7 createUser,
8 flushAndRunServer,
9 makeDeleteRequest, makeGetRequest,
10 makePostBodyRequest,
11 ServerInfo,
12 setAccessTokensToServers,
13 userLogin
14} from '../../../../shared/extra-utils'
15import { 4import {
16 checkBadCountPagination, 5 checkBadCountPagination,
17 checkBadSortPagination, 6 checkBadSortPagination,
18 checkBadStartPagination 7 checkBadStartPagination,
19} from '../../../../shared/extra-utils/requests/check-api-params' 8 cleanupTests,
20import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 9 createSingleServer,
10 makeDeleteRequest,
11 makeGetRequest,
12 makePostBodyRequest,
13 PeerTubeServer,
14 setAccessTokensToServers
15} from '@shared/extra-utils'
16import { HttpStatusCode } from '@shared/models'
21 17
22describe('Test server follows API validators', function () { 18describe('Test server follows API validators', function () {
23 let server: ServerInfo 19 let server: PeerTubeServer
24 20
25 // --------------------------------------------------------------- 21 // ---------------------------------------------------------------
26 22
27 before(async function () { 23 before(async function () {
28 this.timeout(30000) 24 this.timeout(30000)
29 25
30 server = await flushAndRunServer(1) 26 server = await createSingleServer(1)
31 27
32 await setAccessTokensToServers([ server ]) 28 await setAccessTokensToServers([ server ])
33 }) 29 })
@@ -36,64 +32,68 @@ describe('Test server follows API validators', function () {
36 let userAccessToken = null 32 let userAccessToken = null
37 33
38 before(async function () { 34 before(async function () {
39 const user = { 35 userAccessToken = await server.users.generateUserAndToken('user1')
40 username: 'user1',
41 password: 'password'
42 }
43
44 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
45 userAccessToken = await userLogin(server, user)
46 }) 36 })
47 37
48 describe('When adding follows', function () { 38 describe('When adding follows', function () {
49 const path = '/api/v1/server/following' 39 const path = '/api/v1/server/following'
50 40
51 it('Should fail without hosts', async function () { 41 it('Should fail with nothing', async function () {
52 await makePostBodyRequest({ 42 await makePostBodyRequest({
53 url: server.url, 43 url: server.url,
54 path, 44 path,
55 token: server.accessToken, 45 token: server.accessToken,
56 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 46 expectedStatus: HttpStatusCode.BAD_REQUEST_400
57 }) 47 })
58 }) 48 })
59 49
60 it('Should fail if hosts is not an array', async function () { 50 it('Should fail if hosts is not composed by hosts', async function () {
61 await makePostBodyRequest({ 51 await makePostBodyRequest({
62 url: server.url, 52 url: server.url,
63 path, 53 path,
54 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] },
64 token: server.accessToken, 55 token: server.accessToken,
65 fields: { hosts: 'localhost:9002' }, 56 expectedStatus: HttpStatusCode.BAD_REQUEST_400
66 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
67 }) 57 })
68 }) 58 })
69 59
70 it('Should fail if the array is not composed by hosts', async function () { 60 it('Should fail if hosts is composed with http schemes', async function () {
71 await makePostBodyRequest({ 61 await makePostBodyRequest({
72 url: server.url, 62 url: server.url,
73 path, 63 path,
74 fields: { hosts: [ 'localhost:9002', 'localhost:coucou' ] }, 64 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] },
65 token: server.accessToken,
66 expectedStatus: HttpStatusCode.BAD_REQUEST_400
67 })
68 })
69
70 it('Should fail if hosts are not unique', async function () {
71 await makePostBodyRequest({
72 url: server.url,
73 path,
74 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] },
75 token: server.accessToken, 75 token: server.accessToken,
76 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 76 expectedStatus: HttpStatusCode.BAD_REQUEST_400
77 }) 77 })
78 }) 78 })
79 79
80 it('Should fail if the array is composed with http schemes', async function () { 80 it('Should fail if handles is not composed by handles', async function () {
81 await makePostBodyRequest({ 81 await makePostBodyRequest({
82 url: server.url, 82 url: server.url,
83 path, 83 path,
84 fields: { hosts: [ 'localhost:9002', 'http://localhost:9003' ] }, 84 fields: { handles: [ 'hello@example.com', 'localhost:9001' ] },
85 token: server.accessToken, 85 token: server.accessToken,
86 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 86 expectedStatus: HttpStatusCode.BAD_REQUEST_400
87 }) 87 })
88 }) 88 })
89 89
90 it('Should fail if hosts are not unique', async function () { 90 it('Should fail if handles are not unique', async function () {
91 await makePostBodyRequest({ 91 await makePostBodyRequest({
92 url: server.url, 92 url: server.url,
93 path, 93 path,
94 fields: { urls: [ 'localhost:9002', 'localhost:9002' ] }, 94 fields: { urls: [ 'hello@example.com', 'hello@example.com' ] },
95 token: server.accessToken, 95 token: server.accessToken,
96 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 96 expectedStatus: HttpStatusCode.BAD_REQUEST_400
97 }) 97 })
98 }) 98 })
99 99
@@ -103,7 +103,7 @@ describe('Test server follows API validators', function () {
103 path, 103 path,
104 fields: { hosts: [ 'localhost:9002' ] }, 104 fields: { hosts: [ 'localhost:9002' ] },
105 token: 'fake_token', 105 token: 'fake_token',
106 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 106 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
107 }) 107 })
108 }) 108 })
109 109
@@ -113,7 +113,7 @@ describe('Test server follows API validators', function () {
113 path, 113 path,
114 fields: { hosts: [ 'localhost:9002' ] }, 114 fields: { hosts: [ 'localhost:9002' ] },
115 token: userAccessToken, 115 token: userAccessToken,
116 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 116 expectedStatus: HttpStatusCode.FORBIDDEN_403
117 }) 117 })
118 }) 118 })
119 }) 119 })
@@ -157,7 +157,7 @@ describe('Test server follows API validators', function () {
157 await makeGetRequest({ 157 await makeGetRequest({
158 url: server.url, 158 url: server.url,
159 path, 159 path,
160 statusCodeExpected: HttpStatusCode.OK_200, 160 expectedStatus: HttpStatusCode.OK_200,
161 query: { 161 query: {
162 state: 'accepted', 162 state: 'accepted',
163 actorType: 'Application' 163 actorType: 'Application'
@@ -206,7 +206,7 @@ describe('Test server follows API validators', function () {
206 await makeGetRequest({ 206 await makeGetRequest({
207 url: server.url, 207 url: server.url,
208 path, 208 path,
209 statusCodeExpected: HttpStatusCode.OK_200, 209 expectedStatus: HttpStatusCode.OK_200,
210 query: { 210 query: {
211 state: 'accepted' 211 state: 'accepted'
212 } 212 }
@@ -222,7 +222,7 @@ describe('Test server follows API validators', function () {
222 url: server.url, 222 url: server.url,
223 path: path + '/toto@localhost:9002', 223 path: path + '/toto@localhost:9002',
224 token: 'fake_token', 224 token: 'fake_token',
225 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 225 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
226 }) 226 })
227 }) 227 })
228 228
@@ -231,7 +231,7 @@ describe('Test server follows API validators', function () {
231 url: server.url, 231 url: server.url,
232 path: path + '/toto@localhost:9002', 232 path: path + '/toto@localhost:9002',
233 token: userAccessToken, 233 token: userAccessToken,
234 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 234 expectedStatus: HttpStatusCode.FORBIDDEN_403
235 }) 235 })
236 }) 236 })
237 237
@@ -240,7 +240,7 @@ describe('Test server follows API validators', function () {
240 url: server.url, 240 url: server.url,
241 path: path + '/toto', 241 path: path + '/toto',
242 token: server.accessToken, 242 token: server.accessToken,
243 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 243 expectedStatus: HttpStatusCode.BAD_REQUEST_400
244 }) 244 })
245 }) 245 })
246 246
@@ -249,7 +249,7 @@ describe('Test server follows API validators', function () {
249 url: server.url, 249 url: server.url,
250 path: path + '/toto@localhost:9003', 250 path: path + '/toto@localhost:9003',
251 token: server.accessToken, 251 token: server.accessToken,
252 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 252 expectedStatus: HttpStatusCode.NOT_FOUND_404
253 }) 253 })
254 }) 254 })
255 }) 255 })
@@ -262,7 +262,7 @@ describe('Test server follows API validators', function () {
262 url: server.url, 262 url: server.url,
263 path: path + '/toto@localhost:9002/accept', 263 path: path + '/toto@localhost:9002/accept',
264 token: 'fake_token', 264 token: 'fake_token',
265 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 265 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
266 }) 266 })
267 }) 267 })
268 268
@@ -271,7 +271,7 @@ describe('Test server follows API validators', function () {
271 url: server.url, 271 url: server.url,
272 path: path + '/toto@localhost:9002/accept', 272 path: path + '/toto@localhost:9002/accept',
273 token: userAccessToken, 273 token: userAccessToken,
274 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 274 expectedStatus: HttpStatusCode.FORBIDDEN_403
275 }) 275 })
276 }) 276 })
277 277
@@ -280,7 +280,7 @@ describe('Test server follows API validators', function () {
280 url: server.url, 280 url: server.url,
281 path: path + '/toto/accept', 281 path: path + '/toto/accept',
282 token: server.accessToken, 282 token: server.accessToken,
283 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 283 expectedStatus: HttpStatusCode.BAD_REQUEST_400
284 }) 284 })
285 }) 285 })
286 286
@@ -289,7 +289,7 @@ describe('Test server follows API validators', function () {
289 url: server.url, 289 url: server.url,
290 path: path + '/toto@localhost:9003/accept', 290 path: path + '/toto@localhost:9003/accept',
291 token: server.accessToken, 291 token: server.accessToken,
292 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 292 expectedStatus: HttpStatusCode.NOT_FOUND_404
293 }) 293 })
294 }) 294 })
295 }) 295 })
@@ -302,7 +302,7 @@ describe('Test server follows API validators', function () {
302 url: server.url, 302 url: server.url,
303 path: path + '/toto@localhost:9002/reject', 303 path: path + '/toto@localhost:9002/reject',
304 token: 'fake_token', 304 token: 'fake_token',
305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 305 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
306 }) 306 })
307 }) 307 })
308 308
@@ -311,7 +311,7 @@ describe('Test server follows API validators', function () {
311 url: server.url, 311 url: server.url,
312 path: path + '/toto@localhost:9002/reject', 312 path: path + '/toto@localhost:9002/reject',
313 token: userAccessToken, 313 token: userAccessToken,
314 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 314 expectedStatus: HttpStatusCode.FORBIDDEN_403
315 }) 315 })
316 }) 316 })
317 317
@@ -320,7 +320,7 @@ describe('Test server follows API validators', function () {
320 url: server.url, 320 url: server.url,
321 path: path + '/toto/reject', 321 path: path + '/toto/reject',
322 token: server.accessToken, 322 token: server.accessToken,
323 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 323 expectedStatus: HttpStatusCode.BAD_REQUEST_400
324 }) 324 })
325 }) 325 })
326 326
@@ -329,7 +329,7 @@ describe('Test server follows API validators', function () {
329 url: server.url, 329 url: server.url,
330 path: path + '/toto@localhost:9003/reject', 330 path: path + '/toto@localhost:9003/reject',
331 token: server.accessToken, 331 token: server.accessToken,
332 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 332 expectedStatus: HttpStatusCode.NOT_FOUND_404
333 }) 333 })
334 }) 334 })
335 }) 335 })
@@ -342,7 +342,7 @@ describe('Test server follows API validators', function () {
342 url: server.url, 342 url: server.url,
343 path: path + '/localhost:9002', 343 path: path + '/localhost:9002',
344 token: 'fake_token', 344 token: 'fake_token',
345 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 345 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
346 }) 346 })
347 }) 347 })
348 348
@@ -351,7 +351,7 @@ describe('Test server follows API validators', function () {
351 url: server.url, 351 url: server.url,
352 path: path + '/localhost:9002', 352 path: path + '/localhost:9002',
353 token: userAccessToken, 353 token: userAccessToken,
354 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 354 expectedStatus: HttpStatusCode.FORBIDDEN_403
355 }) 355 })
356 }) 356 })
357 357
@@ -360,7 +360,7 @@ describe('Test server follows API validators', function () {
360 url: server.url, 360 url: server.url,
361 path: path + '/example.com', 361 path: path + '/example.com',
362 token: server.accessToken, 362 token: server.accessToken,
363 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 363 expectedStatus: HttpStatusCode.NOT_FOUND_404
364 }) 364 })
365 }) 365 })
366 }) 366 })
diff --git a/server/tests/api/check-params/jobs.ts b/server/tests/api/check-params/jobs.ts
index 3c1d2049b..23d95d8e4 100644
--- a/server/tests/api/check-params/jobs.ts
+++ b/server/tests/api/check-params/jobs.ts
@@ -1,26 +1,21 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import {
6 cleanupTests,
7 createUser,
8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers,
11 userLogin
12} from '../../../../shared/extra-utils'
13import { 4import {
14 checkBadCountPagination, 5 checkBadCountPagination,
15 checkBadSortPagination, 6 checkBadSortPagination,
16 checkBadStartPagination 7 checkBadStartPagination,
17} from '../../../../shared/extra-utils/requests/check-api-params' 8 cleanupTests,
18import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests' 9 createSingleServer,
19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 10 makeGetRequest,
11 PeerTubeServer,
12 setAccessTokensToServers
13} from '@shared/extra-utils'
14import { HttpStatusCode } from '@shared/models'
20 15
21describe('Test jobs API validators', function () { 16describe('Test jobs API validators', function () {
22 const path = '/api/v1/jobs/failed' 17 const path = '/api/v1/jobs/failed'
23 let server: ServerInfo 18 let server: PeerTubeServer
24 let userAccessToken = '' 19 let userAccessToken = ''
25 20
26 // --------------------------------------------------------------- 21 // ---------------------------------------------------------------
@@ -28,7 +23,7 @@ describe('Test jobs API validators', function () {
28 before(async function () { 23 before(async function () {
29 this.timeout(120000) 24 this.timeout(120000)
30 25
31 server = await flushAndRunServer(1) 26 server = await createSingleServer(1)
32 27
33 await setAccessTokensToServers([ server ]) 28 await setAccessTokensToServers([ server ])
34 29
@@ -36,8 +31,8 @@ describe('Test jobs API validators', function () {
36 username: 'user1', 31 username: 'user1',
37 password: 'my super password' 32 password: 'my super password'
38 } 33 }
39 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 34 await server.users.create({ username: user.username, password: user.password })
40 userAccessToken = await userLogin(server, user) 35 userAccessToken = await server.login.getAccessToken(user)
41 }) 36 })
42 37
43 describe('When listing jobs', function () { 38 describe('When listing jobs', function () {
@@ -77,7 +72,7 @@ describe('Test jobs API validators', function () {
77 await makeGetRequest({ 72 await makeGetRequest({
78 url: server.url, 73 url: server.url,
79 path, 74 path,
80 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 75 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
81 }) 76 })
82 }) 77 })
83 78
@@ -86,7 +81,7 @@ describe('Test jobs API validators', function () {
86 url: server.url, 81 url: server.url,
87 path, 82 path,
88 token: userAccessToken, 83 token: userAccessToken,
89 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 84 expectedStatus: HttpStatusCode.FORBIDDEN_403
90 }) 85 })
91 }) 86 })
92 87
diff --git a/server/tests/api/check-params/live.ts b/server/tests/api/check-params/live.ts
index 933d8abf2..700b4724d 100644
--- a/server/tests/api/check-params/live.ts
+++ b/server/tests/api/check-params/live.ts
@@ -2,69 +2,64 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { LiveVideo, VideoCreateResult, VideoPrivacy } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 5import {
8 buildAbsoluteFixturePath, 6 buildAbsoluteFixturePath,
9 cleanupTests, 7 cleanupTests,
10 createUser, 8 createSingleServer,
11 flushAndRunServer, 9 LiveCommand,
12 getLive,
13 getMyUserInformation,
14 immutableAssign,
15 makePostBodyRequest, 10 makePostBodyRequest,
16 makeUploadRequest, 11 makeUploadRequest,
17 runAndTestFfmpegStreamError, 12 PeerTubeServer,
18 sendRTMPStream, 13 sendRTMPStream,
19 ServerInfo,
20 setAccessTokensToServers, 14 setAccessTokensToServers,
21 stopFfmpeg, 15 stopFfmpeg
22 updateCustomSubConfig, 16} from '@shared/extra-utils'
23 updateLive, 17import { HttpStatusCode, VideoCreateResult, VideoPrivacy } from '@shared/models'
24 uploadVideoAndGetId,
25 userLogin,
26 waitUntilLivePublished
27} from '../../../../shared/extra-utils'
28 18
29describe('Test video lives API validator', function () { 19describe('Test video lives API validator', function () {
30 const path = '/api/v1/videos/live' 20 const path = '/api/v1/videos/live'
31 let server: ServerInfo 21 let server: PeerTubeServer
32 let userAccessToken = '' 22 let userAccessToken = ''
33 let channelId: number 23 let channelId: number
34 let video: VideoCreateResult 24 let video: VideoCreateResult
35 let videoIdNotLive: number 25 let videoIdNotLive: number
26 let command: LiveCommand
36 27
37 // --------------------------------------------------------------- 28 // ---------------------------------------------------------------
38 29
39 before(async function () { 30 before(async function () {
40 this.timeout(30000) 31 this.timeout(30000)
41 32
42 server = await flushAndRunServer(1) 33 server = await createSingleServer(1)
43 34
44 await setAccessTokensToServers([ server ]) 35 await setAccessTokensToServers([ server ])
45 36
46 await updateCustomSubConfig(server.url, server.accessToken, { 37 await server.config.updateCustomSubConfig({
47 live: { 38 newConfig: {
48 enabled: true, 39 live: {
49 maxInstanceLives: 20, 40 enabled: true,
50 maxUserLives: 20, 41 maxInstanceLives: 20,
51 allowReplay: true 42 maxUserLives: 20,
43 allowReplay: true
44 }
52 } 45 }
53 }) 46 })
54 47
55 const username = 'user1' 48 const username = 'user1'
56 const password = 'my super password' 49 const password = 'my super password'
57 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 50 await server.users.create({ username: username, password: password })
58 userAccessToken = await userLogin(server, { username, password }) 51 userAccessToken = await server.login.getAccessToken({ username, password })
59 52
60 { 53 {
61 const res = await getMyUserInformation(server.url, server.accessToken) 54 const { videoChannels } = await server.users.getMyInfo()
62 channelId = res.body.videoChannels[0].id 55 channelId = videoChannels[0].id
63 } 56 }
64 57
65 { 58 {
66 videoIdNotLive = (await uploadVideoAndGetId({ server, videoName: 'not live' })).id 59 videoIdNotLive = (await server.videos.quickUpload({ name: 'not live' })).id
67 } 60 }
61
62 command = server.live
68 }) 63 })
69 64
70 describe('When creating a live', function () { 65 describe('When creating a live', function () {
@@ -96,37 +91,37 @@ describe('Test video lives API validator', function () {
96 }) 91 })
97 92
98 it('Should fail with a long name', async function () { 93 it('Should fail with a long name', async function () {
99 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 94 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
100 95
101 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 96 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
102 }) 97 })
103 98
104 it('Should fail with a bad category', async function () { 99 it('Should fail with a bad category', async function () {
105 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 100 const fields = { ...baseCorrectParams, category: 125 }
106 101
107 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 102 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
108 }) 103 })
109 104
110 it('Should fail with a bad licence', async function () { 105 it('Should fail with a bad licence', async function () {
111 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 106 const fields = { ...baseCorrectParams, licence: 125 }
112 107
113 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
114 }) 109 })
115 110
116 it('Should fail with a bad language', async function () { 111 it('Should fail with a bad language', async function () {
117 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 112 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
118 113
119 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
120 }) 115 })
121 116
122 it('Should fail with a long description', async function () { 117 it('Should fail with a long description', async function () {
123 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 118 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
124 119
125 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
126 }) 121 })
127 122
128 it('Should fail with a long support text', async function () { 123 it('Should fail with a long support text', async function () {
129 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 124 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
130 125
131 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
132 }) 127 })
@@ -138,7 +133,7 @@ describe('Test video lives API validator', function () {
138 }) 133 })
139 134
140 it('Should fail with a bad channel', async function () { 135 it('Should fail with a bad channel', async function () {
141 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 136 const fields = { ...baseCorrectParams, channelId: 545454 }
142 137
143 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
144 }) 139 })
@@ -148,31 +143,31 @@ describe('Test video lives API validator', function () {
148 username: 'fake', 143 username: 'fake',
149 password: 'fake_password' 144 password: 'fake_password'
150 } 145 }
151 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 146 await server.users.create({ username: user.username, password: user.password })
152 147
153 const accessTokenUser = await userLogin(server, user) 148 const accessTokenUser = await server.login.getAccessToken(user)
154 const res = await getMyUserInformation(server.url, accessTokenUser) 149 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
155 const customChannelId = res.body.videoChannels[0].id 150 const customChannelId = videoChannels[0].id
156 151
157 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) 152 const fields = { ...baseCorrectParams, channelId: customChannelId }
158 153
159 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 154 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
160 }) 155 })
161 156
162 it('Should fail with too many tags', async function () { 157 it('Should fail with too many tags', async function () {
163 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 158 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
164 159
165 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 160 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
166 }) 161 })
167 162
168 it('Should fail with a tag length too low', async function () { 163 it('Should fail with a tag length too low', async function () {
169 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 164 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
170 165
171 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 166 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
172 }) 167 })
173 168
174 it('Should fail with a tag length too big', async function () { 169 it('Should fail with a tag length too big', async function () {
175 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 170 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
176 171
177 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 172 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
178 }) 173 })
@@ -214,7 +209,7 @@ describe('Test video lives API validator', function () {
214 }) 209 })
215 210
216 it('Should fail with save replay and permanent live set to true', async function () { 211 it('Should fail with save replay and permanent live set to true', async function () {
217 const fields = immutableAssign(baseCorrectParams, { saveReplay: true, permanentLive: true }) 212 const fields = { ...baseCorrectParams, saveReplay: true, permanentLive: true }
218 213
219 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 214 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
220 }) 215 })
@@ -227,16 +222,18 @@ describe('Test video lives API validator', function () {
227 path, 222 path,
228 token: server.accessToken, 223 token: server.accessToken,
229 fields: baseCorrectParams, 224 fields: baseCorrectParams,
230 statusCodeExpected: HttpStatusCode.OK_200 225 expectedStatus: HttpStatusCode.OK_200
231 }) 226 })
232 227
233 video = res.body.video 228 video = res.body.video
234 }) 229 })
235 230
236 it('Should forbid if live is disabled', async function () { 231 it('Should forbid if live is disabled', async function () {
237 await updateCustomSubConfig(server.url, server.accessToken, { 232 await server.config.updateCustomSubConfig({
238 live: { 233 newConfig: {
239 enabled: false 234 live: {
235 enabled: false
236 }
240 } 237 }
241 }) 238 })
242 239
@@ -245,17 +242,19 @@ describe('Test video lives API validator', function () {
245 path, 242 path,
246 token: server.accessToken, 243 token: server.accessToken,
247 fields: baseCorrectParams, 244 fields: baseCorrectParams,
248 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 245 expectedStatus: HttpStatusCode.FORBIDDEN_403
249 }) 246 })
250 }) 247 })
251 248
252 it('Should forbid to save replay if not enabled by the admin', async function () { 249 it('Should forbid to save replay if not enabled by the admin', async function () {
253 const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) 250 const fields = { ...baseCorrectParams, saveReplay: true }
254 251
255 await updateCustomSubConfig(server.url, server.accessToken, { 252 await server.config.updateCustomSubConfig({
256 live: { 253 newConfig: {
257 enabled: true, 254 live: {
258 allowReplay: false 255 enabled: true,
256 allowReplay: false
257 }
259 } 258 }
260 }) 259 })
261 260
@@ -264,17 +263,19 @@ describe('Test video lives API validator', function () {
264 path, 263 path,
265 token: server.accessToken, 264 token: server.accessToken,
266 fields, 265 fields,
267 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 266 expectedStatus: HttpStatusCode.FORBIDDEN_403
268 }) 267 })
269 }) 268 })
270 269
271 it('Should allow to save replay if enabled by the admin', async function () { 270 it('Should allow to save replay if enabled by the admin', async function () {
272 const fields = immutableAssign(baseCorrectParams, { saveReplay: true }) 271 const fields = { ...baseCorrectParams, saveReplay: true }
273 272
274 await updateCustomSubConfig(server.url, server.accessToken, { 273 await server.config.updateCustomSubConfig({
275 live: { 274 newConfig: {
276 enabled: true, 275 live: {
277 allowReplay: true 276 enabled: true,
277 allowReplay: true
278 }
278 } 279 }
279 }) 280 })
280 281
@@ -283,15 +284,17 @@ describe('Test video lives API validator', function () {
283 path, 284 path,
284 token: server.accessToken, 285 token: server.accessToken,
285 fields, 286 fields,
286 statusCodeExpected: HttpStatusCode.OK_200 287 expectedStatus: HttpStatusCode.OK_200
287 }) 288 })
288 }) 289 })
289 290
290 it('Should not allow live if max instance lives is reached', async function () { 291 it('Should not allow live if max instance lives is reached', async function () {
291 await updateCustomSubConfig(server.url, server.accessToken, { 292 await server.config.updateCustomSubConfig({
292 live: { 293 newConfig: {
293 enabled: true, 294 live: {
294 maxInstanceLives: 1 295 enabled: true,
296 maxInstanceLives: 1
297 }
295 } 298 }
296 }) 299 })
297 300
@@ -300,16 +303,18 @@ describe('Test video lives API validator', function () {
300 path, 303 path,
301 token: server.accessToken, 304 token: server.accessToken,
302 fields: baseCorrectParams, 305 fields: baseCorrectParams,
303 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 306 expectedStatus: HttpStatusCode.FORBIDDEN_403
304 }) 307 })
305 }) 308 })
306 309
307 it('Should not allow live if max user lives is reached', async function () { 310 it('Should not allow live if max user lives is reached', async function () {
308 await updateCustomSubConfig(server.url, server.accessToken, { 311 await server.config.updateCustomSubConfig({
309 live: { 312 newConfig: {
310 enabled: true, 313 live: {
311 maxInstanceLives: 20, 314 enabled: true,
312 maxUserLives: 1 315 maxInstanceLives: 20,
316 maxUserLives: 1
317 }
313 } 318 }
314 }) 319 })
315 320
@@ -318,7 +323,7 @@ describe('Test video lives API validator', function () {
318 path, 323 path,
319 token: server.accessToken, 324 token: server.accessToken,
320 fields: baseCorrectParams, 325 fields: baseCorrectParams,
321 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 326 expectedStatus: HttpStatusCode.FORBIDDEN_403
322 }) 327 })
323 }) 328 })
324 }) 329 })
@@ -326,110 +331,112 @@ describe('Test video lives API validator', function () {
326 describe('When getting live information', function () { 331 describe('When getting live information', function () {
327 332
328 it('Should fail without access token', async function () { 333 it('Should fail without access token', async function () {
329 await getLive(server.url, '', video.id, HttpStatusCode.UNAUTHORIZED_401) 334 await command.get({ token: '', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
330 }) 335 })
331 336
332 it('Should fail with a bad access token', async function () { 337 it('Should fail with a bad access token', async function () {
333 await getLive(server.url, 'toto', video.id, HttpStatusCode.UNAUTHORIZED_401) 338 await command.get({ token: 'toto', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
334 }) 339 })
335 340
336 it('Should fail with access token of another user', async function () { 341 it('Should fail with access token of another user', async function () {
337 await getLive(server.url, userAccessToken, video.id, HttpStatusCode.FORBIDDEN_403) 342 await command.get({ token: userAccessToken, videoId: video.id, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
338 }) 343 })
339 344
340 it('Should fail with a bad video id', async function () { 345 it('Should fail with a bad video id', async function () {
341 await getLive(server.url, server.accessToken, 'toto', HttpStatusCode.BAD_REQUEST_400) 346 await command.get({ videoId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
342 }) 347 })
343 348
344 it('Should fail with an unknown video id', async function () { 349 it('Should fail with an unknown video id', async function () {
345 await getLive(server.url, server.accessToken, 454555, HttpStatusCode.NOT_FOUND_404) 350 await command.get({ videoId: 454555, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
346 }) 351 })
347 352
348 it('Should fail with a non live video', async function () { 353 it('Should fail with a non live video', async function () {
349 await getLive(server.url, server.accessToken, videoIdNotLive, HttpStatusCode.NOT_FOUND_404) 354 await command.get({ videoId: videoIdNotLive, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
350 }) 355 })
351 356
352 it('Should succeed with the correct params', async function () { 357 it('Should succeed with the correct params', async function () {
353 await getLive(server.url, server.accessToken, video.id) 358 await command.get({ videoId: video.id })
354 await getLive(server.url, server.accessToken, video.shortUUID) 359 await command.get({ videoId: video.uuid })
360 await command.get({ videoId: video.shortUUID })
355 }) 361 })
356 }) 362 })
357 363
358 describe('When updating live information', async function () { 364 describe('When updating live information', async function () {
359 365
360 it('Should fail without access token', async function () { 366 it('Should fail without access token', async function () {
361 await updateLive(server.url, '', video.id, {}, HttpStatusCode.UNAUTHORIZED_401) 367 await command.update({ token: '', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
362 }) 368 })
363 369
364 it('Should fail with a bad access token', async function () { 370 it('Should fail with a bad access token', async function () {
365 await updateLive(server.url, 'toto', video.id, {}, HttpStatusCode.UNAUTHORIZED_401) 371 await command.update({ token: 'toto', videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
366 }) 372 })
367 373
368 it('Should fail with access token of another user', async function () { 374 it('Should fail with access token of another user', async function () {
369 await updateLive(server.url, userAccessToken, video.id, {}, HttpStatusCode.FORBIDDEN_403) 375 await command.update({ token: userAccessToken, videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
370 }) 376 })
371 377
372 it('Should fail with a bad video id', async function () { 378 it('Should fail with a bad video id', async function () {
373 await updateLive(server.url, server.accessToken, 'toto', {}, HttpStatusCode.BAD_REQUEST_400) 379 await command.update({ videoId: 'toto', fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
374 }) 380 })
375 381
376 it('Should fail with an unknown video id', async function () { 382 it('Should fail with an unknown video id', async function () {
377 await updateLive(server.url, server.accessToken, 454555, {}, HttpStatusCode.NOT_FOUND_404) 383 await command.update({ videoId: 454555, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
378 }) 384 })
379 385
380 it('Should fail with a non live video', async function () { 386 it('Should fail with a non live video', async function () {
381 await updateLive(server.url, server.accessToken, videoIdNotLive, {}, HttpStatusCode.NOT_FOUND_404) 387 await command.update({ videoId: videoIdNotLive, fields: {}, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
382 }) 388 })
383 389
384 it('Should fail with save replay and permanent live set to true', async function () { 390 it('Should fail with save replay and permanent live set to true', async function () {
385 const fields = { saveReplay: true, permanentLive: true } 391 const fields = { saveReplay: true, permanentLive: true }
386 392
387 await updateLive(server.url, server.accessToken, video.id, fields, HttpStatusCode.BAD_REQUEST_400) 393 await command.update({ videoId: video.id, fields, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
388 }) 394 })
389 395
390 it('Should succeed with the correct params', async function () { 396 it('Should succeed with the correct params', async function () {
391 await updateLive(server.url, server.accessToken, video.id, { saveReplay: false }) 397 await command.update({ videoId: video.id, fields: { saveReplay: false } })
392 await updateLive(server.url, server.accessToken, video.shortUUID, { saveReplay: false }) 398 await command.update({ videoId: video.uuid, fields: { saveReplay: false } })
399 await command.update({ videoId: video.shortUUID, fields: { saveReplay: false } })
393 }) 400 })
394 401
395 it('Should fail to update replay status if replay is not allowed on the instance', async function () { 402 it('Should fail to update replay status if replay is not allowed on the instance', async function () {
396 await updateCustomSubConfig(server.url, server.accessToken, { 403 await server.config.updateCustomSubConfig({
397 live: { 404 newConfig: {
398 enabled: true, 405 live: {
399 allowReplay: false 406 enabled: true,
407 allowReplay: false
408 }
400 } 409 }
401 }) 410 })
402 411
403 await updateLive(server.url, server.accessToken, video.id, { saveReplay: true }, HttpStatusCode.FORBIDDEN_403) 412 await command.update({ videoId: video.id, fields: { saveReplay: true }, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
404 }) 413 })
405 414
406 it('Should fail to update a live if it has already started', async function () { 415 it('Should fail to update a live if it has already started', async function () {
407 this.timeout(40000) 416 this.timeout(40000)
408 417
409 const resLive = await getLive(server.url, server.accessToken, video.id) 418 const live = await command.get({ videoId: video.id })
410 const live: LiveVideo = resLive.body
411 419
412 const command = sendRTMPStream(live.rtmpUrl, live.streamKey) 420 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
413 421
414 await waitUntilLivePublished(server.url, server.accessToken, video.id) 422 await command.waitUntilPublished({ videoId: video.id })
415 await updateLive(server.url, server.accessToken, video.id, {}, HttpStatusCode.BAD_REQUEST_400) 423 await command.update({ videoId: video.id, fields: {}, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
416 424
417 await stopFfmpeg(command) 425 await stopFfmpeg(ffmpegCommand)
418 }) 426 })
419 427
420 it('Should fail to stream twice in the save live', async function () { 428 it('Should fail to stream twice in the save live', async function () {
421 this.timeout(40000) 429 this.timeout(40000)
422 430
423 const resLive = await getLive(server.url, server.accessToken, video.id) 431 const live = await command.get({ videoId: video.id })
424 const live: LiveVideo = resLive.body
425 432
426 const command = sendRTMPStream(live.rtmpUrl, live.streamKey) 433 const ffmpegCommand = sendRTMPStream(live.rtmpUrl, live.streamKey)
427 434
428 await waitUntilLivePublished(server.url, server.accessToken, video.id) 435 await command.waitUntilPublished({ videoId: video.id })
429 436
430 await runAndTestFfmpegStreamError(server.url, server.accessToken, video.id, true) 437 await command.runAndTestStreamError({ videoId: video.id, shouldHaveError: true })
431 438
432 await stopFfmpeg(command) 439 await stopFfmpeg(ffmpegCommand)
433 }) 440 })
434 }) 441 })
435 442
diff --git a/server/tests/api/check-params/logs.ts b/server/tests/api/check-params/logs.ts
index dac1e6b98..05372257a 100644
--- a/server/tests/api/check-params/logs.ts
+++ b/server/tests/api/check-params/logs.ts
@@ -1,21 +1,12 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { cleanupTests, createSingleServer, makeGetRequest, PeerTubeServer, setAccessTokensToServers } from '@shared/extra-utils'
5import { 5import { HttpStatusCode } from '@shared/models'
6 cleanupTests,
7 createUser,
8 flushAndRunServer,
9 ServerInfo,
10 setAccessTokensToServers,
11 userLogin
12} from '../../../../shared/extra-utils'
13import { makeGetRequest } from '../../../../shared/extra-utils/requests/requests'
14import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
15 6
16describe('Test logs API validators', function () { 7describe('Test logs API validators', function () {
17 const path = '/api/v1/server/logs' 8 const path = '/api/v1/server/logs'
18 let server: ServerInfo 9 let server: PeerTubeServer
19 let userAccessToken = '' 10 let userAccessToken = ''
20 11
21 // --------------------------------------------------------------- 12 // ---------------------------------------------------------------
@@ -23,7 +14,7 @@ describe('Test logs API validators', function () {
23 before(async function () { 14 before(async function () {
24 this.timeout(120000) 15 this.timeout(120000)
25 16
26 server = await flushAndRunServer(1) 17 server = await createSingleServer(1)
27 18
28 await setAccessTokensToServers([ server ]) 19 await setAccessTokensToServers([ server ])
29 20
@@ -31,8 +22,8 @@ describe('Test logs API validators', function () {
31 username: 'user1', 22 username: 'user1',
32 password: 'my super password' 23 password: 'my super password'
33 } 24 }
34 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 25 await server.users.create({ username: user.username, password: user.password })
35 userAccessToken = await userLogin(server, user) 26 userAccessToken = await server.login.getAccessToken(user)
36 }) 27 })
37 28
38 describe('When getting logs', function () { 29 describe('When getting logs', function () {
@@ -41,7 +32,7 @@ describe('Test logs API validators', function () {
41 await makeGetRequest({ 32 await makeGetRequest({
42 url: server.url, 33 url: server.url,
43 path, 34 path,
44 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 35 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
45 }) 36 })
46 }) 37 })
47 38
@@ -50,7 +41,7 @@ describe('Test logs API validators', function () {
50 url: server.url, 41 url: server.url,
51 path, 42 path,
52 token: userAccessToken, 43 token: userAccessToken,
53 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 44 expectedStatus: HttpStatusCode.FORBIDDEN_403
54 }) 45 })
55 }) 46 })
56 47
@@ -59,7 +50,7 @@ describe('Test logs API validators', function () {
59 url: server.url, 50 url: server.url,
60 path, 51 path,
61 token: server.accessToken, 52 token: server.accessToken,
62 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 53 expectedStatus: HttpStatusCode.BAD_REQUEST_400
63 }) 54 })
64 }) 55 })
65 56
@@ -69,7 +60,7 @@ describe('Test logs API validators', function () {
69 path, 60 path,
70 token: server.accessToken, 61 token: server.accessToken,
71 query: { startDate: 'toto' }, 62 query: { startDate: 'toto' },
72 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 63 expectedStatus: HttpStatusCode.BAD_REQUEST_400
73 }) 64 })
74 }) 65 })
75 66
@@ -79,7 +70,7 @@ describe('Test logs API validators', function () {
79 path, 70 path,
80 token: server.accessToken, 71 token: server.accessToken,
81 query: { startDate: new Date().toISOString(), endDate: 'toto' }, 72 query: { startDate: new Date().toISOString(), endDate: 'toto' },
82 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 73 expectedStatus: HttpStatusCode.BAD_REQUEST_400
83 }) 74 })
84 }) 75 })
85 76
@@ -89,7 +80,7 @@ describe('Test logs API validators', function () {
89 path, 80 path,
90 token: server.accessToken, 81 token: server.accessToken,
91 query: { startDate: new Date().toISOString(), level: 'toto' }, 82 query: { startDate: new Date().toISOString(), level: 'toto' },
92 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 83 expectedStatus: HttpStatusCode.BAD_REQUEST_400
93 }) 84 })
94 }) 85 })
95 86
@@ -99,7 +90,7 @@ describe('Test logs API validators', function () {
99 path, 90 path,
100 token: server.accessToken, 91 token: server.accessToken,
101 query: { startDate: new Date().toISOString() }, 92 query: { startDate: new Date().toISOString() },
102 statusCodeExpected: HttpStatusCode.OK_200 93 expectedStatus: HttpStatusCode.OK_200
103 }) 94 })
104 }) 95 })
105 }) 96 })
diff --git a/server/tests/api/check-params/plugins.ts b/server/tests/api/check-params/plugins.ts
index a833fe6ff..33f84ecbc 100644
--- a/server/tests/api/check-params/plugins.ts
+++ b/server/tests/api/check-params/plugins.ts
@@ -1,27 +1,22 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { HttpStatusCode } from '@shared/core-utils'
5import { 4import {
6 checkBadCountPagination, 5 checkBadCountPagination,
7 checkBadSortPagination, 6 checkBadSortPagination,
8 checkBadStartPagination, 7 checkBadStartPagination,
9 cleanupTests, 8 cleanupTests,
10 createUser, 9 createSingleServer,
11 flushAndRunServer,
12 immutableAssign,
13 installPlugin,
14 makeGetRequest, 10 makeGetRequest,
15 makePostBodyRequest, 11 makePostBodyRequest,
16 makePutBodyRequest, 12 makePutBodyRequest,
17 ServerInfo, 13 PeerTubeServer,
18 setAccessTokensToServers, 14 setAccessTokensToServers
19 userLogin
20} from '@shared/extra-utils' 15} from '@shared/extra-utils'
21import { PeerTubePlugin, PluginType } from '@shared/models' 16import { HttpStatusCode, PeerTubePlugin, PluginType } from '@shared/models'
22 17
23describe('Test server plugins API validators', function () { 18describe('Test server plugins API validators', function () {
24 let server: ServerInfo 19 let server: PeerTubeServer
25 let userAccessToken = null 20 let userAccessToken = null
26 21
27 const npmPlugin = 'peertube-plugin-hello-world' 22 const npmPlugin = 'peertube-plugin-hello-world'
@@ -37,7 +32,7 @@ describe('Test server plugins API validators', function () {
37 before(async function () { 32 before(async function () {
38 this.timeout(30000) 33 this.timeout(30000)
39 34
40 server = await flushAndRunServer(1) 35 server = await createSingleServer(1)
41 36
42 await setAccessTokensToServers([ server ]) 37 await setAccessTokensToServers([ server ])
43 38
@@ -46,17 +41,17 @@ describe('Test server plugins API validators', function () {
46 password: 'password' 41 password: 'password'
47 } 42 }
48 43
49 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 44 await server.users.create({ username: user.username, password: user.password })
50 userAccessToken = await userLogin(server, user) 45 userAccessToken = await server.login.getAccessToken(user)
51 46
52 { 47 {
53 const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: npmPlugin }) 48 const res = await server.plugins.install({ npmName: npmPlugin })
54 const plugin = res.body as PeerTubePlugin 49 const plugin = res.body as PeerTubePlugin
55 npmVersion = plugin.version 50 npmVersion = plugin.version
56 } 51 }
57 52
58 { 53 {
59 const res = await installPlugin({ url: server.url, accessToken: server.accessToken, npmName: themePlugin }) 54 const res = await server.plugins.install({ npmName: themePlugin })
60 const plugin = res.body as PeerTubePlugin 55 const plugin = res.body as PeerTubePlugin
61 themeVersion = plugin.version 56 themeVersion = plugin.version
62 } 57 }
@@ -74,7 +69,7 @@ describe('Test server plugins API validators', function () {
74 ] 69 ]
75 70
76 for (const p of paths) { 71 for (const p of paths) {
77 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 72 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
78 } 73 }
79 }) 74 })
80 75
@@ -82,7 +77,7 @@ describe('Test server plugins API validators', function () {
82 await makeGetRequest({ 77 await makeGetRequest({
83 url: server.url, 78 url: server.url,
84 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png', 79 path: '/themes/' + pluginName + '/' + npmVersion + '/static/images/chocobo.png',
85 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 80 expectedStatus: HttpStatusCode.NOT_FOUND_404
86 }) 81 })
87 }) 82 })
88 83
@@ -97,7 +92,7 @@ describe('Test server plugins API validators', function () {
97 ] 92 ]
98 93
99 for (const p of paths) { 94 for (const p of paths) {
100 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 95 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
101 } 96 }
102 }) 97 })
103 98
@@ -111,14 +106,14 @@ describe('Test server plugins API validators', function () {
111 ] 106 ]
112 107
113 for (const p of paths) { 108 for (const p of paths) {
114 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 109 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
115 } 110 }
116 }) 111 })
117 112
118 it('Should fail with an unknown auth name', async function () { 113 it('Should fail with an unknown auth name', async function () {
119 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth' 114 const path = '/plugins/' + pluginName + '/' + npmVersion + '/auth/bad-auth'
120 115
121 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 116 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
122 }) 117 })
123 118
124 it('Should fail with an unknown static file', async function () { 119 it('Should fail with an unknown static file', async function () {
@@ -130,7 +125,7 @@ describe('Test server plugins API validators', function () {
130 ] 125 ]
131 126
132 for (const p of paths) { 127 for (const p of paths) {
133 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 128 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
134 } 129 }
135 }) 130 })
136 131
@@ -138,7 +133,7 @@ describe('Test server plugins API validators', function () {
138 await makeGetRequest({ 133 await makeGetRequest({
139 url: server.url, 134 url: server.url,
140 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css', 135 path: '/themes/' + themeName + '/' + themeVersion + '/css/assets/fake.css',
141 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 136 expectedStatus: HttpStatusCode.NOT_FOUND_404
142 }) 137 })
143 }) 138 })
144 139
@@ -152,11 +147,11 @@ describe('Test server plugins API validators', function () {
152 ] 147 ]
153 148
154 for (const p of paths) { 149 for (const p of paths) {
155 await makeGetRequest({ url: server.url, path: p, statusCodeExpected: HttpStatusCode.OK_200 }) 150 await makeGetRequest({ url: server.url, path: p, expectedStatus: HttpStatusCode.OK_200 })
156 } 151 }
157 152
158 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth' 153 const authPath = '/plugins/' + pluginName + '/' + npmVersion + '/auth/fake-auth'
159 await makeGetRequest({ url: server.url, path: authPath, statusCodeExpected: HttpStatusCode.FOUND_302 }) 154 await makeGetRequest({ url: server.url, path: authPath, expectedStatus: HttpStatusCode.FOUND_302 })
160 }) 155 })
161 }) 156 })
162 157
@@ -174,7 +169,7 @@ describe('Test server plugins API validators', function () {
174 path, 169 path,
175 token: 'fake_token', 170 token: 'fake_token',
176 query: baseQuery, 171 query: baseQuery,
177 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 172 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
178 }) 173 })
179 }) 174 })
180 175
@@ -184,7 +179,7 @@ describe('Test server plugins API validators', function () {
184 path, 179 path,
185 token: userAccessToken, 180 token: userAccessToken,
186 query: baseQuery, 181 query: baseQuery,
187 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 182 expectedStatus: HttpStatusCode.FORBIDDEN_403
188 }) 183 })
189 }) 184 })
190 185
@@ -201,7 +196,7 @@ describe('Test server plugins API validators', function () {
201 }) 196 })
202 197
203 it('Should fail with an invalid plugin type', async function () { 198 it('Should fail with an invalid plugin type', async function () {
204 const query = immutableAssign(baseQuery, { pluginType: 5 }) 199 const query = { ...baseQuery, pluginType: 5 }
205 200
206 await makeGetRequest({ 201 await makeGetRequest({
207 url: server.url, 202 url: server.url,
@@ -212,7 +207,7 @@ describe('Test server plugins API validators', function () {
212 }) 207 })
213 208
214 it('Should fail with an invalid current peertube engine', async function () { 209 it('Should fail with an invalid current peertube engine', async function () {
215 const query = immutableAssign(baseQuery, { currentPeerTubeEngine: '1.0' }) 210 const query = { ...baseQuery, currentPeerTubeEngine: '1.0' }
216 211
217 await makeGetRequest({ 212 await makeGetRequest({
218 url: server.url, 213 url: server.url,
@@ -228,7 +223,7 @@ describe('Test server plugins API validators', function () {
228 path, 223 path,
229 token: server.accessToken, 224 token: server.accessToken,
230 query: baseQuery, 225 query: baseQuery,
231 statusCodeExpected: HttpStatusCode.OK_200 226 expectedStatus: HttpStatusCode.OK_200
232 }) 227 })
233 }) 228 })
234 }) 229 })
@@ -245,7 +240,7 @@ describe('Test server plugins API validators', function () {
245 path, 240 path,
246 token: 'fake_token', 241 token: 'fake_token',
247 query: baseQuery, 242 query: baseQuery,
248 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 243 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
249 }) 244 })
250 }) 245 })
251 246
@@ -255,7 +250,7 @@ describe('Test server plugins API validators', function () {
255 path, 250 path,
256 token: userAccessToken, 251 token: userAccessToken,
257 query: baseQuery, 252 query: baseQuery,
258 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 253 expectedStatus: HttpStatusCode.FORBIDDEN_403
259 }) 254 })
260 }) 255 })
261 256
@@ -272,7 +267,7 @@ describe('Test server plugins API validators', function () {
272 }) 267 })
273 268
274 it('Should fail with an invalid plugin type', async function () { 269 it('Should fail with an invalid plugin type', async function () {
275 const query = immutableAssign(baseQuery, { pluginType: 5 }) 270 const query = { ...baseQuery, pluginType: 5 }
276 271
277 await makeGetRequest({ 272 await makeGetRequest({
278 url: server.url, 273 url: server.url,
@@ -288,7 +283,7 @@ describe('Test server plugins API validators', function () {
288 path, 283 path,
289 token: server.accessToken, 284 token: server.accessToken,
290 query: baseQuery, 285 query: baseQuery,
291 statusCodeExpected: HttpStatusCode.OK_200 286 expectedStatus: HttpStatusCode.OK_200
292 }) 287 })
293 }) 288 })
294 }) 289 })
@@ -302,7 +297,7 @@ describe('Test server plugins API validators', function () {
302 url: server.url, 297 url: server.url,
303 path: path + suffix, 298 path: path + suffix,
304 token: 'fake_token', 299 token: 'fake_token',
305 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 300 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
306 }) 301 })
307 } 302 }
308 }) 303 })
@@ -313,7 +308,7 @@ describe('Test server plugins API validators', function () {
313 url: server.url, 308 url: server.url,
314 path: path + suffix, 309 path: path + suffix,
315 token: userAccessToken, 310 token: userAccessToken,
316 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 311 expectedStatus: HttpStatusCode.FORBIDDEN_403
317 }) 312 })
318 } 313 }
319 }) 314 })
@@ -324,7 +319,7 @@ describe('Test server plugins API validators', function () {
324 url: server.url, 319 url: server.url,
325 path: path + suffix, 320 path: path + suffix,
326 token: server.accessToken, 321 token: server.accessToken,
327 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 322 expectedStatus: HttpStatusCode.BAD_REQUEST_400
328 }) 323 })
329 } 324 }
330 325
@@ -333,7 +328,7 @@ describe('Test server plugins API validators', function () {
333 url: server.url, 328 url: server.url,
334 path: path + suffix, 329 path: path + suffix,
335 token: server.accessToken, 330 token: server.accessToken,
336 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 331 expectedStatus: HttpStatusCode.BAD_REQUEST_400
337 }) 332 })
338 } 333 }
339 }) 334 })
@@ -344,7 +339,7 @@ describe('Test server plugins API validators', function () {
344 url: server.url, 339 url: server.url,
345 path: path + suffix, 340 path: path + suffix,
346 token: server.accessToken, 341 token: server.accessToken,
347 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 342 expectedStatus: HttpStatusCode.NOT_FOUND_404
348 }) 343 })
349 } 344 }
350 }) 345 })
@@ -355,7 +350,7 @@ describe('Test server plugins API validators', function () {
355 url: server.url, 350 url: server.url,
356 path: path + suffix, 351 path: path + suffix,
357 token: server.accessToken, 352 token: server.accessToken,
358 statusCodeExpected: HttpStatusCode.OK_200 353 expectedStatus: HttpStatusCode.OK_200
359 }) 354 })
360 } 355 }
361 }) 356 })
@@ -371,7 +366,7 @@ describe('Test server plugins API validators', function () {
371 path: path + npmPlugin + '/settings', 366 path: path + npmPlugin + '/settings',
372 fields: { settings }, 367 fields: { settings },
373 token: 'fake_token', 368 token: 'fake_token',
374 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 369 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
375 }) 370 })
376 }) 371 })
377 372
@@ -381,7 +376,7 @@ describe('Test server plugins API validators', function () {
381 path: path + npmPlugin + '/settings', 376 path: path + npmPlugin + '/settings',
382 fields: { settings }, 377 fields: { settings },
383 token: userAccessToken, 378 token: userAccessToken,
384 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 379 expectedStatus: HttpStatusCode.FORBIDDEN_403
385 }) 380 })
386 }) 381 })
387 382
@@ -391,7 +386,7 @@ describe('Test server plugins API validators', function () {
391 path: path + 'toto/settings', 386 path: path + 'toto/settings',
392 fields: { settings }, 387 fields: { settings },
393 token: server.accessToken, 388 token: server.accessToken,
394 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 389 expectedStatus: HttpStatusCode.BAD_REQUEST_400
395 }) 390 })
396 391
397 await makePutBodyRequest({ 392 await makePutBodyRequest({
@@ -399,7 +394,7 @@ describe('Test server plugins API validators', function () {
399 path: path + 'peertube-plugin-TOTO/settings', 394 path: path + 'peertube-plugin-TOTO/settings',
400 fields: { settings }, 395 fields: { settings },
401 token: server.accessToken, 396 token: server.accessToken,
402 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 397 expectedStatus: HttpStatusCode.BAD_REQUEST_400
403 }) 398 })
404 }) 399 })
405 400
@@ -409,7 +404,7 @@ describe('Test server plugins API validators', function () {
409 path: path + 'peertube-plugin-toto/settings', 404 path: path + 'peertube-plugin-toto/settings',
410 fields: { settings }, 405 fields: { settings },
411 token: server.accessToken, 406 token: server.accessToken,
412 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 407 expectedStatus: HttpStatusCode.NOT_FOUND_404
413 }) 408 })
414 }) 409 })
415 410
@@ -419,7 +414,7 @@ describe('Test server plugins API validators', function () {
419 path: path + npmPlugin + '/settings', 414 path: path + npmPlugin + '/settings',
420 fields: { settings }, 415 fields: { settings },
421 token: server.accessToken, 416 token: server.accessToken,
422 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 417 expectedStatus: HttpStatusCode.NO_CONTENT_204
423 }) 418 })
424 }) 419 })
425 }) 420 })
@@ -434,7 +429,7 @@ describe('Test server plugins API validators', function () {
434 path: path + suffix, 429 path: path + suffix,
435 fields: { npmName: npmPlugin }, 430 fields: { npmName: npmPlugin },
436 token: 'fake_token', 431 token: 'fake_token',
437 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 432 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
438 }) 433 })
439 } 434 }
440 }) 435 })
@@ -446,7 +441,7 @@ describe('Test server plugins API validators', function () {
446 path: path + suffix, 441 path: path + suffix,
447 fields: { npmName: npmPlugin }, 442 fields: { npmName: npmPlugin },
448 token: userAccessToken, 443 token: userAccessToken,
449 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 444 expectedStatus: HttpStatusCode.FORBIDDEN_403
450 }) 445 })
451 } 446 }
452 }) 447 })
@@ -458,7 +453,7 @@ describe('Test server plugins API validators', function () {
458 path: path + suffix, 453 path: path + suffix,
459 fields: { npmName: 'toto' }, 454 fields: { npmName: 'toto' },
460 token: server.accessToken, 455 token: server.accessToken,
461 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 456 expectedStatus: HttpStatusCode.BAD_REQUEST_400
462 }) 457 })
463 } 458 }
464 459
@@ -468,7 +463,7 @@ describe('Test server plugins API validators', function () {
468 path: path + suffix, 463 path: path + suffix,
469 fields: { npmName: 'peertube-plugin-TOTO' }, 464 fields: { npmName: 'peertube-plugin-TOTO' },
470 token: server.accessToken, 465 token: server.accessToken,
471 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 466 expectedStatus: HttpStatusCode.BAD_REQUEST_400
472 }) 467 })
473 } 468 }
474 }) 469 })
@@ -488,7 +483,7 @@ describe('Test server plugins API validators', function () {
488 path: path + obj.suffix, 483 path: path + obj.suffix,
489 fields: { npmName: npmPlugin }, 484 fields: { npmName: npmPlugin },
490 token: server.accessToken, 485 token: server.accessToken,
491 statusCodeExpected: obj.status 486 expectedStatus: obj.status
492 }) 487 })
493 } 488 }
494 }) 489 })
diff --git a/server/tests/api/check-params/redundancy.ts b/server/tests/api/check-params/redundancy.ts
index dac6938de..d9f905549 100644
--- a/server/tests/api/check-params/redundancy.ts
+++ b/server/tests/api/check-params/redundancy.ts
@@ -1,30 +1,25 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { VideoCreateResult } from '@shared/models'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 4import {
7 checkBadCountPagination, 5 checkBadCountPagination,
8 checkBadSortPagination, 6 checkBadSortPagination,
9 checkBadStartPagination, 7 checkBadStartPagination,
10 cleanupTests, 8 cleanupTests,
11 createUser, 9 createMultipleServers,
12 doubleFollow, 10 doubleFollow,
13 flushAndRunMultipleServers,
14 getVideo,
15 makeDeleteRequest, 11 makeDeleteRequest,
16 makeGetRequest, 12 makeGetRequest,
17 makePostBodyRequest, 13 makePostBodyRequest,
18 makePutBodyRequest, 14 makePutBodyRequest,
19 ServerInfo, 15 PeerTubeServer,
20 setAccessTokensToServers, 16 setAccessTokensToServers,
21 uploadVideoAndGetId,
22 userLogin,
23 waitJobs 17 waitJobs
24} from '../../../../shared/extra-utils' 18} from '@shared/extra-utils'
19import { HttpStatusCode, VideoCreateResult } from '@shared/models'
25 20
26describe('Test server redundancy API validators', function () { 21describe('Test server redundancy API validators', function () {
27 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
28 let userAccessToken = null 23 let userAccessToken = null
29 let videoIdLocal: number 24 let videoIdLocal: number
30 let videoRemote: VideoCreateResult 25 let videoRemote: VideoCreateResult
@@ -34,7 +29,7 @@ describe('Test server redundancy API validators', function () {
34 before(async function () { 29 before(async function () {
35 this.timeout(80000) 30 this.timeout(80000)
36 31
37 servers = await flushAndRunMultipleServers(2) 32 servers = await createMultipleServers(2)
38 33
39 await setAccessTokensToServers(servers) 34 await setAccessTokensToServers(servers)
40 await doubleFollow(servers[0], servers[1]) 35 await doubleFollow(servers[0], servers[1])
@@ -44,17 +39,16 @@ describe('Test server redundancy API validators', function () {
44 password: 'password' 39 password: 'password'
45 } 40 }
46 41
47 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: user.username, password: user.password }) 42 await servers[0].users.create({ username: user.username, password: user.password })
48 userAccessToken = await userLogin(servers[0], user) 43 userAccessToken = await servers[0].login.getAccessToken(user)
49 44
50 videoIdLocal = (await uploadVideoAndGetId({ server: servers[0], videoName: 'video' })).id 45 videoIdLocal = (await servers[0].videos.quickUpload({ name: 'video' })).id
51 46
52 const remoteUUID = (await uploadVideoAndGetId({ server: servers[1], videoName: 'video' })).uuid 47 const remoteUUID = (await servers[1].videos.quickUpload({ name: 'video' })).uuid
53 48
54 await waitJobs(servers) 49 await waitJobs(servers)
55 50
56 const resVideo = await getVideo(servers[0].url, remoteUUID) 51 videoRemote = await servers[0].videos.get({ id: remoteUUID })
57 videoRemote = resVideo.body
58 }) 52 })
59 53
60 describe('When listing redundancies', function () { 54 describe('When listing redundancies', function () {
@@ -69,11 +63,11 @@ describe('Test server redundancy API validators', function () {
69 }) 63 })
70 64
71 it('Should fail with an invalid token', async function () { 65 it('Should fail with an invalid token', async function () {
72 await makeGetRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 66 await makeGetRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
73 }) 67 })
74 68
75 it('Should fail if the user is not an administrator', async function () { 69 it('Should fail if the user is not an administrator', async function () {
76 await makeGetRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 70 await makeGetRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
77 }) 71 })
78 72
79 it('Should fail with a bad start pagination', async function () { 73 it('Should fail with a bad start pagination', async function () {
@@ -97,7 +91,7 @@ describe('Test server redundancy API validators', function () {
97 }) 91 })
98 92
99 it('Should succeed with the correct params', async function () { 93 it('Should succeed with the correct params', async function () {
100 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, statusCodeExpected: HttpStatusCode.OK_200 }) 94 await makeGetRequest({ url, path, token, query: { target: 'my-videos' }, expectedStatus: HttpStatusCode.OK_200 })
101 }) 95 })
102 }) 96 })
103 97
@@ -113,11 +107,11 @@ describe('Test server redundancy API validators', function () {
113 }) 107 })
114 108
115 it('Should fail with an invalid token', async function () { 109 it('Should fail with an invalid token', async function () {
116 await makePostBodyRequest({ url, path, token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 110 await makePostBodyRequest({ url, path, token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
117 }) 111 })
118 112
119 it('Should fail if the user is not an administrator', async function () { 113 it('Should fail if the user is not an administrator', async function () {
120 await makePostBodyRequest({ url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 114 await makePostBodyRequest({ url, path, token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
121 }) 115 })
122 116
123 it('Should fail without a video id', async function () { 117 it('Should fail without a video id', async function () {
@@ -129,7 +123,7 @@ describe('Test server redundancy API validators', function () {
129 }) 123 })
130 124
131 it('Should fail with a not found video id', async function () { 125 it('Should fail with a not found video id', async function () {
132 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 126 await makePostBodyRequest({ url, path, token, fields: { videoId: 6565 }, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
133 }) 127 })
134 128
135 it('Should fail with a local a video id', async function () { 129 it('Should fail with a local a video id', async function () {
@@ -142,7 +136,7 @@ describe('Test server redundancy API validators', function () {
142 path, 136 path,
143 token, 137 token,
144 fields: { videoId: videoRemote.shortUUID }, 138 fields: { videoId: videoRemote.shortUUID },
145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 139 expectedStatus: HttpStatusCode.NO_CONTENT_204
146 }) 140 })
147 }) 141 })
148 142
@@ -156,7 +150,7 @@ describe('Test server redundancy API validators', function () {
156 path, 150 path,
157 token, 151 token,
158 fields: { videoId: videoRemote.uuid }, 152 fields: { videoId: videoRemote.uuid },
159 statusCodeExpected: HttpStatusCode.CONFLICT_409 153 expectedStatus: HttpStatusCode.CONFLICT_409
160 }) 154 })
161 }) 155 })
162 }) 156 })
@@ -173,11 +167,11 @@ describe('Test server redundancy API validators', function () {
173 }) 167 })
174 168
175 it('Should fail with an invalid token', async function () { 169 it('Should fail with an invalid token', async function () {
176 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 170 await makeDeleteRequest({ url, path: path + '1', token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
177 }) 171 })
178 172
179 it('Should fail if the user is not an administrator', async function () { 173 it('Should fail if the user is not an administrator', async function () {
180 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 174 await makeDeleteRequest({ url, path: path + '1', token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
181 }) 175 })
182 176
183 it('Should fail with an incorrect video id', async function () { 177 it('Should fail with an incorrect video id', async function () {
@@ -185,7 +179,7 @@ describe('Test server redundancy API validators', function () {
185 }) 179 })
186 180
187 it('Should fail with a not found video redundancy', async function () { 181 it('Should fail with a not found video redundancy', async function () {
188 await makeDeleteRequest({ url, path: path + '454545', token, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 182 await makeDeleteRequest({ url, path: path + '454545', token, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
189 }) 183 })
190 }) 184 })
191 185
@@ -198,7 +192,7 @@ describe('Test server redundancy API validators', function () {
198 path: path + '/localhost:' + servers[1].port, 192 path: path + '/localhost:' + servers[1].port,
199 fields: { redundancyAllowed: true }, 193 fields: { redundancyAllowed: true },
200 token: 'fake_token', 194 token: 'fake_token',
201 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 195 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
202 }) 196 })
203 }) 197 })
204 198
@@ -208,7 +202,7 @@ describe('Test server redundancy API validators', function () {
208 path: path + '/localhost:' + servers[1].port, 202 path: path + '/localhost:' + servers[1].port,
209 fields: { redundancyAllowed: true }, 203 fields: { redundancyAllowed: true },
210 token: userAccessToken, 204 token: userAccessToken,
211 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 205 expectedStatus: HttpStatusCode.FORBIDDEN_403
212 }) 206 })
213 }) 207 })
214 208
@@ -218,7 +212,7 @@ describe('Test server redundancy API validators', function () {
218 path: path + '/example.com', 212 path: path + '/example.com',
219 fields: { redundancyAllowed: true }, 213 fields: { redundancyAllowed: true },
220 token: servers[0].accessToken, 214 token: servers[0].accessToken,
221 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 215 expectedStatus: HttpStatusCode.NOT_FOUND_404
222 }) 216 })
223 }) 217 })
224 218
@@ -228,7 +222,7 @@ describe('Test server redundancy API validators', function () {
228 path: path + '/localhost:' + servers[1].port, 222 path: path + '/localhost:' + servers[1].port,
229 fields: { blabla: true }, 223 fields: { blabla: true },
230 token: servers[0].accessToken, 224 token: servers[0].accessToken,
231 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 225 expectedStatus: HttpStatusCode.BAD_REQUEST_400
232 }) 226 })
233 }) 227 })
234 228
@@ -238,7 +232,7 @@ describe('Test server redundancy API validators', function () {
238 path: path + '/localhost:' + servers[1].port, 232 path: path + '/localhost:' + servers[1].port,
239 fields: { redundancyAllowed: true }, 233 fields: { redundancyAllowed: true },
240 token: servers[0].accessToken, 234 token: servers[0].accessToken,
241 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 235 expectedStatus: HttpStatusCode.NO_CONTENT_204
242 }) 236 })
243 }) 237 })
244 }) 238 })
diff --git a/server/tests/api/check-params/search.ts b/server/tests/api/check-params/search.ts
index 20ad46cff..a3da54e1f 100644
--- a/server/tests/api/check-params/search.ts
+++ b/server/tests/api/check-params/search.ts
@@ -2,41 +2,39 @@
2 2
3import 'mocha' 3import 'mocha'
4import { 4import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
5 cleanupTests, 8 cleanupTests,
6 flushAndRunServer, 9 createSingleServer,
7 immutableAssign,
8 makeGetRequest, 10 makeGetRequest,
9 ServerInfo, 11 PeerTubeServer,
10 updateCustomSubConfig,
11 setAccessTokensToServers 12 setAccessTokensToServers
12} from '../../../../shared/extra-utils' 13} from '@shared/extra-utils'
13import { 14import { HttpStatusCode } from '@shared/models'
14 checkBadCountPagination, 15
15 checkBadSortPagination, 16function updateSearchIndex (server: PeerTubeServer, enabled: boolean, disableLocalSearch = false) {
16 checkBadStartPagination 17 return server.config.updateCustomSubConfig({
17} from '../../../../shared/extra-utils/requests/check-api-params' 18 newConfig: {
18import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes' 19 search: {
19 20 searchIndex: {
20function updateSearchIndex (server: ServerInfo, enabled: boolean, disableLocalSearch = false) { 21 enabled,
21 return updateCustomSubConfig(server.url, server.accessToken, { 22 disableLocalSearch
22 search: { 23 }
23 searchIndex: {
24 enabled,
25 disableLocalSearch
26 } 24 }
27 } 25 }
28 }) 26 })
29} 27}
30 28
31describe('Test videos API validator', function () { 29describe('Test videos API validator', function () {
32 let server: ServerInfo 30 let server: PeerTubeServer
33 31
34 // --------------------------------------------------------------- 32 // ---------------------------------------------------------------
35 33
36 before(async function () { 34 before(async function () {
37 this.timeout(30000) 35 this.timeout(30000)
38 36
39 server = await flushAndRunServer(1) 37 server = await createSingleServer(1)
40 await setAccessTokensToServers([ server ]) 38 await setAccessTokensToServers([ server ])
41 }) 39 })
42 40
@@ -60,83 +58,83 @@ describe('Test videos API validator', function () {
60 }) 58 })
61 59
62 it('Should success with the correct parameters', async function () { 60 it('Should success with the correct parameters', async function () {
63 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) 61 await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
64 }) 62 })
65 63
66 it('Should fail with an invalid category', async function () { 64 it('Should fail with an invalid category', async function () {
67 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 'aa', 'b' ] }) 65 const customQuery1 = { ...query, categoryOneOf: [ 'aa', 'b' ] }
68 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 66 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
69 67
70 const customQuery2 = immutableAssign(query, { categoryOneOf: 'a' }) 68 const customQuery2 = { ...query, categoryOneOf: 'a' }
71 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 69 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
72 }) 70 })
73 71
74 it('Should succeed with a valid category', async function () { 72 it('Should succeed with a valid category', async function () {
75 const customQuery1 = immutableAssign(query, { categoryOneOf: [ 1, 7 ] }) 73 const customQuery1 = { ...query, categoryOneOf: [ 1, 7 ] }
76 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 74 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
77 75
78 const customQuery2 = immutableAssign(query, { categoryOneOf: 1 }) 76 const customQuery2 = { ...query, categoryOneOf: 1 }
79 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 77 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
80 }) 78 })
81 79
82 it('Should fail with an invalid licence', async function () { 80 it('Should fail with an invalid licence', async function () {
83 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 'aa', 'b' ] }) 81 const customQuery1 = { ...query, licenceOneOf: [ 'aa', 'b' ] }
84 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 82 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
85 83
86 const customQuery2 = immutableAssign(query, { licenceOneOf: 'a' }) 84 const customQuery2 = { ...query, licenceOneOf: 'a' }
87 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 85 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
88 }) 86 })
89 87
90 it('Should succeed with a valid licence', async function () { 88 it('Should succeed with a valid licence', async function () {
91 const customQuery1 = immutableAssign(query, { licenceOneOf: [ 1, 2 ] }) 89 const customQuery1 = { ...query, licenceOneOf: [ 1, 2 ] }
92 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 90 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
93 91
94 const customQuery2 = immutableAssign(query, { licenceOneOf: 1 }) 92 const customQuery2 = { ...query, licenceOneOf: 1 }
95 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 93 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
96 }) 94 })
97 95
98 it('Should succeed with a valid language', async function () { 96 it('Should succeed with a valid language', async function () {
99 const customQuery1 = immutableAssign(query, { languageOneOf: [ 'fr', 'en' ] }) 97 const customQuery1 = { ...query, languageOneOf: [ 'fr', 'en' ] }
100 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 98 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
101 99
102 const customQuery2 = immutableAssign(query, { languageOneOf: 'fr' }) 100 const customQuery2 = { ...query, languageOneOf: 'fr' }
103 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 101 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
104 }) 102 })
105 103
106 it('Should succeed with valid tags', async function () { 104 it('Should succeed with valid tags', async function () {
107 const customQuery1 = immutableAssign(query, { tagsOneOf: [ 'tag1', 'tag2' ] }) 105 const customQuery1 = { ...query, tagsOneOf: [ 'tag1', 'tag2' ] }
108 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.OK_200 }) 106 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.OK_200 })
109 107
110 const customQuery2 = immutableAssign(query, { tagsOneOf: 'tag1' }) 108 const customQuery2 = { ...query, tagsOneOf: 'tag1' }
111 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.OK_200 }) 109 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.OK_200 })
112 110
113 const customQuery3 = immutableAssign(query, { tagsAllOf: [ 'tag1', 'tag2' ] }) 111 const customQuery3 = { ...query, tagsAllOf: [ 'tag1', 'tag2' ] }
114 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.OK_200 }) 112 await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.OK_200 })
115 113
116 const customQuery4 = immutableAssign(query, { tagsAllOf: 'tag1' }) 114 const customQuery4 = { ...query, tagsAllOf: 'tag1' }
117 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.OK_200 }) 115 await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.OK_200 })
118 }) 116 })
119 117
120 it('Should fail with invalid durations', async function () { 118 it('Should fail with invalid durations', async function () {
121 const customQuery1 = immutableAssign(query, { durationMin: 'hello' }) 119 const customQuery1 = { ...query, durationMin: 'hello' }
122 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 120 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
123 121
124 const customQuery2 = immutableAssign(query, { durationMax: 'hello' }) 122 const customQuery2 = { ...query, durationMax: 'hello' }
125 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 123 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
126 }) 124 })
127 125
128 it('Should fail with invalid dates', async function () { 126 it('Should fail with invalid dates', async function () {
129 const customQuery1 = immutableAssign(query, { startDate: 'hello' }) 127 const customQuery1 = { ...query, startDate: 'hello' }
130 await makeGetRequest({ url: server.url, path, query: customQuery1, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 128 await makeGetRequest({ url: server.url, path, query: customQuery1, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
131 129
132 const customQuery2 = immutableAssign(query, { endDate: 'hello' }) 130 const customQuery2 = { ...query, endDate: 'hello' }
133 await makeGetRequest({ url: server.url, path, query: customQuery2, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 131 await makeGetRequest({ url: server.url, path, query: customQuery2, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
134 132
135 const customQuery3 = immutableAssign(query, { originallyPublishedStartDate: 'hello' }) 133 const customQuery3 = { ...query, originallyPublishedStartDate: 'hello' }
136 await makeGetRequest({ url: server.url, path, query: customQuery3, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 134 await makeGetRequest({ url: server.url, path, query: customQuery3, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
137 135
138 const customQuery4 = immutableAssign(query, { originallyPublishedEndDate: 'hello' }) 136 const customQuery4 = { ...query, originallyPublishedEndDate: 'hello' }
139 await makeGetRequest({ url: server.url, path, query: customQuery4, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 137 await makeGetRequest({ url: server.url, path, query: customQuery4, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
140 }) 138 })
141 }) 139 })
142 140
@@ -160,7 +158,7 @@ describe('Test videos API validator', function () {
160 }) 158 })
161 159
162 it('Should success with the correct parameters', async function () { 160 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) 161 await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
164 }) 162 })
165 }) 163 })
166 164
@@ -184,7 +182,7 @@ describe('Test videos API validator', function () {
184 }) 182 })
185 183
186 it('Should success with the correct parameters', async function () { 184 it('Should success with the correct parameters', async function () {
187 await makeGetRequest({ url: server.url, path, query, statusCodeExpected: HttpStatusCode.OK_200 }) 185 await makeGetRequest({ url: server.url, path, query, expectedStatus: HttpStatusCode.OK_200 })
188 }) 186 })
189 }) 187 })
190 188
@@ -202,42 +200,42 @@ describe('Test videos API validator', function () {
202 200
203 for (const path of paths) { 201 for (const path of paths) {
204 { 202 {
205 const customQuery = immutableAssign(query, { searchTarget: 'hello' }) 203 const customQuery = { ...query, searchTarget: 'hello' }
206 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 204 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
207 } 205 }
208 206
209 { 207 {
210 const customQuery = immutableAssign(query, { searchTarget: undefined }) 208 const customQuery = { ...query, searchTarget: undefined }
211 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 209 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
212 } 210 }
213 211
214 { 212 {
215 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 213 const customQuery = { ...query, searchTarget: 'local' }
216 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 214 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
217 } 215 }
218 216
219 { 217 {
220 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 218 const customQuery = { ...query, searchTarget: 'search-index' }
221 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 219 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
222 } 220 }
223 221
224 await updateSearchIndex(server, true, true) 222 await updateSearchIndex(server, true, true)
225 223
226 { 224 {
227 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 225 const customQuery = { ...query, searchTarget: 'local' }
228 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 }) 226 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
229 } 227 }
230 228
231 { 229 {
232 const customQuery = immutableAssign(query, { searchTarget: 'search-index' }) 230 const customQuery = { ...query, searchTarget: 'search-index' }
233 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 231 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
234 } 232 }
235 233
236 await updateSearchIndex(server, true, false) 234 await updateSearchIndex(server, true, false)
237 235
238 { 236 {
239 const customQuery = immutableAssign(query, { searchTarget: 'local' }) 237 const customQuery = { ...query, searchTarget: 'local' }
240 await makeGetRequest({ url: server.url, path, query: customQuery, statusCodeExpected: HttpStatusCode.OK_200 }) 238 await makeGetRequest({ url: server.url, path, query: customQuery, expectedStatus: HttpStatusCode.OK_200 })
241 } 239 }
242 240
243 await updateSearchIndex(server, false, false) 241 await updateSearchIndex(server, false, false)
diff --git a/server/tests/api/check-params/services.ts b/server/tests/api/check-params/services.ts
index 514e3da70..4c4a5cade 100644
--- a/server/tests/api/check-params/services.ts
+++ b/server/tests/api/check-params/services.ts
@@ -1,22 +1,18 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import { 4import {
6 cleanupTests, 5 cleanupTests,
7 flushAndRunServer, 6 createSingleServer,
8 makeGetRequest, 7 makeGetRequest,
9 ServerInfo, 8 PeerTubeServer,
10 setAccessTokensToServers, 9 setAccessTokensToServers,
11 uploadVideo,
12 createVideoPlaylist,
13 setDefaultVideoChannel 10 setDefaultVideoChannel
14} from '../../../../shared/extra-utils' 11} from '@shared/extra-utils'
15import { VideoPlaylistPrivacy } from '@shared/models' 12import { HttpStatusCode, VideoPlaylistPrivacy } from '@shared/models'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
17 13
18describe('Test services API validators', function () { 14describe('Test services API validators', function () {
19 let server: ServerInfo 15 let server: PeerTubeServer
20 let playlistUUID: string 16 let playlistUUID: string
21 17
22 // --------------------------------------------------------------- 18 // ---------------------------------------------------------------
@@ -24,27 +20,22 @@ describe('Test services API validators', function () {
24 before(async function () { 20 before(async function () {
25 this.timeout(60000) 21 this.timeout(60000)
26 22
27 server = await flushAndRunServer(1) 23 server = await createSingleServer(1)
28 await setAccessTokensToServers([ server ]) 24 await setAccessTokensToServers([ server ])
29 await setDefaultVideoChannel([ server ]) 25 await setDefaultVideoChannel([ server ])
30 26
31 { 27 server.store.video = await server.videos.upload({ attributes: { name: 'my super name' } })
32 const res = await uploadVideo(server.url, server.accessToken, { name: 'my super name' })
33 server.video = res.body.video
34 }
35 28
36 { 29 {
37 const res = await createVideoPlaylist({ 30 const created = await server.playlists.create({
38 url: server.url, 31 attributes: {
39 token: server.accessToken,
40 playlistAttrs: {
41 displayName: 'super playlist', 32 displayName: 'super playlist',
42 privacy: VideoPlaylistPrivacy.PUBLIC, 33 privacy: VideoPlaylistPrivacy.PUBLIC,
43 videoChannelId: server.videoChannel.id 34 videoChannelId: server.store.channel.id
44 } 35 }
45 }) 36 })
46 37
47 playlistUUID = res.body.videoPlaylist.uuid 38 playlistUUID = created.uuid
48 } 39 }
49 }) 40 })
50 41
@@ -56,7 +47,7 @@ describe('Test services API validators', function () {
56 }) 47 })
57 48
58 it('Should fail with an invalid host', async function () { 49 it('Should fail with an invalid host', async function () {
59 const embedUrl = 'http://hello.com/videos/watch/' + server.video.uuid 50 const embedUrl = 'http://hello.com/videos/watch/' + server.store.video.uuid
60 await checkParamEmbed(server, embedUrl) 51 await checkParamEmbed(server, embedUrl)
61 }) 52 })
62 53
@@ -71,37 +62,37 @@ describe('Test services API validators', function () {
71 }) 62 })
72 63
73 it('Should fail with an invalid path', async function () { 64 it('Should fail with an invalid path', async function () {
74 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.video.uuid}` 65 const embedUrl = `http://localhost:${server.port}/videos/watchs/${server.store.video.uuid}`
75 66
76 await checkParamEmbed(server, embedUrl) 67 await checkParamEmbed(server, embedUrl)
77 }) 68 })
78 69
79 it('Should fail with an invalid max height', async function () { 70 it('Should fail with an invalid max height', async function () {
80 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 71 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
81 72
82 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' }) 73 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxheight: 'hello' })
83 }) 74 })
84 75
85 it('Should fail with an invalid max width', async function () { 76 it('Should fail with an invalid max width', async function () {
86 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 77 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
87 78
88 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' }) 79 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { maxwidth: 'hello' })
89 }) 80 })
90 81
91 it('Should fail with an invalid format', async function () { 82 it('Should fail with an invalid format', async function () {
92 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 83 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
93 84
94 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' }) 85 await checkParamEmbed(server, embedUrl, HttpStatusCode.BAD_REQUEST_400, { format: 'blabla' })
95 }) 86 })
96 87
97 it('Should fail with a non supported format', async function () { 88 it('Should fail with a non supported format', async function () {
98 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 89 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
99 90
100 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' }) 91 await checkParamEmbed(server, embedUrl, HttpStatusCode.NOT_IMPLEMENTED_501, { format: 'xml' })
101 }) 92 })
102 93
103 it('Should succeed with the correct params with a video', async function () { 94 it('Should succeed with the correct params with a video', async function () {
104 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.video.uuid}` 95 const embedUrl = `http://localhost:${server.port}/videos/watch/${server.store.video.uuid}`
105 const query = { 96 const query = {
106 format: 'json', 97 format: 'json',
107 maxheight: 400, 98 maxheight: 400,
@@ -128,13 +119,13 @@ describe('Test services API validators', function () {
128 }) 119 })
129}) 120})
130 121
131function checkParamEmbed (server: ServerInfo, embedUrl: string, statusCodeExpected = HttpStatusCode.BAD_REQUEST_400, query = {}) { 122function checkParamEmbed (server: PeerTubeServer, embedUrl: string, expectedStatus = HttpStatusCode.BAD_REQUEST_400, query = {}) {
132 const path = '/services/oembed' 123 const path = '/services/oembed'
133 124
134 return makeGetRequest({ 125 return makeGetRequest({
135 url: server.url, 126 url: server.url,
136 path, 127 path,
137 query: Object.assign(query, { url: embedUrl }), 128 query: Object.assign(query, { url: embedUrl }),
138 statusCodeExpected 129 expectedStatus
139 }) 130 })
140} 131}
diff --git a/server/tests/api/check-params/upload-quota.ts b/server/tests/api/check-params/upload-quota.ts
index d0fbec415..322e93d0d 100644
--- a/server/tests/api/check-params/upload-quota.ts
+++ b/server/tests/api/check-params/upload-quota.ts
@@ -2,46 +2,39 @@
2 2
3import 'mocha' 3import 'mocha'
4import { expect } from 'chai' 4import { expect } from 'chai'
5import { HttpStatusCode, randomInt } from '@shared/core-utils' 5import { randomInt } from '@shared/core-utils'
6import { getGoodVideoUrl, getMagnetURI, getMyVideoImports, importVideo } from '@shared/extra-utils/videos/video-imports'
7import { MyUser, VideoImport, VideoImportState, VideoPrivacy } from '@shared/models'
8import { 6import {
9 cleanupTests, 7 cleanupTests,
10 flushAndRunServer, 8 createSingleServer,
11 getMyUserInformation, 9 FIXTURE_URLS,
12 immutableAssign, 10 PeerTubeServer,
13 registerUser,
14 ServerInfo,
15 setAccessTokensToServers, 11 setAccessTokensToServers,
16 setDefaultVideoChannel, 12 setDefaultVideoChannel,
17 updateUser, 13 VideosCommand,
18 uploadVideo,
19 userLogin,
20 waitJobs 14 waitJobs
21} from '../../../../shared/extra-utils' 15} from '@shared/extra-utils'
16import { HttpStatusCode, VideoImportState, VideoPrivacy } from '@shared/models'
22 17
23describe('Test upload quota', function () { 18describe('Test upload quota', function () {
24 let server: ServerInfo 19 let server: PeerTubeServer
25 let rootId: number 20 let rootId: number
21 let command: VideosCommand
26 22
27 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
28 24
29 before(async function () { 25 before(async function () {
30 this.timeout(30000) 26 this.timeout(30000)
31 27
32 server = await flushAndRunServer(1) 28 server = await createSingleServer(1)
33 await setAccessTokensToServers([ server ]) 29 await setAccessTokensToServers([ server ])
34 await setDefaultVideoChannel([ server ]) 30 await setDefaultVideoChannel([ server ])
35 31
36 const res = await getMyUserInformation(server.url, server.accessToken) 32 const user = await server.users.getMyInfo()
37 rootId = (res.body as MyUser).id 33 rootId = user.id
38 34
39 await updateUser({ 35 await server.users.update({ userId: rootId, videoQuota: 42 })
40 url: server.url, 36
41 userId: rootId, 37 command = server.videos
42 accessToken: server.accessToken,
43 videoQuota: 42
44 })
45 }) 38 })
46 39
47 describe('When having a video quota', function () { 40 describe('When having a video quota', function () {
@@ -50,49 +43,48 @@ describe('Test upload quota', function () {
50 this.timeout(30000) 43 this.timeout(30000)
51 44
52 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 45 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
53 await registerUser(server.url, user.username, user.password) 46 await server.users.register(user)
54 const userAccessToken = await userLogin(server, user) 47 const userToken = await server.login.getAccessToken(user)
55 48
56 const videoAttributes = { fixture: 'video_short2.webm' } 49 const attributes = { fixture: 'video_short2.webm' }
57 for (let i = 0; i < 5; i++) { 50 for (let i = 0; i < 5; i++) {
58 await uploadVideo(server.url, userAccessToken, videoAttributes) 51 await command.upload({ token: userToken, attributes })
59 } 52 }
60 53
61 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 54 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
62 }) 55 })
63 56
64 it('Should fail with a registered user having too many videos with resumable upload', async function () { 57 it('Should fail with a registered user having too many videos with resumable upload', async function () {
65 this.timeout(30000) 58 this.timeout(30000)
66 59
67 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' } 60 const user = { username: 'registered' + randomInt(1, 1500), password: 'password' }
68 await registerUser(server.url, user.username, user.password) 61 await server.users.register(user)
69 const userAccessToken = await userLogin(server, user) 62 const userToken = await server.login.getAccessToken(user)
70 63
71 const videoAttributes = { fixture: 'video_short2.webm' } 64 const attributes = { fixture: 'video_short2.webm' }
72 for (let i = 0; i < 5; i++) { 65 for (let i = 0; i < 5; i++) {
73 await uploadVideo(server.url, userAccessToken, videoAttributes) 66 await command.upload({ token: userToken, attributes })
74 } 67 }
75 68
76 await uploadVideo(server.url, userAccessToken, videoAttributes, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 69 await command.upload({ token: userToken, attributes, expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
77 }) 70 })
78 71
79 it('Should fail to import with HTTP/Torrent/magnet', async function () { 72 it('Should fail to import with HTTP/Torrent/magnet', async function () {
80 this.timeout(120000) 73 this.timeout(120000)
81 74
82 const baseAttributes = { 75 const baseAttributes = {
83 channelId: server.videoChannel.id, 76 channelId: server.store.channel.id,
84 privacy: VideoPrivacy.PUBLIC 77 privacy: VideoPrivacy.PUBLIC
85 } 78 }
86 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { targetUrl: getGoodVideoUrl() })) 79 await server.imports.importVideo({ attributes: { ...baseAttributes, targetUrl: FIXTURE_URLS.goodVideo } })
87 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { magnetUri: getMagnetURI() })) 80 await server.imports.importVideo({ attributes: { ...baseAttributes, magnetUri: FIXTURE_URLS.magnet } })
88 await importVideo(server.url, server.accessToken, immutableAssign(baseAttributes, { torrentfile: 'video-720p.torrent' as any })) 81 await server.imports.importVideo({ attributes: { ...baseAttributes, torrentfile: 'video-720p.torrent' as any } })
89 82
90 await waitJobs([ server ]) 83 await waitJobs([ server ])
91 84
92 const res = await getMyVideoImports(server.url, server.accessToken) 85 const { total, data: videoImports } = await server.imports.getMyVideoImports()
86 expect(total).to.equal(3)
93 87
94 expect(res.body.total).to.equal(3)
95 const videoImports: VideoImport[] = res.body.data
96 expect(videoImports).to.have.lengthOf(3) 88 expect(videoImports).to.have.lengthOf(3)
97 89
98 for (const videoImport of videoImports) { 90 for (const videoImport of videoImports) {
@@ -106,43 +98,34 @@ describe('Test upload quota', function () {
106 describe('When having a daily video quota', function () { 98 describe('When having a daily video quota', function () {
107 99
108 it('Should fail with a user having too many videos daily', async function () { 100 it('Should fail with a user having too many videos daily', async function () {
109 await updateUser({ 101 await server.users.update({ userId: rootId, videoQuotaDaily: 42 })
110 url: server.url,
111 userId: rootId,
112 accessToken: server.accessToken,
113 videoQuotaDaily: 42
114 })
115 102
116 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 103 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
117 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 104 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
118 }) 105 })
119 }) 106 })
120 107
121 describe('When having an absolute and daily video quota', function () { 108 describe('When having an absolute and daily video quota', function () {
122 it('Should fail if exceeding total quota', async function () { 109 it('Should fail if exceeding total quota', async function () {
123 await updateUser({ 110 await server.users.update({
124 url: server.url,
125 userId: rootId, 111 userId: rootId,
126 accessToken: server.accessToken,
127 videoQuota: 42, 112 videoQuota: 42,
128 videoQuotaDaily: 1024 * 1024 * 1024 113 videoQuotaDaily: 1024 * 1024 * 1024
129 }) 114 })
130 115
131 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 116 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
132 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 117 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
133 }) 118 })
134 119
135 it('Should fail if exceeding daily quota', async function () { 120 it('Should fail if exceeding daily quota', async function () {
136 await updateUser({ 121 await server.users.update({
137 url: server.url,
138 userId: rootId, 122 userId: rootId,
139 accessToken: server.accessToken,
140 videoQuota: 1024 * 1024 * 1024, 123 videoQuota: 1024 * 1024 * 1024,
141 videoQuotaDaily: 42 124 videoQuotaDaily: 42
142 }) 125 })
143 126
144 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'legacy') 127 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'legacy' })
145 await uploadVideo(server.url, server.accessToken, {}, HttpStatusCode.PAYLOAD_TOO_LARGE_413, 'resumable') 128 await command.upload({ expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413, mode: 'resumable' })
146 }) 129 })
147 }) 130 })
148 131
diff --git a/server/tests/api/check-params/user-notifications.ts b/server/tests/api/check-params/user-notifications.ts
index 26d4423f9..17edf5aa1 100644
--- a/server/tests/api/check-params/user-notifications.ts
+++ b/server/tests/api/check-params/user-notifications.ts
@@ -2,35 +2,30 @@
2 2
3import 'mocha' 3import 'mocha'
4import { io } from 'socket.io-client' 4import { io } from 'socket.io-client'
5
6import { 5import {
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
7 cleanupTests, 9 cleanupTests,
8 flushAndRunServer, 10 createSingleServer,
9 immutableAssign,
10 makeGetRequest, 11 makeGetRequest,
11 makePostBodyRequest, 12 makePostBodyRequest,
12 makePutBodyRequest, 13 makePutBodyRequest,
13 ServerInfo, 14 PeerTubeServer,
14 setAccessTokensToServers, 15 setAccessTokensToServers,
15 wait 16 wait
16} from '../../../../shared/extra-utils' 17} from '@shared/extra-utils'
17import { 18import { HttpStatusCode, UserNotificationSetting, UserNotificationSettingValue } from '@shared/models'
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { UserNotificationSetting, UserNotificationSettingValue } from '../../../../shared/models/users'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 19
25describe('Test user notifications API validators', function () { 20describe('Test user notifications API validators', function () {
26 let server: ServerInfo 21 let server: PeerTubeServer
27 22
28 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
29 24
30 before(async function () { 25 before(async function () {
31 this.timeout(30000) 26 this.timeout(30000)
32 27
33 server = await flushAndRunServer(1) 28 server = await createSingleServer(1)
34 29
35 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
36 }) 31 })
@@ -58,7 +53,7 @@ describe('Test user notifications API validators', function () {
58 unread: 'toto' 53 unread: 'toto'
59 }, 54 },
60 token: server.accessToken, 55 token: server.accessToken,
61 statusCodeExpected: HttpStatusCode.OK_200 56 expectedStatus: HttpStatusCode.OK_200
62 }) 57 })
63 }) 58 })
64 59
@@ -66,7 +61,7 @@ describe('Test user notifications API validators', function () {
66 await makeGetRequest({ 61 await makeGetRequest({
67 url: server.url, 62 url: server.url,
68 path, 63 path,
69 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 64 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
70 }) 65 })
71 }) 66 })
72 67
@@ -75,7 +70,7 @@ describe('Test user notifications API validators', function () {
75 url: server.url, 70 url: server.url,
76 path, 71 path,
77 token: server.accessToken, 72 token: server.accessToken,
78 statusCodeExpected: HttpStatusCode.OK_200 73 expectedStatus: HttpStatusCode.OK_200
79 }) 74 })
80 }) 75 })
81 }) 76 })
@@ -91,7 +86,7 @@ describe('Test user notifications API validators', function () {
91 ids: [ 'hello' ] 86 ids: [ 'hello' ]
92 }, 87 },
93 token: server.accessToken, 88 token: server.accessToken,
94 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 89 expectedStatus: HttpStatusCode.BAD_REQUEST_400
95 }) 90 })
96 91
97 await makePostBodyRequest({ 92 await makePostBodyRequest({
@@ -101,7 +96,7 @@ describe('Test user notifications API validators', function () {
101 ids: [ ] 96 ids: [ ]
102 }, 97 },
103 token: server.accessToken, 98 token: server.accessToken,
104 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 99 expectedStatus: HttpStatusCode.BAD_REQUEST_400
105 }) 100 })
106 101
107 await makePostBodyRequest({ 102 await makePostBodyRequest({
@@ -111,7 +106,7 @@ describe('Test user notifications API validators', function () {
111 ids: 5 106 ids: 5
112 }, 107 },
113 token: server.accessToken, 108 token: server.accessToken,
114 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 109 expectedStatus: HttpStatusCode.BAD_REQUEST_400
115 }) 110 })
116 }) 111 })
117 112
@@ -122,7 +117,7 @@ describe('Test user notifications API validators', function () {
122 fields: { 117 fields: {
123 ids: [ 5 ] 118 ids: [ 5 ]
124 }, 119 },
125 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 120 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
126 }) 121 })
127 }) 122 })
128 123
@@ -134,7 +129,7 @@ describe('Test user notifications API validators', function () {
134 ids: [ 5 ] 129 ids: [ 5 ]
135 }, 130 },
136 token: server.accessToken, 131 token: server.accessToken,
137 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 132 expectedStatus: HttpStatusCode.NO_CONTENT_204
138 }) 133 })
139 }) 134 })
140 }) 135 })
@@ -146,7 +141,7 @@ describe('Test user notifications API validators', function () {
146 await makePostBodyRequest({ 141 await makePostBodyRequest({
147 url: server.url, 142 url: server.url,
148 path, 143 path,
149 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 144 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
150 }) 145 })
151 }) 146 })
152 147
@@ -155,7 +150,7 @@ describe('Test user notifications API validators', function () {
155 url: server.url, 150 url: server.url,
156 path, 151 path,
157 token: server.accessToken, 152 token: server.accessToken,
158 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 153 expectedStatus: HttpStatusCode.NO_CONTENT_204
159 }) 154 })
160 }) 155 })
161 }) 156 })
@@ -187,32 +182,32 @@ describe('Test user notifications API validators', function () {
187 path, 182 path,
188 token: server.accessToken, 183 token: server.accessToken,
189 fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB }, 184 fields: { newVideoFromSubscription: UserNotificationSettingValue.WEB },
190 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 185 expectedStatus: HttpStatusCode.BAD_REQUEST_400
191 }) 186 })
192 }) 187 })
193 188
194 it('Should fail with incorrect field values', async function () { 189 it('Should fail with incorrect field values', async function () {
195 { 190 {
196 const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 15 }) 191 const fields = { ...correctFields, newCommentOnMyVideo: 15 }
197 192
198 await makePutBodyRequest({ 193 await makePutBodyRequest({
199 url: server.url, 194 url: server.url,
200 path, 195 path,
201 token: server.accessToken, 196 token: server.accessToken,
202 fields, 197 fields,
203 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 198 expectedStatus: HttpStatusCode.BAD_REQUEST_400
204 }) 199 })
205 } 200 }
206 201
207 { 202 {
208 const fields = immutableAssign(correctFields, { newCommentOnMyVideo: 'toto' }) 203 const fields = { ...correctFields, newCommentOnMyVideo: 'toto' }
209 204
210 await makePutBodyRequest({ 205 await makePutBodyRequest({
211 url: server.url, 206 url: server.url,
212 path, 207 path,
213 fields, 208 fields,
214 token: server.accessToken, 209 token: server.accessToken,
215 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 210 expectedStatus: HttpStatusCode.BAD_REQUEST_400
216 }) 211 })
217 } 212 }
218 }) 213 })
@@ -222,7 +217,7 @@ describe('Test user notifications API validators', function () {
222 url: server.url, 217 url: server.url,
223 path, 218 path,
224 fields: correctFields, 219 fields: correctFields,
225 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 220 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
226 }) 221 })
227 }) 222 })
228 223
@@ -232,7 +227,7 @@ describe('Test user notifications API validators', function () {
232 path, 227 path,
233 token: server.accessToken, 228 token: server.accessToken,
234 fields: correctFields, 229 fields: correctFields,
235 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 230 expectedStatus: HttpStatusCode.NO_CONTENT_204
236 }) 231 })
237 }) 232 })
238 }) 233 })
diff --git a/server/tests/api/check-params/user-subscriptions.ts b/server/tests/api/check-params/user-subscriptions.ts
index 538201647..624069c80 100644
--- a/server/tests/api/check-params/user-subscriptions.ts
+++ b/server/tests/api/check-params/user-subscriptions.ts
@@ -1,30 +1,24 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4
5import { 4import {
5 checkBadCountPagination,
6 checkBadSortPagination,
7 checkBadStartPagination,
6 cleanupTests, 8 cleanupTests,
7 createUser, 9 createSingleServer,
8 flushAndRunServer,
9 makeDeleteRequest, 10 makeDeleteRequest,
10 makeGetRequest, 11 makeGetRequest,
11 makePostBodyRequest, 12 makePostBodyRequest,
12 ServerInfo, 13 PeerTubeServer,
13 setAccessTokensToServers, 14 setAccessTokensToServers,
14 userLogin 15 waitJobs
15} from '../../../../shared/extra-utils' 16} from '@shared/extra-utils'
16 17import { HttpStatusCode } from '@shared/models'
17import {
18 checkBadCountPagination,
19 checkBadSortPagination,
20 checkBadStartPagination
21} from '../../../../shared/extra-utils/requests/check-api-params'
22import { waitJobs } from '../../../../shared/extra-utils/server/jobs'
23import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
24 18
25describe('Test user subscriptions API validators', function () { 19describe('Test user subscriptions API validators', function () {
26 const path = '/api/v1/users/me/subscriptions' 20 const path = '/api/v1/users/me/subscriptions'
27 let server: ServerInfo 21 let server: PeerTubeServer
28 let userAccessToken = '' 22 let userAccessToken = ''
29 23
30 // --------------------------------------------------------------- 24 // ---------------------------------------------------------------
@@ -32,7 +26,7 @@ describe('Test user subscriptions API validators', function () {
32 before(async function () { 26 before(async function () {
33 this.timeout(30000) 27 this.timeout(30000)
34 28
35 server = await flushAndRunServer(1) 29 server = await createSingleServer(1)
36 30
37 await setAccessTokensToServers([ server ]) 31 await setAccessTokensToServers([ server ])
38 32
@@ -40,8 +34,8 @@ describe('Test user subscriptions API validators', function () {
40 username: 'user1', 34 username: 'user1',
41 password: 'my super password' 35 password: 'my super password'
42 } 36 }
43 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 37 await server.users.create({ username: user.username, password: user.password })
44 userAccessToken = await userLogin(server, user) 38 userAccessToken = await server.login.getAccessToken(user)
45 }) 39 })
46 40
47 describe('When listing my subscriptions', function () { 41 describe('When listing my subscriptions', function () {
@@ -61,7 +55,7 @@ describe('Test user subscriptions API validators', function () {
61 await makeGetRequest({ 55 await makeGetRequest({
62 url: server.url, 56 url: server.url,
63 path, 57 path,
64 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 58 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
65 }) 59 })
66 }) 60 })
67 61
@@ -70,7 +64,7 @@ describe('Test user subscriptions API validators', function () {
70 url: server.url, 64 url: server.url,
71 path, 65 path,
72 token: userAccessToken, 66 token: userAccessToken,
73 statusCodeExpected: HttpStatusCode.OK_200 67 expectedStatus: HttpStatusCode.OK_200
74 }) 68 })
75 }) 69 })
76 }) 70 })
@@ -94,7 +88,7 @@ describe('Test user subscriptions API validators', function () {
94 await makeGetRequest({ 88 await makeGetRequest({
95 url: server.url, 89 url: server.url,
96 path, 90 path,
97 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
98 }) 92 })
99 }) 93 })
100 94
@@ -103,7 +97,7 @@ describe('Test user subscriptions API validators', function () {
103 url: server.url, 97 url: server.url,
104 path, 98 path,
105 token: userAccessToken, 99 token: userAccessToken,
106 statusCodeExpected: HttpStatusCode.OK_200 100 expectedStatus: HttpStatusCode.OK_200
107 }) 101 })
108 }) 102 })
109 }) 103 })
@@ -114,7 +108,7 @@ describe('Test user subscriptions API validators', function () {
114 url: server.url, 108 url: server.url,
115 path, 109 path,
116 fields: { uri: 'user1_channel@localhost:' + server.port }, 110 fields: { uri: 'user1_channel@localhost:' + server.port },
117 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 111 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
118 }) 112 })
119 }) 113 })
120 114
@@ -124,7 +118,7 @@ describe('Test user subscriptions API validators', function () {
124 path, 118 path,
125 token: server.accessToken, 119 token: server.accessToken,
126 fields: { uri: 'root' }, 120 fields: { uri: 'root' },
127 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 121 expectedStatus: HttpStatusCode.BAD_REQUEST_400
128 }) 122 })
129 123
130 await makePostBodyRequest({ 124 await makePostBodyRequest({
@@ -132,7 +126,7 @@ describe('Test user subscriptions API validators', function () {
132 path, 126 path,
133 token: server.accessToken, 127 token: server.accessToken,
134 fields: { uri: 'root@' }, 128 fields: { uri: 'root@' },
135 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 129 expectedStatus: HttpStatusCode.BAD_REQUEST_400
136 }) 130 })
137 131
138 await makePostBodyRequest({ 132 await makePostBodyRequest({
@@ -140,7 +134,7 @@ describe('Test user subscriptions API validators', function () {
140 path, 134 path,
141 token: server.accessToken, 135 token: server.accessToken,
142 fields: { uri: 'root@hello@' }, 136 fields: { uri: 'root@hello@' },
143 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 137 expectedStatus: HttpStatusCode.BAD_REQUEST_400
144 }) 138 })
145 }) 139 })
146 140
@@ -152,7 +146,7 @@ describe('Test user subscriptions API validators', function () {
152 path, 146 path,
153 token: server.accessToken, 147 token: server.accessToken,
154 fields: { uri: 'user1_channel@localhost:' + server.port }, 148 fields: { uri: 'user1_channel@localhost:' + server.port },
155 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 149 expectedStatus: HttpStatusCode.NO_CONTENT_204
156 }) 150 })
157 151
158 await waitJobs([ server ]) 152 await waitJobs([ server ])
@@ -164,7 +158,7 @@ describe('Test user subscriptions API validators', function () {
164 await makeGetRequest({ 158 await makeGetRequest({
165 url: server.url, 159 url: server.url,
166 path: path + '/user1_channel@localhost:' + server.port, 160 path: path + '/user1_channel@localhost:' + server.port,
167 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 161 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
168 }) 162 })
169 }) 163 })
170 164
@@ -173,21 +167,21 @@ describe('Test user subscriptions API validators', function () {
173 url: server.url, 167 url: server.url,
174 path: path + '/root', 168 path: path + '/root',
175 token: server.accessToken, 169 token: server.accessToken,
176 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 170 expectedStatus: HttpStatusCode.BAD_REQUEST_400
177 }) 171 })
178 172
179 await makeGetRequest({ 173 await makeGetRequest({
180 url: server.url, 174 url: server.url,
181 path: path + '/root@', 175 path: path + '/root@',
182 token: server.accessToken, 176 token: server.accessToken,
183 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 177 expectedStatus: HttpStatusCode.BAD_REQUEST_400
184 }) 178 })
185 179
186 await makeGetRequest({ 180 await makeGetRequest({
187 url: server.url, 181 url: server.url,
188 path: path + '/root@hello@', 182 path: path + '/root@hello@',
189 token: server.accessToken, 183 token: server.accessToken,
190 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 184 expectedStatus: HttpStatusCode.BAD_REQUEST_400
191 }) 185 })
192 }) 186 })
193 187
@@ -196,7 +190,7 @@ describe('Test user subscriptions API validators', function () {
196 url: server.url, 190 url: server.url,
197 path: path + '/root1@localhost:' + server.port, 191 path: path + '/root1@localhost:' + server.port,
198 token: server.accessToken, 192 token: server.accessToken,
199 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 193 expectedStatus: HttpStatusCode.NOT_FOUND_404
200 }) 194 })
201 }) 195 })
202 196
@@ -205,7 +199,7 @@ describe('Test user subscriptions API validators', function () {
205 url: server.url, 199 url: server.url,
206 path: path + '/user1_channel@localhost:' + server.port, 200 path: path + '/user1_channel@localhost:' + server.port,
207 token: server.accessToken, 201 token: server.accessToken,
208 statusCodeExpected: HttpStatusCode.OK_200 202 expectedStatus: HttpStatusCode.OK_200
209 }) 203 })
210 }) 204 })
211 }) 205 })
@@ -217,7 +211,7 @@ describe('Test user subscriptions API validators', function () {
217 await makeGetRequest({ 211 await makeGetRequest({
218 url: server.url, 212 url: server.url,
219 path: existPath, 213 path: existPath,
220 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 214 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
221 }) 215 })
222 }) 216 })
223 217
@@ -227,7 +221,7 @@ describe('Test user subscriptions API validators', function () {
227 path: existPath, 221 path: existPath,
228 query: { uris: 'toto' }, 222 query: { uris: 'toto' },
229 token: server.accessToken, 223 token: server.accessToken,
230 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 224 expectedStatus: HttpStatusCode.BAD_REQUEST_400
231 }) 225 })
232 226
233 await makeGetRequest({ 227 await makeGetRequest({
@@ -235,7 +229,7 @@ describe('Test user subscriptions API validators', function () {
235 path: existPath, 229 path: existPath,
236 query: { 'uris[]': 1 }, 230 query: { 'uris[]': 1 },
237 token: server.accessToken, 231 token: server.accessToken,
238 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 232 expectedStatus: HttpStatusCode.BAD_REQUEST_400
239 }) 233 })
240 }) 234 })
241 235
@@ -245,7 +239,7 @@ describe('Test user subscriptions API validators', function () {
245 path: existPath, 239 path: existPath,
246 query: { 'uris[]': 'coucou@localhost:' + server.port }, 240 query: { 'uris[]': 'coucou@localhost:' + server.port },
247 token: server.accessToken, 241 token: server.accessToken,
248 statusCodeExpected: HttpStatusCode.OK_200 242 expectedStatus: HttpStatusCode.OK_200
249 }) 243 })
250 }) 244 })
251 }) 245 })
@@ -255,7 +249,7 @@ describe('Test user subscriptions API validators', function () {
255 await makeDeleteRequest({ 249 await makeDeleteRequest({
256 url: server.url, 250 url: server.url,
257 path: path + '/user1_channel@localhost:' + server.port, 251 path: path + '/user1_channel@localhost:' + server.port,
258 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 252 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
259 }) 253 })
260 }) 254 })
261 255
@@ -264,21 +258,21 @@ describe('Test user subscriptions API validators', function () {
264 url: server.url, 258 url: server.url,
265 path: path + '/root', 259 path: path + '/root',
266 token: server.accessToken, 260 token: server.accessToken,
267 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 261 expectedStatus: HttpStatusCode.BAD_REQUEST_400
268 }) 262 })
269 263
270 await makeDeleteRequest({ 264 await makeDeleteRequest({
271 url: server.url, 265 url: server.url,
272 path: path + '/root@', 266 path: path + '/root@',
273 token: server.accessToken, 267 token: server.accessToken,
274 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 268 expectedStatus: HttpStatusCode.BAD_REQUEST_400
275 }) 269 })
276 270
277 await makeDeleteRequest({ 271 await makeDeleteRequest({
278 url: server.url, 272 url: server.url,
279 path: path + '/root@hello@', 273 path: path + '/root@hello@',
280 token: server.accessToken, 274 token: server.accessToken,
281 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 275 expectedStatus: HttpStatusCode.BAD_REQUEST_400
282 }) 276 })
283 }) 277 })
284 278
@@ -287,7 +281,7 @@ describe('Test user subscriptions API validators', function () {
287 url: server.url, 281 url: server.url,
288 path: path + '/root1@localhost:' + server.port, 282 path: path + '/root1@localhost:' + server.port,
289 token: server.accessToken, 283 token: server.accessToken,
290 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 284 expectedStatus: HttpStatusCode.NOT_FOUND_404
291 }) 285 })
292 }) 286 })
293 287
@@ -296,7 +290,7 @@ describe('Test user subscriptions API validators', function () {
296 url: server.url, 290 url: server.url,
297 path: path + '/user1_channel@localhost:' + server.port, 291 path: path + '/user1_channel@localhost:' + server.port,
298 token: server.accessToken, 292 token: server.accessToken,
299 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 293 expectedStatus: HttpStatusCode.NO_CONTENT_204
300 }) 294 })
301 }) 295 })
302 }) 296 })
diff --git a/server/tests/api/check-params/users.ts b/server/tests/api/check-params/users.ts
index 70a872ce5..9d8f933db 100644
--- a/server/tests/api/check-params/users.ts
+++ b/server/tests/api/check-params/users.ts
@@ -2,43 +2,24 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { User, UserRole, VideoCreateResult } from '../../../../shared'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 5import {
8 addVideoChannel,
9 blockUser,
10 buildAbsoluteFixturePath, 6 buildAbsoluteFixturePath,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
11 cleanupTests, 10 cleanupTests,
12 createUser, 11 createSingleServer,
13 deleteMe,
14 flushAndRunServer,
15 getMyUserInformation,
16 getMyUserVideoRating,
17 getUserScopedTokens,
18 getUsersList,
19 immutableAssign,
20 killallServers, 12 killallServers,
21 makeGetRequest, 13 makeGetRequest,
22 makePostBodyRequest, 14 makePostBodyRequest,
23 makePutBodyRequest, 15 makePutBodyRequest,
24 makeUploadRequest, 16 makeUploadRequest,
25 registerUser, 17 MockSmtpServer,
26 removeUser, 18 PeerTubeServer,
27 renewUserScopedTokens,
28 reRunServer,
29 ServerInfo,
30 setAccessTokensToServers, 19 setAccessTokensToServers,
31 unblockUser, 20 UsersCommand
32 uploadVideo, 21} from '@shared/extra-utils'
33 userLogin 22import { HttpStatusCode, UserAdminFlag, UserRole, VideoCreateResult } from '@shared/models'
34} from '../../../../shared/extra-utils'
35import { MockSmtpServer } from '../../../../shared/extra-utils/miscs/email'
36import {
37 checkBadCountPagination,
38 checkBadSortPagination,
39 checkBadStartPagination
40} from '../../../../shared/extra-utils/requests/check-api-params'
41import { UserAdminFlag } from '../../../../shared/models/users/user-flag.model'
42 23
43describe('Test users API validators', function () { 24describe('Test users API validators', function () {
44 const path = '/api/v1/users/' 25 const path = '/api/v1/users/'
@@ -46,10 +27,10 @@ describe('Test users API validators', function () {
46 let rootId: number 27 let rootId: number
47 let moderatorId: number 28 let moderatorId: number
48 let video: VideoCreateResult 29 let video: VideoCreateResult
49 let server: ServerInfo 30 let server: PeerTubeServer
50 let serverWithRegistrationDisabled: ServerInfo 31 let serverWithRegistrationDisabled: PeerTubeServer
51 let userAccessToken = '' 32 let userToken = ''
52 let moderatorAccessToken = '' 33 let moderatorToken = ''
53 let emailPort: number 34 let emailPort: number
54 let overrideConfig: Object 35 let overrideConfig: Object
55 36
@@ -65,8 +46,8 @@ describe('Test users API validators', function () {
65 46
66 { 47 {
67 const res = await Promise.all([ 48 const res = await Promise.all([
68 flushAndRunServer(1, overrideConfig), 49 createSingleServer(1, overrideConfig),
69 flushAndRunServer(2) 50 createSingleServer(2)
70 ]) 51 ])
71 52
72 server = res[0] 53 server = res[0]
@@ -76,66 +57,31 @@ describe('Test users API validators', function () {
76 } 57 }
77 58
78 { 59 {
79 const user = { 60 const user = { username: 'user1' }
80 username: 'user1', 61 await server.users.create({ ...user })
81 password: 'my super password' 62 userToken = await server.login.getAccessToken(user)
82 }
83
84 const videoQuota = 42000000
85 await createUser({
86 url: server.url,
87 accessToken: server.accessToken,
88 username: user.username,
89 password: user.password,
90 videoQuota: videoQuota
91 })
92 userAccessToken = await userLogin(server, user)
93 } 63 }
94 64
95 { 65 {
96 const moderator = { 66 const moderator = { username: 'moderator1' }
97 username: 'moderator1', 67 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
98 password: 'super password' 68 moderatorToken = await server.login.getAccessToken(moderator)
99 }
100
101 await createUser({
102 url: server.url,
103 accessToken: server.accessToken,
104 username: moderator.username,
105 password: moderator.password,
106 role: UserRole.MODERATOR
107 })
108
109 moderatorAccessToken = await userLogin(server, moderator)
110 } 69 }
111 70
112 { 71 {
113 const moderator = { 72 const moderator = { username: 'moderator2' }
114 username: 'moderator2', 73 await server.users.create({ ...moderator, role: UserRole.MODERATOR })
115 password: 'super password'
116 }
117
118 await createUser({
119 url: server.url,
120 accessToken: server.accessToken,
121 username: moderator.username,
122 password: moderator.password,
123 role: UserRole.MODERATOR
124 })
125 } 74 }
126 75
127 { 76 {
128 const res = await uploadVideo(server.url, server.accessToken, {}) 77 video = await server.videos.upload()
129 video = res.body.video
130 } 78 }
131 79
132 { 80 {
133 const res = await getUsersList(server.url, server.accessToken) 81 const { data } = await server.users.list()
134 const users: User[] = res.body.data 82 userId = data.find(u => u.username === 'user1').id
135 83 rootId = data.find(u => u.username === 'root').id
136 userId = users.find(u => u.username === 'user1').id 84 moderatorId = data.find(u => u.username === 'moderator2').id
137 rootId = users.find(u => u.username === 'root').id
138 moderatorId = users.find(u => u.username === 'moderator2').id
139 } 85 }
140 }) 86 })
141 87
@@ -156,7 +102,7 @@ describe('Test users API validators', function () {
156 await makeGetRequest({ 102 await makeGetRequest({
157 url: server.url, 103 url: server.url,
158 path, 104 path,
159 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 105 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
160 }) 106 })
161 }) 107 })
162 108
@@ -164,8 +110,8 @@ describe('Test users API validators', function () {
164 await makeGetRequest({ 110 await makeGetRequest({
165 url: server.url, 111 url: server.url,
166 path, 112 path,
167 token: userAccessToken, 113 token: userToken,
168 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 114 expectedStatus: HttpStatusCode.FORBIDDEN_403
169 }) 115 })
170 }) 116 })
171 }) 117 })
@@ -182,25 +128,25 @@ describe('Test users API validators', function () {
182 } 128 }
183 129
184 it('Should fail with a too small username', async function () { 130 it('Should fail with a too small username', async function () {
185 const fields = immutableAssign(baseCorrectParams, { username: '' }) 131 const fields = { ...baseCorrectParams, username: '' }
186 132
187 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 133 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
188 }) 134 })
189 135
190 it('Should fail with a too long username', async function () { 136 it('Should fail with a too long username', async function () {
191 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 137 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
192 138
193 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 139 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
194 }) 140 })
195 141
196 it('Should fail with a not lowercase username', async function () { 142 it('Should fail with a not lowercase username', async function () {
197 const fields = immutableAssign(baseCorrectParams, { username: 'Toto' }) 143 const fields = { ...baseCorrectParams, username: 'Toto' }
198 144
199 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 145 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
200 }) 146 })
201 147
202 it('Should fail with an incorrect username', async function () { 148 it('Should fail with an incorrect username', async function () {
203 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 149 const fields = { ...baseCorrectParams, username: 'my username' }
204 150
205 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 151 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
206 }) 152 })
@@ -212,25 +158,25 @@ describe('Test users API validators', function () {
212 }) 158 })
213 159
214 it('Should fail with an invalid email', async function () { 160 it('Should fail with an invalid email', async function () {
215 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 161 const fields = { ...baseCorrectParams, email: 'test_example.com' }
216 162
217 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 163 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
218 }) 164 })
219 165
220 it('Should fail with a too small password', async function () { 166 it('Should fail with a too small password', async function () {
221 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 167 const fields = { ...baseCorrectParams, password: 'bla' }
222 168
223 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 169 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 }) 170 })
225 171
226 it('Should fail with a too long password', async function () { 172 it('Should fail with a too long password', async function () {
227 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 173 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
228 174
229 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 175 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
230 }) 176 })
231 177
232 it('Should fail with empty password and no smtp configured', async function () { 178 it('Should fail with empty password and no smtp configured', async function () {
233 const fields = immutableAssign(baseCorrectParams, { password: '' }) 179 const fields = { ...baseCorrectParams, password: '' }
234 180
235 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 181 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
236 }) 182 })
@@ -238,33 +184,37 @@ describe('Test users API validators', function () {
238 it('Should succeed with no password on a server with smtp enabled', async function () { 184 it('Should succeed with no password on a server with smtp enabled', async function () {
239 this.timeout(20000) 185 this.timeout(20000)
240 186
241 killallServers([ server ]) 187 await killallServers([ server ])
188
189 const config = {
190 ...overrideConfig,
242 191
243 const config = immutableAssign(overrideConfig, {
244 smtp: { 192 smtp: {
245 hostname: 'localhost', 193 hostname: 'localhost',
246 port: emailPort 194 port: emailPort
247 } 195 }
248 }) 196 }
249 await reRunServer(server, config) 197 await server.run(config)
198
199 const fields = {
200 ...baseCorrectParams,
250 201
251 const fields = immutableAssign(baseCorrectParams, {
252 password: '', 202 password: '',
253 username: 'create_password', 203 username: 'create_password',
254 email: 'create_password@example.com' 204 email: 'create_password@example.com'
255 }) 205 }
256 206
257 await makePostBodyRequest({ 207 await makePostBodyRequest({
258 url: server.url, 208 url: server.url,
259 path: path, 209 path: path,
260 token: server.accessToken, 210 token: server.accessToken,
261 fields, 211 fields,
262 statusCodeExpected: HttpStatusCode.OK_200 212 expectedStatus: HttpStatusCode.OK_200
263 }) 213 })
264 }) 214 })
265 215
266 it('Should fail with invalid admin flags', async function () { 216 it('Should fail with invalid admin flags', async function () {
267 const fields = immutableAssign(baseCorrectParams, { adminFlags: 'toto' }) 217 const fields = { ...baseCorrectParams, adminFlags: 'toto' }
268 218
269 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 219 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
270 }) 220 })
@@ -275,31 +225,31 @@ describe('Test users API validators', function () {
275 path, 225 path,
276 token: 'super token', 226 token: 'super token',
277 fields: baseCorrectParams, 227 fields: baseCorrectParams,
278 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 228 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
279 }) 229 })
280 }) 230 })
281 231
282 it('Should fail if we add a user with the same username', async function () { 232 it('Should fail if we add a user with the same username', async function () {
283 const fields = immutableAssign(baseCorrectParams, { username: 'user1' }) 233 const fields = { ...baseCorrectParams, username: 'user1' }
284 234
285 await makePostBodyRequest({ 235 await makePostBodyRequest({
286 url: server.url, 236 url: server.url,
287 path, 237 path,
288 token: server.accessToken, 238 token: server.accessToken,
289 fields, 239 fields,
290 statusCodeExpected: HttpStatusCode.CONFLICT_409 240 expectedStatus: HttpStatusCode.CONFLICT_409
291 }) 241 })
292 }) 242 })
293 243
294 it('Should fail if we add a user with the same email', async function () { 244 it('Should fail if we add a user with the same email', async function () {
295 const fields = immutableAssign(baseCorrectParams, { email: 'user1@example.com' }) 245 const fields = { ...baseCorrectParams, email: 'user1@example.com' }
296 246
297 await makePostBodyRequest({ 247 await makePostBodyRequest({
298 url: server.url, 248 url: server.url,
299 path, 249 path,
300 token: server.accessToken, 250 token: server.accessToken,
301 fields, 251 fields,
302 statusCodeExpected: HttpStatusCode.CONFLICT_409 252 expectedStatus: HttpStatusCode.CONFLICT_409
303 }) 253 })
304 }) 254 })
305 255
@@ -316,13 +266,13 @@ describe('Test users API validators', function () {
316 }) 266 })
317 267
318 it('Should fail with an invalid videoQuota', async function () { 268 it('Should fail with an invalid videoQuota', async function () {
319 const fields = immutableAssign(baseCorrectParams, { videoQuota: -5 }) 269 const fields = { ...baseCorrectParams, videoQuota: -5 }
320 270
321 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 271 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
322 }) 272 })
323 273
324 it('Should fail with an invalid videoQuotaDaily', async function () { 274 it('Should fail with an invalid videoQuotaDaily', async function () {
325 const fields = immutableAssign(baseCorrectParams, { videoQuotaDaily: -7 }) 275 const fields = { ...baseCorrectParams, videoQuotaDaily: -7 }
326 276
327 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 277 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
328 }) 278 })
@@ -334,46 +284,46 @@ describe('Test users API validators', function () {
334 }) 284 })
335 285
336 it('Should fail with an invalid user role', async function () { 286 it('Should fail with an invalid user role', async function () {
337 const fields = immutableAssign(baseCorrectParams, { role: 88989 }) 287 const fields = { ...baseCorrectParams, role: 88989 }
338 288
339 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 289 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
340 }) 290 })
341 291
342 it('Should fail with a "peertube" username', async function () { 292 it('Should fail with a "peertube" username', async function () {
343 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 293 const fields = { ...baseCorrectParams, username: 'peertube' }
344 294
345 await makePostBodyRequest({ 295 await makePostBodyRequest({
346 url: server.url, 296 url: server.url,
347 path, 297 path,
348 token: server.accessToken, 298 token: server.accessToken,
349 fields, 299 fields,
350 statusCodeExpected: HttpStatusCode.CONFLICT_409 300 expectedStatus: HttpStatusCode.CONFLICT_409
351 }) 301 })
352 }) 302 })
353 303
354 it('Should fail to create a moderator or an admin with a moderator', async function () { 304 it('Should fail to create a moderator or an admin with a moderator', async function () {
355 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) { 305 for (const role of [ UserRole.MODERATOR, UserRole.ADMINISTRATOR ]) {
356 const fields = immutableAssign(baseCorrectParams, { role }) 306 const fields = { ...baseCorrectParams, role }
357 307
358 await makePostBodyRequest({ 308 await makePostBodyRequest({
359 url: server.url, 309 url: server.url,
360 path, 310 path,
361 token: moderatorAccessToken, 311 token: moderatorToken,
362 fields, 312 fields,
363 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 313 expectedStatus: HttpStatusCode.FORBIDDEN_403
364 }) 314 })
365 } 315 }
366 }) 316 })
367 317
368 it('Should succeed to create a user with a moderator', async function () { 318 it('Should succeed to create a user with a moderator', async function () {
369 const fields = immutableAssign(baseCorrectParams, { username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }) 319 const fields = { ...baseCorrectParams, username: 'a4656', email: 'a4656@example.com', role: UserRole.USER }
370 320
371 await makePostBodyRequest({ 321 await makePostBodyRequest({
372 url: server.url, 322 url: server.url,
373 path, 323 path,
374 token: moderatorAccessToken, 324 token: moderatorToken,
375 fields, 325 fields,
376 statusCodeExpected: HttpStatusCode.OK_200 326 expectedStatus: HttpStatusCode.OK_200
377 }) 327 })
378 }) 328 })
379 329
@@ -383,16 +333,13 @@ describe('Test users API validators', function () {
383 path, 333 path,
384 token: server.accessToken, 334 token: server.accessToken,
385 fields: baseCorrectParams, 335 fields: baseCorrectParams,
386 statusCodeExpected: HttpStatusCode.OK_200 336 expectedStatus: HttpStatusCode.OK_200
387 }) 337 })
388 }) 338 })
389 339
390 it('Should fail with a non admin user', async function () { 340 it('Should fail with a non admin user', async function () {
391 const user = { 341 const user = { username: 'user1' }
392 username: 'user1', 342 userToken = await server.login.getAccessToken(user)
393 password: 'my super password'
394 }
395 userAccessToken = await userLogin(server, user)
396 343
397 const fields = { 344 const fields = {
398 username: 'user3', 345 username: 'user3',
@@ -400,11 +347,12 @@ describe('Test users API validators', function () {
400 password: 'my super password', 347 password: 'my super password',
401 videoQuota: 42000000 348 videoQuota: 42000000
402 } 349 }
403 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 350 await makePostBodyRequest({ url: server.url, path, token: userToken, fields, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
404 }) 351 })
405 }) 352 })
406 353
407 describe('When updating my account', function () { 354 describe('When updating my account', function () {
355
408 it('Should fail with an invalid email attribute', async function () { 356 it('Should fail with an invalid email attribute', async function () {
409 const fields = { 357 const fields = {
410 email: 'blabla' 358 email: 'blabla'
@@ -415,29 +363,29 @@ describe('Test users API validators', function () {
415 363
416 it('Should fail with a too small password', async function () { 364 it('Should fail with a too small password', async function () {
417 const fields = { 365 const fields = {
418 currentPassword: 'my super password', 366 currentPassword: 'password',
419 password: 'bla' 367 password: 'bla'
420 } 368 }
421 369
422 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 370 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
423 }) 371 })
424 372
425 it('Should fail with a too long password', async function () { 373 it('Should fail with a too long password', async function () {
426 const fields = { 374 const fields = {
427 currentPassword: 'my super password', 375 currentPassword: 'password',
428 password: 'super'.repeat(61) 376 password: 'super'.repeat(61)
429 } 377 }
430 378
431 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 379 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
432 }) 380 })
433 381
434 it('Should fail without the current password', async function () { 382 it('Should fail without the current password', async function () {
435 const fields = { 383 const fields = {
436 currentPassword: 'my super password', 384 currentPassword: 'password',
437 password: 'super'.repeat(61) 385 password: 'super'.repeat(61)
438 } 386 }
439 387
440 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 388 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
441 }) 389 })
442 390
443 it('Should fail with an invalid current password', async function () { 391 it('Should fail with an invalid current password', async function () {
@@ -449,9 +397,9 @@ describe('Test users API validators', function () {
449 await makePutBodyRequest({ 397 await makePutBodyRequest({
450 url: server.url, 398 url: server.url,
451 path: path + 'me', 399 path: path + 'me',
452 token: userAccessToken, 400 token: userToken,
453 fields, 401 fields,
454 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 402 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
455 }) 403 })
456 }) 404 })
457 405
@@ -460,7 +408,7 @@ describe('Test users API validators', function () {
460 nsfwPolicy: 'hello' 408 nsfwPolicy: 'hello'
461 } 409 }
462 410
463 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 411 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
464 }) 412 })
465 413
466 it('Should fail with an invalid autoPlayVideo attribute', async function () { 414 it('Should fail with an invalid autoPlayVideo attribute', async function () {
@@ -468,7 +416,7 @@ describe('Test users API validators', function () {
468 autoPlayVideo: -1 416 autoPlayVideo: -1
469 } 417 }
470 418
471 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 419 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
472 }) 420 })
473 421
474 it('Should fail with an invalid autoPlayNextVideo attribute', async function () { 422 it('Should fail with an invalid autoPlayNextVideo attribute', async function () {
@@ -476,7 +424,7 @@ describe('Test users API validators', function () {
476 autoPlayNextVideo: -1 424 autoPlayNextVideo: -1
477 } 425 }
478 426
479 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 427 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
480 }) 428 })
481 429
482 it('Should fail with an invalid videosHistoryEnabled attribute', async function () { 430 it('Should fail with an invalid videosHistoryEnabled attribute', async function () {
@@ -484,12 +432,12 @@ describe('Test users API validators', function () {
484 videosHistoryEnabled: -1 432 videosHistoryEnabled: -1
485 } 433 }
486 434
487 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 435 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
488 }) 436 })
489 437
490 it('Should fail with an non authenticated user', async function () { 438 it('Should fail with an non authenticated user', async function () {
491 const fields = { 439 const fields = {
492 currentPassword: 'my super password', 440 currentPassword: 'password',
493 password: 'my super password' 441 password: 'my super password'
494 } 442 }
495 443
@@ -498,7 +446,7 @@ describe('Test users API validators', function () {
498 path: path + 'me', 446 path: path + 'me',
499 token: 'super token', 447 token: 'super token',
500 fields, 448 fields,
501 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 449 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
502 }) 450 })
503 }) 451 })
504 452
@@ -507,7 +455,7 @@ describe('Test users API validators', function () {
507 description: 'super'.repeat(201) 455 description: 'super'.repeat(201)
508 } 456 }
509 457
510 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 458 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
511 }) 459 })
512 460
513 it('Should fail with an invalid videoLanguages attribute', async function () { 461 it('Should fail with an invalid videoLanguages attribute', async function () {
@@ -516,7 +464,7 @@ describe('Test users API validators', function () {
516 videoLanguages: 'toto' 464 videoLanguages: 'toto'
517 } 465 }
518 466
519 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 467 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
520 } 468 }
521 469
522 { 470 {
@@ -529,18 +477,18 @@ describe('Test users API validators', function () {
529 videoLanguages: languages 477 videoLanguages: languages
530 } 478 }
531 479
532 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 480 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
533 } 481 }
534 }) 482 })
535 483
536 it('Should fail with an invalid theme', async function () { 484 it('Should fail with an invalid theme', async function () {
537 const fields = { theme: 'invalid' } 485 const fields = { theme: 'invalid' }
538 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 486 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
539 }) 487 })
540 488
541 it('Should fail with an unknown theme', async function () { 489 it('Should fail with an unknown theme', async function () {
542 const fields = { theme: 'peertube-theme-unknown' } 490 const fields = { theme: 'peertube-theme-unknown' }
543 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 491 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
544 }) 492 })
545 493
546 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () { 494 it('Should fail with an invalid noInstanceConfigWarningModal attribute', async function () {
@@ -548,7 +496,7 @@ describe('Test users API validators', function () {
548 noInstanceConfigWarningModal: -1 496 noInstanceConfigWarningModal: -1
549 } 497 }
550 498
551 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 499 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
552 }) 500 })
553 501
554 it('Should fail with an invalid noWelcomeModal attribute', async function () { 502 it('Should fail with an invalid noWelcomeModal attribute', async function () {
@@ -556,12 +504,12 @@ describe('Test users API validators', function () {
556 noWelcomeModal: -1 504 noWelcomeModal: -1
557 } 505 }
558 506
559 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userAccessToken, fields }) 507 await makePutBodyRequest({ url: server.url, path: path + 'me', token: userToken, fields })
560 }) 508 })
561 509
562 it('Should succeed to change password with the correct params', async function () { 510 it('Should succeed to change password with the correct params', async function () {
563 const fields = { 511 const fields = {
564 currentPassword: 'my super password', 512 currentPassword: 'password',
565 password: 'my super password', 513 password: 'my super password',
566 nsfwPolicy: 'blur', 514 nsfwPolicy: 'blur',
567 autoPlayVideo: false, 515 autoPlayVideo: false,
@@ -574,9 +522,9 @@ describe('Test users API validators', function () {
574 await makePutBodyRequest({ 522 await makePutBodyRequest({
575 url: server.url, 523 url: server.url,
576 path: path + 'me', 524 path: path + 'me',
577 token: userAccessToken, 525 token: userToken,
578 fields, 526 fields,
579 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 527 expectedStatus: HttpStatusCode.NO_CONTENT_204
580 }) 528 })
581 }) 529 })
582 530
@@ -589,9 +537,9 @@ describe('Test users API validators', function () {
589 await makePutBodyRequest({ 537 await makePutBodyRequest({
590 url: server.url, 538 url: server.url,
591 path: path + 'me', 539 path: path + 'me',
592 token: userAccessToken, 540 token: userToken,
593 fields, 541 fields,
594 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 542 expectedStatus: HttpStatusCode.NO_CONTENT_204
595 }) 543 })
596 }) 544 })
597 }) 545 })
@@ -623,7 +571,7 @@ describe('Test users API validators', function () {
623 path: path + '/me/avatar/pick', 571 path: path + '/me/avatar/pick',
624 fields, 572 fields,
625 attaches, 573 attaches,
626 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 574 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
627 }) 575 })
628 }) 576 })
629 577
@@ -638,7 +586,7 @@ describe('Test users API validators', function () {
638 token: server.accessToken, 586 token: server.accessToken,
639 fields, 587 fields,
640 attaches, 588 attaches,
641 statusCodeExpected: HttpStatusCode.OK_200 589 expectedStatus: HttpStatusCode.OK_200
642 }) 590 })
643 }) 591 })
644 }) 592 })
@@ -646,28 +594,28 @@ describe('Test users API validators', function () {
646 describe('When managing my scoped tokens', function () { 594 describe('When managing my scoped tokens', function () {
647 595
648 it('Should fail to get my scoped tokens with an non authenticated user', async function () { 596 it('Should fail to get my scoped tokens with an non authenticated user', async function () {
649 await getUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) 597 await server.users.getMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
650 }) 598 })
651 599
652 it('Should fail to get my scoped tokens with a bad token', async function () { 600 it('Should fail to get my scoped tokens with a bad token', async function () {
653 await getUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) 601 await server.users.getMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
654 602
655 }) 603 })
656 604
657 it('Should succeed to get my scoped tokens', async function () { 605 it('Should succeed to get my scoped tokens', async function () {
658 await getUserScopedTokens(server.url, server.accessToken) 606 await server.users.getMyScopedTokens()
659 }) 607 })
660 608
661 it('Should fail to renew my scoped tokens with an non authenticated user', async function () { 609 it('Should fail to renew my scoped tokens with an non authenticated user', async function () {
662 await renewUserScopedTokens(server.url, null, HttpStatusCode.UNAUTHORIZED_401) 610 await server.users.renewMyScopedTokens({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
663 }) 611 })
664 612
665 it('Should fail to renew my scoped tokens with a bad token', async function () { 613 it('Should fail to renew my scoped tokens with a bad token', async function () {
666 await renewUserScopedTokens(server.url, 'bad', HttpStatusCode.UNAUTHORIZED_401) 614 await server.users.renewMyScopedTokens({ token: 'bad', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
667 }) 615 })
668 616
669 it('Should succeed to renew my scoped tokens', async function () { 617 it('Should succeed to renew my scoped tokens', async function () {
670 await renewUserScopedTokens(server.url, server.accessToken) 618 await server.users.renewMyScopedTokens()
671 }) 619 })
672 }) 620 })
673 621
@@ -678,16 +626,16 @@ describe('Test users API validators', function () {
678 url: server.url, 626 url: server.url,
679 path: path + userId, 627 path: path + userId,
680 token: 'super token', 628 token: 'super token',
681 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 629 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
682 }) 630 })
683 }) 631 })
684 632
685 it('Should fail with a non admin user', async function () { 633 it('Should fail with a non admin user', async function () {
686 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 634 await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
687 }) 635 })
688 636
689 it('Should succeed with the correct params', async function () { 637 it('Should succeed with the correct params', async function () {
690 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, statusCodeExpected: HttpStatusCode.OK_200 }) 638 await makeGetRequest({ url: server.url, path: path + userId, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 })
691 }) 639 })
692 }) 640 })
693 641
@@ -727,7 +675,7 @@ describe('Test users API validators', function () {
727 675
728 it('Should fail with a too small password', async function () { 676 it('Should fail with a too small password', async function () {
729 const fields = { 677 const fields = {
730 currentPassword: 'my super password', 678 currentPassword: 'password',
731 password: 'bla' 679 password: 'bla'
732 } 680 }
733 681
@@ -736,7 +684,7 @@ describe('Test users API validators', function () {
736 684
737 it('Should fail with a too long password', async function () { 685 it('Should fail with a too long password', async function () {
738 const fields = { 686 const fields = {
739 currentPassword: 'my super password', 687 currentPassword: 'password',
740 password: 'super'.repeat(61) 688 password: 'super'.repeat(61)
741 } 689 }
742 690
@@ -753,7 +701,7 @@ describe('Test users API validators', function () {
753 path: path + userId, 701 path: path + userId,
754 token: 'super token', 702 token: 'super token',
755 fields, 703 fields,
756 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 704 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
757 }) 705 })
758 }) 706 })
759 707
@@ -779,9 +727,9 @@ describe('Test users API validators', function () {
779 await makePutBodyRequest({ 727 await makePutBodyRequest({
780 url: server.url, 728 url: server.url,
781 path: path + moderatorId, 729 path: path + moderatorId,
782 token: moderatorAccessToken, 730 token: moderatorToken,
783 fields, 731 fields,
784 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 732 expectedStatus: HttpStatusCode.FORBIDDEN_403
785 }) 733 })
786 }) 734 })
787 735
@@ -793,9 +741,9 @@ describe('Test users API validators', function () {
793 await makePutBodyRequest({ 741 await makePutBodyRequest({
794 url: server.url, 742 url: server.url,
795 path: path + userId, 743 path: path + userId,
796 token: moderatorAccessToken, 744 token: moderatorToken,
797 fields, 745 fields,
798 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 746 expectedStatus: HttpStatusCode.NO_CONTENT_204
799 }) 747 })
800 }) 748 })
801 749
@@ -812,38 +760,44 @@ describe('Test users API validators', function () {
812 path: path + userId, 760 path: path + userId,
813 token: server.accessToken, 761 token: server.accessToken,
814 fields, 762 fields,
815 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 763 expectedStatus: HttpStatusCode.NO_CONTENT_204
816 }) 764 })
817 }) 765 })
818 }) 766 })
819 767
820 describe('When getting my information', function () { 768 describe('When getting my information', function () {
821 it('Should fail with a non authenticated user', async function () { 769 it('Should fail with a non authenticated user', async function () {
822 await getMyUserInformation(server.url, 'fake_token', HttpStatusCode.UNAUTHORIZED_401) 770 await server.users.getMyInfo({ token: 'fake_token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
823 }) 771 })
824 772
825 it('Should success with the correct parameters', async function () { 773 it('Should success with the correct parameters', async function () {
826 await getMyUserInformation(server.url, userAccessToken) 774 await server.users.getMyInfo({ token: userToken })
827 }) 775 })
828 }) 776 })
829 777
830 describe('When getting my video rating', function () { 778 describe('When getting my video rating', function () {
779 let command: UsersCommand
780
781 before(function () {
782 command = server.users
783 })
784
831 it('Should fail with a non authenticated user', async function () { 785 it('Should fail with a non authenticated user', async function () {
832 await getMyUserVideoRating(server.url, 'fake_token', video.id, HttpStatusCode.UNAUTHORIZED_401) 786 await command.getMyRating({ token: 'fake_token', videoId: video.id, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
833 }) 787 })
834 788
835 it('Should fail with an incorrect video uuid', async function () { 789 it('Should fail with an incorrect video uuid', async function () {
836 await getMyUserVideoRating(server.url, server.accessToken, 'blabla', HttpStatusCode.BAD_REQUEST_400) 790 await command.getMyRating({ videoId: 'blabla', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
837 }) 791 })
838 792
839 it('Should fail with an unknown video', async function () { 793 it('Should fail with an unknown video', async function () {
840 await getMyUserVideoRating(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 794 await command.getMyRating({ videoId: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
841 }) 795 })
842 796
843 it('Should succeed with the correct parameters', async function () { 797 it('Should succeed with the correct parameters', async function () {
844 await getMyUserVideoRating(server.url, server.accessToken, video.id) 798 await command.getMyRating({ videoId: video.id })
845 await getMyUserVideoRating(server.url, server.accessToken, video.uuid) 799 await command.getMyRating({ videoId: video.uuid })
846 await getMyUserVideoRating(server.url, server.accessToken, video.shortUUID) 800 await command.getMyRating({ videoId: video.shortUUID })
847 }) 801 })
848 }) 802 })
849 803
@@ -851,80 +805,93 @@ describe('Test users API validators', function () {
851 const path = '/api/v1/accounts/user1/ratings' 805 const path = '/api/v1/accounts/user1/ratings'
852 806
853 it('Should fail with a bad start pagination', async function () { 807 it('Should fail with a bad start pagination', async function () {
854 await checkBadStartPagination(server.url, path, userAccessToken) 808 await checkBadStartPagination(server.url, path, userToken)
855 }) 809 })
856 810
857 it('Should fail with a bad count pagination', async function () { 811 it('Should fail with a bad count pagination', async function () {
858 await checkBadCountPagination(server.url, path, userAccessToken) 812 await checkBadCountPagination(server.url, path, userToken)
859 }) 813 })
860 814
861 it('Should fail with an incorrect sort', async function () { 815 it('Should fail with an incorrect sort', async function () {
862 await checkBadSortPagination(server.url, path, userAccessToken) 816 await checkBadSortPagination(server.url, path, userToken)
863 }) 817 })
864 818
865 it('Should fail with a unauthenticated user', async function () { 819 it('Should fail with a unauthenticated user', async function () {
866 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 820 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
867 }) 821 })
868 822
869 it('Should fail with a another user', async function () { 823 it('Should fail with a another user', async function () {
870 await makeGetRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 824 await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
871 }) 825 })
872 826
873 it('Should fail with a bad type', async function () { 827 it('Should fail with a bad type', async function () {
874 await makeGetRequest({ 828 await makeGetRequest({
875 url: server.url, 829 url: server.url,
876 path, 830 path,
877 token: userAccessToken, 831 token: userToken,
878 query: { rating: 'toto ' }, 832 query: { rating: 'toto ' },
879 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 833 expectedStatus: HttpStatusCode.BAD_REQUEST_400
880 }) 834 })
881 }) 835 })
882 836
883 it('Should succeed with the correct params', async function () { 837 it('Should succeed with the correct params', async function () {
884 await makeGetRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.OK_200 }) 838 await makeGetRequest({ url: server.url, path, token: userToken, expectedStatus: HttpStatusCode.OK_200 })
885 }) 839 })
886 }) 840 })
887 841
888 describe('When blocking/unblocking/removing user', function () { 842 describe('When blocking/unblocking/removing user', function () {
843
889 it('Should fail with an incorrect id', async function () { 844 it('Should fail with an incorrect id', async function () {
890 await removeUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 845 const options = { userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
891 await blockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 846
892 await unblockUser(server.url, 'blabla', server.accessToken, HttpStatusCode.BAD_REQUEST_400) 847 await server.users.remove(options)
848 await server.users.banUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
849 await server.users.unbanUser({ userId: 'blabla' as any, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
893 }) 850 })
894 851
895 it('Should fail with the root user', async function () { 852 it('Should fail with the root user', async function () {
896 await removeUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 853 const options = { userId: rootId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 }
897 await blockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 854
898 await unblockUser(server.url, rootId, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 855 await server.users.remove(options)
856 await server.users.banUser(options)
857 await server.users.unbanUser(options)
899 }) 858 })
900 859
901 it('Should return 404 with a non existing id', async function () { 860 it('Should return 404 with a non existing id', async function () {
902 await removeUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 861 const options = { userId: 4545454, expectedStatus: HttpStatusCode.NOT_FOUND_404 }
903 await blockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 862
904 await unblockUser(server.url, 4545454, server.accessToken, HttpStatusCode.NOT_FOUND_404) 863 await server.users.remove(options)
864 await server.users.banUser(options)
865 await server.users.unbanUser(options)
905 }) 866 })
906 867
907 it('Should fail with a non admin user', async function () { 868 it('Should fail with a non admin user', async function () {
908 await removeUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 869 const options = { userId, token: userToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
909 await blockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 870
910 await unblockUser(server.url, userId, userAccessToken, HttpStatusCode.FORBIDDEN_403) 871 await server.users.remove(options)
872 await server.users.banUser(options)
873 await server.users.unbanUser(options)
911 }) 874 })
912 875
913 it('Should fail on a moderator with a moderator', async function () { 876 it('Should fail on a moderator with a moderator', async function () {
914 await removeUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 877 const options = { userId: moderatorId, token: moderatorToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }
915 await blockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 878
916 await unblockUser(server.url, moderatorId, moderatorAccessToken, HttpStatusCode.FORBIDDEN_403) 879 await server.users.remove(options)
880 await server.users.banUser(options)
881 await server.users.unbanUser(options)
917 }) 882 })
918 883
919 it('Should succeed on a user with a moderator', async function () { 884 it('Should succeed on a user with a moderator', async function () {
920 await blockUser(server.url, userId, moderatorAccessToken) 885 const options = { userId, token: moderatorToken }
921 await unblockUser(server.url, userId, moderatorAccessToken) 886
887 await server.users.banUser(options)
888 await server.users.unbanUser(options)
922 }) 889 })
923 }) 890 })
924 891
925 describe('When deleting our account', function () { 892 describe('When deleting our account', function () {
926 it('Should fail with with the root account', async function () { 893 it('Should fail with with the root account', async function () {
927 await deleteMe(server.url, server.accessToken, HttpStatusCode.BAD_REQUEST_400) 894 await server.users.deleteMe({ expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
928 }) 895 })
929 }) 896 })
930 897
@@ -938,19 +905,19 @@ describe('Test users API validators', function () {
938 } 905 }
939 906
940 it('Should fail with a too small username', async function () { 907 it('Should fail with a too small username', async function () {
941 const fields = immutableAssign(baseCorrectParams, { username: '' }) 908 const fields = { ...baseCorrectParams, username: '' }
942 909
943 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 910 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
944 }) 911 })
945 912
946 it('Should fail with a too long username', async function () { 913 it('Should fail with a too long username', async function () {
947 const fields = immutableAssign(baseCorrectParams, { username: 'super'.repeat(50) }) 914 const fields = { ...baseCorrectParams, username: 'super'.repeat(50) }
948 915
949 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 916 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
950 }) 917 })
951 918
952 it('Should fail with an incorrect username', async function () { 919 it('Should fail with an incorrect username', async function () {
953 const fields = immutableAssign(baseCorrectParams, { username: 'my username' }) 920 const fields = { ...baseCorrectParams, username: 'my username' }
954 921
955 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 922 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
956 }) 923 })
@@ -962,108 +929,108 @@ describe('Test users API validators', function () {
962 }) 929 })
963 930
964 it('Should fail with an invalid email', async function () { 931 it('Should fail with an invalid email', async function () {
965 const fields = immutableAssign(baseCorrectParams, { email: 'test_example.com' }) 932 const fields = { ...baseCorrectParams, email: 'test_example.com' }
966 933
967 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 934 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
968 }) 935 })
969 936
970 it('Should fail with a too small password', async function () { 937 it('Should fail with a too small password', async function () {
971 const fields = immutableAssign(baseCorrectParams, { password: 'bla' }) 938 const fields = { ...baseCorrectParams, password: 'bla' }
972 939
973 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 940 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
974 }) 941 })
975 942
976 it('Should fail with a too long password', async function () { 943 it('Should fail with a too long password', async function () {
977 const fields = immutableAssign(baseCorrectParams, { password: 'super'.repeat(61) }) 944 const fields = { ...baseCorrectParams, password: 'super'.repeat(61) }
978 945
979 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 946 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
980 }) 947 })
981 948
982 it('Should fail if we register a user with the same username', async function () { 949 it('Should fail if we register a user with the same username', async function () {
983 const fields = immutableAssign(baseCorrectParams, { username: 'root' }) 950 const fields = { ...baseCorrectParams, username: 'root' }
984 951
985 await makePostBodyRequest({ 952 await makePostBodyRequest({
986 url: server.url, 953 url: server.url,
987 path: registrationPath, 954 path: registrationPath,
988 token: server.accessToken, 955 token: server.accessToken,
989 fields, 956 fields,
990 statusCodeExpected: HttpStatusCode.CONFLICT_409 957 expectedStatus: HttpStatusCode.CONFLICT_409
991 }) 958 })
992 }) 959 })
993 960
994 it('Should fail with a "peertube" username', async function () { 961 it('Should fail with a "peertube" username', async function () {
995 const fields = immutableAssign(baseCorrectParams, { username: 'peertube' }) 962 const fields = { ...baseCorrectParams, username: 'peertube' }
996 963
997 await makePostBodyRequest({ 964 await makePostBodyRequest({
998 url: server.url, 965 url: server.url,
999 path: registrationPath, 966 path: registrationPath,
1000 token: server.accessToken, 967 token: server.accessToken,
1001 fields, 968 fields,
1002 statusCodeExpected: HttpStatusCode.CONFLICT_409 969 expectedStatus: HttpStatusCode.CONFLICT_409
1003 }) 970 })
1004 }) 971 })
1005 972
1006 it('Should fail if we register a user with the same email', async function () { 973 it('Should fail if we register a user with the same email', async function () {
1007 const fields = immutableAssign(baseCorrectParams, { email: 'admin' + server.internalServerNumber + '@example.com' }) 974 const fields = { ...baseCorrectParams, email: 'admin' + server.internalServerNumber + '@example.com' }
1008 975
1009 await makePostBodyRequest({ 976 await makePostBodyRequest({
1010 url: server.url, 977 url: server.url,
1011 path: registrationPath, 978 path: registrationPath,
1012 token: server.accessToken, 979 token: server.accessToken,
1013 fields, 980 fields,
1014 statusCodeExpected: HttpStatusCode.CONFLICT_409 981 expectedStatus: HttpStatusCode.CONFLICT_409
1015 }) 982 })
1016 }) 983 })
1017 984
1018 it('Should fail with a bad display name', async function () { 985 it('Should fail with a bad display name', async function () {
1019 const fields = immutableAssign(baseCorrectParams, { displayName: 'a'.repeat(150) }) 986 const fields = { ...baseCorrectParams, displayName: 'a'.repeat(150) }
1020 987
1021 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 988 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1022 }) 989 })
1023 990
1024 it('Should fail with a bad channel name', async function () { 991 it('Should fail with a bad channel name', async function () {
1025 const fields = immutableAssign(baseCorrectParams, { channel: { name: '[]azf', displayName: 'toto' } }) 992 const fields = { ...baseCorrectParams, channel: { name: '[]azf', displayName: 'toto' } }
1026 993
1027 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 994 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1028 }) 995 })
1029 996
1030 it('Should fail with a bad channel display name', async function () { 997 it('Should fail with a bad channel display name', async function () {
1031 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'toto', displayName: '' } }) 998 const fields = { ...baseCorrectParams, channel: { name: 'toto', displayName: '' } }
1032 999
1033 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1000 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1034 }) 1001 })
1035 1002
1036 it('Should fail with a channel name that is the same as username', async function () { 1003 it('Should fail with a channel name that is the same as username', async function () {
1037 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } } 1004 const source = { username: 'super_user', channel: { name: 'super_user', displayName: 'display name' } }
1038 const fields = immutableAssign(baseCorrectParams, source) 1005 const fields = { ...baseCorrectParams, ...source }
1039 1006
1040 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields }) 1007 await makePostBodyRequest({ url: server.url, path: registrationPath, token: server.accessToken, fields })
1041 }) 1008 })
1042 1009
1043 it('Should fail with an existing channel', async function () { 1010 it('Should fail with an existing channel', async function () {
1044 const videoChannelAttributesArg = { name: 'existing_channel', displayName: 'hello', description: 'super description' } 1011 const attributes = { name: 'existing_channel', displayName: 'hello', description: 'super description' }
1045 await addVideoChannel(server.url, server.accessToken, videoChannelAttributesArg) 1012 await server.channels.create({ attributes })
1046 1013
1047 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'existing_channel', displayName: 'toto' } }) 1014 const fields = { ...baseCorrectParams, channel: { name: 'existing_channel', displayName: 'toto' } }
1048 1015
1049 await makePostBodyRequest({ 1016 await makePostBodyRequest({
1050 url: server.url, 1017 url: server.url,
1051 path: registrationPath, 1018 path: registrationPath,
1052 token: server.accessToken, 1019 token: server.accessToken,
1053 fields, 1020 fields,
1054 statusCodeExpected: HttpStatusCode.CONFLICT_409 1021 expectedStatus: HttpStatusCode.CONFLICT_409
1055 }) 1022 })
1056 }) 1023 })
1057 1024
1058 it('Should succeed with the correct params', async function () { 1025 it('Should succeed with the correct params', async function () {
1059 const fields = immutableAssign(baseCorrectParams, { channel: { name: 'super_channel', displayName: 'toto' } }) 1026 const fields = { ...baseCorrectParams, channel: { name: 'super_channel', displayName: 'toto' } }
1060 1027
1061 await makePostBodyRequest({ 1028 await makePostBodyRequest({
1062 url: server.url, 1029 url: server.url,
1063 path: registrationPath, 1030 path: registrationPath,
1064 token: server.accessToken, 1031 token: server.accessToken,
1065 fields: fields, 1032 fields: fields,
1066 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 1033 expectedStatus: HttpStatusCode.NO_CONTENT_204
1067 }) 1034 })
1068 }) 1035 })
1069 1036
@@ -1079,14 +1046,14 @@ describe('Test users API validators', function () {
1079 path: registrationPath, 1046 path: registrationPath,
1080 token: serverWithRegistrationDisabled.accessToken, 1047 token: serverWithRegistrationDisabled.accessToken,
1081 fields, 1048 fields,
1082 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 1049 expectedStatus: HttpStatusCode.FORBIDDEN_403
1083 }) 1050 })
1084 }) 1051 })
1085 }) 1052 })
1086 1053
1087 describe('When registering multiple users on a server with users limit', function () { 1054 describe('When registering multiple users on a server with users limit', function () {
1088 it('Should fail when after 3 registrations', async function () { 1055 it('Should fail when after 3 registrations', async function () {
1089 await registerUser(server.url, 'user42', 'super password', HttpStatusCode.FORBIDDEN_403) 1056 await server.users.register({ username: 'user42', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
1090 }) 1057 })
1091 }) 1058 })
1092 1059
@@ -1113,7 +1080,7 @@ describe('Test users API validators', function () {
1113 path, 1080 path,
1114 token: server.accessToken, 1081 token: server.accessToken,
1115 fields, 1082 fields,
1116 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 1083 expectedStatus: HttpStatusCode.NO_CONTENT_204
1117 }) 1084 })
1118 }) 1085 })
1119 }) 1086 })
@@ -1141,7 +1108,7 @@ describe('Test users API validators', function () {
1141 path, 1108 path,
1142 token: server.accessToken, 1109 token: server.accessToken,
1143 fields, 1110 fields,
1144 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 1111 expectedStatus: HttpStatusCode.NO_CONTENT_204
1145 }) 1112 })
1146 }) 1113 })
1147 }) 1114 })
diff --git a/server/tests/api/check-params/video-blacklist.ts b/server/tests/api/check-params/video-blacklist.ts
index ce7f5fa17..d28c6a952 100644
--- a/server/tests/api/check-params/video-blacklist.ts
+++ b/server/tests/api/check-params/video-blacklist.ts
@@ -1,46 +1,37 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4 4import { expect } from 'chai'
5import { 5import {
6 BlacklistCommand,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
6 cleanupTests, 10 cleanupTests,
7 createUser, 11 createMultipleServers,
8 doubleFollow, 12 doubleFollow,
9 flushAndRunMultipleServers,
10 getBlacklistedVideosList,
11 getVideo,
12 getVideoWithToken,
13 makePostBodyRequest, 13 makePostBodyRequest,
14 makePutBodyRequest, 14 makePutBodyRequest,
15 removeVideoFromBlacklist, 15 PeerTubeServer,
16 ServerInfo,
17 setAccessTokensToServers, 16 setAccessTokensToServers,
18 uploadVideo,
19 userLogin,
20 waitJobs 17 waitJobs
21} from '../../../../shared/extra-utils' 18} from '@shared/extra-utils'
22import { 19import { HttpStatusCode, VideoBlacklistType } from '@shared/models'
23 checkBadCountPagination,
24 checkBadSortPagination,
25 checkBadStartPagination
26} from '../../../../shared/extra-utils/requests/check-api-params'
27import { VideoBlacklistType, VideoDetails } from '../../../../shared/models/videos'
28import { expect } from 'chai'
29import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
30 20
31describe('Test video blacklist API validators', function () { 21describe('Test video blacklist API validators', function () {
32 let servers: ServerInfo[] 22 let servers: PeerTubeServer[]
33 let notBlacklistedVideoId: number 23 let notBlacklistedVideoId: string
34 let remoteVideoUUID: string 24 let remoteVideoUUID: string
35 let userAccessToken1 = '' 25 let userAccessToken1 = ''
36 let userAccessToken2 = '' 26 let userAccessToken2 = ''
27 let command: BlacklistCommand
37 28
38 // --------------------------------------------------------------- 29 // ---------------------------------------------------------------
39 30
40 before(async function () { 31 before(async function () {
41 this.timeout(120000) 32 this.timeout(120000)
42 33
43 servers = await flushAndRunMultipleServers(2) 34 servers = await createMultipleServers(2)
44 35
45 await setAccessTokensToServers(servers) 36 await setAccessTokensToServers(servers)
46 await doubleFollow(servers[0], servers[1]) 37 await doubleFollow(servers[0], servers[1])
@@ -48,40 +39,41 @@ describe('Test video blacklist API validators', function () {
48 { 39 {
49 const username = 'user1' 40 const username = 'user1'
50 const password = 'my super password' 41 const password = 'my super password'
51 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) 42 await servers[0].users.create({ username: username, password: password })
52 userAccessToken1 = await userLogin(servers[0], { username, password }) 43 userAccessToken1 = await servers[0].login.getAccessToken({ username, password })
53 } 44 }
54 45
55 { 46 {
56 const username = 'user2' 47 const username = 'user2'
57 const password = 'my super password' 48 const password = 'my super password'
58 await createUser({ url: servers[0].url, accessToken: servers[0].accessToken, username: username, password: password }) 49 await servers[0].users.create({ username: username, password: password })
59 userAccessToken2 = await userLogin(servers[0], { username, password }) 50 userAccessToken2 = await servers[0].login.getAccessToken({ username, password })
60 } 51 }
61 52
62 { 53 {
63 const res = await uploadVideo(servers[0].url, userAccessToken1, {}) 54 servers[0].store.video = await servers[0].videos.upload({ token: userAccessToken1 })
64 servers[0].video = res.body.video
65 } 55 }
66 56
67 { 57 {
68 const res = await uploadVideo(servers[0].url, servers[0].accessToken, {}) 58 const { uuid } = await servers[0].videos.upload()
69 notBlacklistedVideoId = res.body.video.uuid 59 notBlacklistedVideoId = uuid
70 } 60 }
71 61
72 { 62 {
73 const res = await uploadVideo(servers[1].url, servers[1].accessToken, {}) 63 const { uuid } = await servers[1].videos.upload()
74 remoteVideoUUID = res.body.video.uuid 64 remoteVideoUUID = uuid
75 } 65 }
76 66
77 await waitJobs(servers) 67 await waitJobs(servers)
68
69 command = servers[0].blacklist
78 }) 70 })
79 71
80 describe('When adding a video in blacklist', function () { 72 describe('When adding a video in blacklist', function () {
81 const basePath = '/api/v1/videos/' 73 const basePath = '/api/v1/videos/'
82 74
83 it('Should fail with nothing', async function () { 75 it('Should fail with nothing', async function () {
84 const path = basePath + servers[0].video + '/blacklist' 76 const path = basePath + servers[0].store.video + '/blacklist'
85 const fields = {} 77 const fields = {}
86 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) 78 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
87 }) 79 })
@@ -93,25 +85,25 @@ describe('Test video blacklist API validators', function () {
93 }) 85 })
94 86
95 it('Should fail with a non authenticated user', async function () { 87 it('Should fail with a non authenticated user', async function () {
96 const path = basePath + servers[0].video + '/blacklist' 88 const path = basePath + servers[0].store.video + '/blacklist'
97 const fields = {} 89 const fields = {}
98 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 90 await makePostBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
99 }) 91 })
100 92
101 it('Should fail with a non admin user', async function () { 93 it('Should fail with a non admin user', async function () {
102 const path = basePath + servers[0].video + '/blacklist' 94 const path = basePath + servers[0].store.video + '/blacklist'
103 const fields = {} 95 const fields = {}
104 await makePostBodyRequest({ 96 await makePostBodyRequest({
105 url: servers[0].url, 97 url: servers[0].url,
106 path, 98 path,
107 token: userAccessToken2, 99 token: userAccessToken2,
108 fields, 100 fields,
109 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 101 expectedStatus: HttpStatusCode.FORBIDDEN_403
110 }) 102 })
111 }) 103 })
112 104
113 it('Should fail with an invalid reason', async function () { 105 it('Should fail with an invalid reason', async function () {
114 const path = basePath + servers[0].video.uuid + '/blacklist' 106 const path = basePath + servers[0].store.video.uuid + '/blacklist'
115 const fields = { reason: 'a'.repeat(305) } 107 const fields = { reason: 'a'.repeat(305) }
116 108
117 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) 109 await makePostBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
@@ -126,12 +118,12 @@ describe('Test video blacklist API validators', function () {
126 path, 118 path,
127 token: servers[0].accessToken, 119 token: servers[0].accessToken,
128 fields, 120 fields,
129 statusCodeExpected: HttpStatusCode.CONFLICT_409 121 expectedStatus: HttpStatusCode.CONFLICT_409
130 }) 122 })
131 }) 123 })
132 124
133 it('Should succeed with the correct params', async function () { 125 it('Should succeed with the correct params', async function () {
134 const path = basePath + servers[0].video.uuid + '/blacklist' 126 const path = basePath + servers[0].store.video.uuid + '/blacklist'
135 const fields = {} 127 const fields = {}
136 128
137 await makePostBodyRequest({ 129 await makePostBodyRequest({
@@ -139,7 +131,7 @@ describe('Test video blacklist API validators', function () {
139 path, 131 path,
140 token: servers[0].accessToken, 132 token: servers[0].accessToken,
141 fields, 133 fields,
142 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 134 expectedStatus: HttpStatusCode.NO_CONTENT_204
143 }) 135 })
144 }) 136 })
145 }) 137 })
@@ -161,37 +153,37 @@ describe('Test video blacklist API validators', function () {
161 path, 153 path,
162 token: servers[0].accessToken, 154 token: servers[0].accessToken,
163 fields, 155 fields,
164 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 156 expectedStatus: HttpStatusCode.NOT_FOUND_404
165 }) 157 })
166 }) 158 })
167 159
168 it('Should fail with a non authenticated user', async function () { 160 it('Should fail with a non authenticated user', async function () {
169 const path = basePath + servers[0].video + '/blacklist' 161 const path = basePath + servers[0].store.video + '/blacklist'
170 const fields = {} 162 const fields = {}
171 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 163 await makePutBodyRequest({ url: servers[0].url, path, token: 'hello', fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
172 }) 164 })
173 165
174 it('Should fail with a non admin user', async function () { 166 it('Should fail with a non admin user', async function () {
175 const path = basePath + servers[0].video + '/blacklist' 167 const path = basePath + servers[0].store.video + '/blacklist'
176 const fields = {} 168 const fields = {}
177 await makePutBodyRequest({ 169 await makePutBodyRequest({
178 url: servers[0].url, 170 url: servers[0].url,
179 path, 171 path,
180 token: userAccessToken2, 172 token: userAccessToken2,
181 fields, 173 fields,
182 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 174 expectedStatus: HttpStatusCode.FORBIDDEN_403
183 }) 175 })
184 }) 176 })
185 177
186 it('Should fail with an invalid reason', async function () { 178 it('Should fail with an invalid reason', async function () {
187 const path = basePath + servers[0].video.uuid + '/blacklist' 179 const path = basePath + servers[0].store.video.uuid + '/blacklist'
188 const fields = { reason: 'a'.repeat(305) } 180 const fields = { reason: 'a'.repeat(305) }
189 181
190 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields }) 182 await makePutBodyRequest({ url: servers[0].url, path, token: servers[0].accessToken, fields })
191 }) 183 })
192 184
193 it('Should succeed with the correct params', async function () { 185 it('Should succeed with the correct params', async function () {
194 const path = basePath + servers[0].video.shortUUID + '/blacklist' 186 const path = basePath + servers[0].store.video.shortUUID + '/blacklist'
195 const fields = { reason: 'hello' } 187 const fields = { reason: 'hello' }
196 188
197 await makePutBodyRequest({ 189 await makePutBodyRequest({
@@ -199,7 +191,7 @@ describe('Test video blacklist API validators', function () {
199 path, 191 path,
200 token: servers[0].accessToken, 192 token: servers[0].accessToken,
201 fields, 193 fields,
202 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 194 expectedStatus: HttpStatusCode.NO_CONTENT_204
203 }) 195 })
204 }) 196 })
205 }) 197 })
@@ -207,52 +199,53 @@ describe('Test video blacklist API validators', function () {
207 describe('When getting blacklisted video', function () { 199 describe('When getting blacklisted video', function () {
208 200
209 it('Should fail with a non authenticated user', async function () { 201 it('Should fail with a non authenticated user', async function () {
210 await getVideo(servers[0].url, servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) 202 await servers[0].videos.get({ id: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
211 }) 203 })
212 204
213 it('Should fail with another user', async function () { 205 it('Should fail with another user', async function () {
214 await getVideoWithToken(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) 206 await servers[0].videos.getWithToken({
207 token: userAccessToken2,
208 id: servers[0].store.video.uuid,
209 expectedStatus: HttpStatusCode.FORBIDDEN_403
210 })
215 }) 211 })
216 212
217 it('Should succeed with the owner authenticated user', async function () { 213 it('Should succeed with the owner authenticated user', async function () {
218 const res = await getVideoWithToken(servers[0].url, userAccessToken1, servers[0].video.uuid, HttpStatusCode.OK_200) 214 const video = await servers[0].videos.getWithToken({ token: userAccessToken1, id: servers[0].store.video.uuid })
219 const video: VideoDetails = res.body
220
221 expect(video.blacklisted).to.be.true 215 expect(video.blacklisted).to.be.true
222 }) 216 })
223 217
224 it('Should succeed with an admin', async function () { 218 it('Should succeed with an admin', async function () {
225 const video = servers[0].video 219 const video = servers[0].store.video
226 220
227 for (const id of [ video.id, video.uuid, video.shortUUID ]) { 221 for (const id of [ video.id, video.uuid, video.shortUUID ]) {
228 const res = await getVideoWithToken(servers[0].url, servers[0].accessToken, id, HttpStatusCode.OK_200) 222 const video = await servers[0].videos.getWithToken({ id, expectedStatus: HttpStatusCode.OK_200 })
229 const video: VideoDetails = res.body
230
231 expect(video.blacklisted).to.be.true 223 expect(video.blacklisted).to.be.true
232 } 224 }
233 }) 225 })
234 }) 226 })
235 227
236 describe('When removing a video in blacklist', function () { 228 describe('When removing a video in blacklist', function () {
229
237 it('Should fail with a non authenticated user', async function () { 230 it('Should fail with a non authenticated user', async function () {
238 await removeVideoFromBlacklist(servers[0].url, 'fake token', servers[0].video.uuid, HttpStatusCode.UNAUTHORIZED_401) 231 await command.remove({ token: 'fake token', videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
239 }) 232 })
240 233
241 it('Should fail with a non admin user', async function () { 234 it('Should fail with a non admin user', async function () {
242 await removeVideoFromBlacklist(servers[0].url, userAccessToken2, servers[0].video.uuid, HttpStatusCode.FORBIDDEN_403) 235 await command.remove({ token: userAccessToken2, videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
243 }) 236 })
244 237
245 it('Should fail with an incorrect id', async function () { 238 it('Should fail with an incorrect id', async function () {
246 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) 239 await command.remove({ videoId: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
247 }) 240 })
248 241
249 it('Should fail with a not blacklisted video', async function () { 242 it('Should fail with a not blacklisted video', async function () {
250 // The video was not added to the blacklist so it should fail 243 // The video was not added to the blacklist so it should fail
251 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, notBlacklistedVideoId, HttpStatusCode.NOT_FOUND_404) 244 await command.remove({ videoId: notBlacklistedVideoId, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
252 }) 245 })
253 246
254 it('Should succeed with the correct params', async function () { 247 it('Should succeed with the correct params', async function () {
255 await removeVideoFromBlacklist(servers[0].url, servers[0].accessToken, servers[0].video.uuid, HttpStatusCode.NO_CONTENT_204) 248 await command.remove({ videoId: servers[0].store.video.uuid, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
256 }) 249 })
257 }) 250 })
258 251
@@ -260,11 +253,11 @@ describe('Test video blacklist API validators', function () {
260 const basePath = '/api/v1/videos/blacklist/' 253 const basePath = '/api/v1/videos/blacklist/'
261 254
262 it('Should fail with a non authenticated user', async function () { 255 it('Should fail with a non authenticated user', async function () {
263 await getBlacklistedVideosList({ url: servers[0].url, token: 'fake token', specialStatus: HttpStatusCode.UNAUTHORIZED_401 }) 256 await servers[0].blacklist.list({ token: 'fake token', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
264 }) 257 })
265 258
266 it('Should fail with a non admin user', async function () { 259 it('Should fail with a non admin user', async function () {
267 await getBlacklistedVideosList({ url: servers[0].url, token: userAccessToken2, specialStatus: HttpStatusCode.FORBIDDEN_403 }) 260 await servers[0].blacklist.list({ token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
268 }) 261 })
269 262
270 it('Should fail with a bad start pagination', async function () { 263 it('Should fail with a bad start pagination', async function () {
@@ -280,16 +273,11 @@ describe('Test video blacklist API validators', function () {
280 }) 273 })
281 274
282 it('Should fail with an invalid type', async function () { 275 it('Should fail with an invalid type', async function () {
283 await getBlacklistedVideosList({ 276 await servers[0].blacklist.list({ type: 0, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
284 url: servers[0].url,
285 token: servers[0].accessToken,
286 type: 0,
287 specialStatus: HttpStatusCode.BAD_REQUEST_400
288 })
289 }) 277 })
290 278
291 it('Should succeed with the correct parameters', async function () { 279 it('Should succeed with the correct parameters', async function () {
292 await getBlacklistedVideosList({ url: servers[0].url, token: servers[0].accessToken, type: VideoBlacklistType.MANUAL }) 280 await servers[0].blacklist.list({ type: VideoBlacklistType.MANUAL })
293 }) 281 })
294 }) 282 })
295 283
diff --git a/server/tests/api/check-params/video-captions.ts b/server/tests/api/check-params/video-captions.ts
index c0595c04d..90f429314 100644
--- a/server/tests/api/check-params/video-captions.ts
+++ b/server/tests/api/check-params/video-captions.ts
@@ -1,27 +1,22 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { VideoCreateResult } from '@shared/models'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 4import {
7 buildAbsoluteFixturePath, 5 buildAbsoluteFixturePath,
8 cleanupTests, 6 cleanupTests,
9 createUser, 7 createSingleServer,
10 flushAndRunServer,
11 makeDeleteRequest, 8 makeDeleteRequest,
12 makeGetRequest, 9 makeGetRequest,
13 makeUploadRequest, 10 makeUploadRequest,
14 ServerInfo, 11 PeerTubeServer,
15 setAccessTokensToServers, 12 setAccessTokensToServers
16 uploadVideo, 13} from '@shared/extra-utils'
17 userLogin 14import { HttpStatusCode, VideoCreateResult } from '@shared/models'
18} from '../../../../shared/extra-utils'
19import { createVideoCaption } from '../../../../shared/extra-utils/videos/video-captions'
20 15
21describe('Test video captions API validator', function () { 16describe('Test video captions API validator', function () {
22 const path = '/api/v1/videos/' 17 const path = '/api/v1/videos/'
23 18
24 let server: ServerInfo 19 let server: PeerTubeServer
25 let userAccessToken: string 20 let userAccessToken: string
26 let video: VideoCreateResult 21 let video: VideoCreateResult
27 22
@@ -30,22 +25,19 @@ describe('Test video captions API validator', function () {
30 before(async function () { 25 before(async function () {
31 this.timeout(30000) 26 this.timeout(30000)
32 27
33 server = await flushAndRunServer(1) 28 server = await createSingleServer(1)
34 29
35 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
36 31
37 { 32 video = await server.videos.upload()
38 const res = await uploadVideo(server.url, server.accessToken, {})
39 video = res.body.video
40 }
41 33
42 { 34 {
43 const user = { 35 const user = {
44 username: 'user1', 36 username: 'user1',
45 password: 'my super password' 37 password: 'my super password'
46 } 38 }
47 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 39 await server.users.create({ username: user.username, password: user.password })
48 userAccessToken = await userLogin(server, user) 40 userAccessToken = await server.login.getAccessToken(user)
49 } 41 }
50 }) 42 })
51 43
@@ -74,7 +66,7 @@ describe('Test video captions API validator', function () {
74 token: server.accessToken, 66 token: server.accessToken,
75 fields, 67 fields,
76 attaches, 68 attaches,
77 statusCodeExpected: 404 69 expectedStatus: 404
78 }) 70 })
79 }) 71 })
80 72
@@ -110,7 +102,7 @@ describe('Test video captions API validator', function () {
110 path: captionPath, 102 path: captionPath,
111 fields, 103 fields,
112 attaches, 104 attaches,
113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 105 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
114 }) 106 })
115 }) 107 })
116 108
@@ -123,7 +115,7 @@ describe('Test video captions API validator', function () {
123 token: 'blabla', 115 token: 'blabla',
124 fields, 116 fields,
125 attaches, 117 attaches,
126 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 118 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
127 }) 119 })
128 }) 120 })
129 121
@@ -141,7 +133,7 @@ describe('Test video captions API validator', function () {
141 // token: server.accessToken, 133 // token: server.accessToken,
142 // fields, 134 // fields,
143 // attaches, 135 // attaches,
144 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 136 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
145 // }) 137 // })
146 // }) 138 // })
147 139
@@ -154,14 +146,12 @@ describe('Test video captions API validator', function () {
154 // videoId: video.uuid, 146 // videoId: video.uuid,
155 // fixture: 'subtitle-bad.txt', 147 // fixture: 'subtitle-bad.txt',
156 // mimeType: 'application/octet-stream', 148 // mimeType: 'application/octet-stream',
157 // statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 149 // expectedStatus: HttpStatusCode.BAD_REQUEST_400
158 // }) 150 // })
159 // }) 151 // })
160 152
161 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () { 153 it('Should succeed with a valid captionfile extension and octet-stream mime type', async function () {
162 await createVideoCaption({ 154 await server.captions.add({
163 url: server.url,
164 accessToken: server.accessToken,
165 language: 'zh', 155 language: 'zh',
166 videoId: video.uuid, 156 videoId: video.uuid,
167 fixture: 'subtitle-good.srt', 157 fixture: 'subtitle-good.srt',
@@ -183,7 +173,7 @@ describe('Test video captions API validator', function () {
183 // token: server.accessToken, 173 // token: server.accessToken,
184 // fields, 174 // fields,
185 // attaches, 175 // attaches,
186 // statusCodeExpected: HttpStatusCode.INTERNAL_SERVER_ERROR_500 176 // expectedStatus: HttpStatusCode.INTERNAL_SERVER_ERROR_500
187 // }) 177 // })
188 // }) 178 // })
189 179
@@ -196,7 +186,7 @@ describe('Test video captions API validator', function () {
196 token: server.accessToken, 186 token: server.accessToken,
197 fields, 187 fields,
198 attaches, 188 attaches,
199 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 189 expectedStatus: HttpStatusCode.NO_CONTENT_204
200 }) 190 })
201 }) 191 })
202 }) 192 })
@@ -210,12 +200,12 @@ describe('Test video captions API validator', function () {
210 await makeGetRequest({ 200 await makeGetRequest({
211 url: server.url, 201 url: server.url,
212 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions', 202 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions',
213 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 203 expectedStatus: HttpStatusCode.NOT_FOUND_404
214 }) 204 })
215 }) 205 })
216 206
217 it('Should success with the correct parameters', async function () { 207 it('Should success with the correct parameters', async function () {
218 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', statusCodeExpected: HttpStatusCode.OK_200 }) 208 await makeGetRequest({ url: server.url, path: path + video.shortUUID + '/captions', expectedStatus: HttpStatusCode.OK_200 })
219 }) 209 })
220 }) 210 })
221 211
@@ -233,7 +223,7 @@ describe('Test video captions API validator', function () {
233 url: server.url, 223 url: server.url,
234 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr', 224 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/captions/fr',
235 token: server.accessToken, 225 token: server.accessToken,
236 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 226 expectedStatus: HttpStatusCode.NOT_FOUND_404
237 }) 227 })
238 }) 228 })
239 229
@@ -257,12 +247,12 @@ describe('Test video captions API validator', function () {
257 247
258 it('Should fail without access token', async function () { 248 it('Should fail without access token', async function () {
259 const captionPath = path + video.shortUUID + '/captions/fr' 249 const captionPath = path + video.shortUUID + '/captions/fr'
260 await makeDeleteRequest({ url: server.url, path: captionPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 250 await makeDeleteRequest({ url: server.url, path: captionPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
261 }) 251 })
262 252
263 it('Should fail with a bad access token', async function () { 253 it('Should fail with a bad access token', async function () {
264 const captionPath = path + video.shortUUID + '/captions/fr' 254 const captionPath = path + video.shortUUID + '/captions/fr'
265 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 255 await makeDeleteRequest({ url: server.url, path: captionPath, token: 'coucou', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
266 }) 256 })
267 257
268 it('Should fail with another user', async function () { 258 it('Should fail with another user', async function () {
@@ -271,7 +261,7 @@ describe('Test video captions API validator', function () {
271 url: server.url, 261 url: server.url,
272 path: captionPath, 262 path: captionPath,
273 token: userAccessToken, 263 token: userAccessToken,
274 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 264 expectedStatus: HttpStatusCode.FORBIDDEN_403
275 }) 265 })
276 }) 266 })
277 267
@@ -281,7 +271,7 @@ describe('Test video captions API validator', function () {
281 url: server.url, 271 url: server.url,
282 path: captionPath, 272 path: captionPath,
283 token: server.accessToken, 273 token: server.accessToken,
284 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 274 expectedStatus: HttpStatusCode.NO_CONTENT_204
285 }) 275 })
286 }) 276 })
287 }) 277 })
diff --git a/server/tests/api/check-params/video-channels.ts b/server/tests/api/check-params/video-channels.ts
index 5c02afd31..2e63916d4 100644
--- a/server/tests/api/check-params/video-channels.ts
+++ b/server/tests/api/check-params/video-channels.ts
@@ -3,43 +3,37 @@
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 6import {
8 buildAbsoluteFixturePath, 7 buildAbsoluteFixturePath,
8 ChannelsCommand,
9 checkBadCountPagination,
10 checkBadSortPagination,
11 checkBadStartPagination,
9 cleanupTests, 12 cleanupTests,
10 createUser, 13 createSingleServer,
11 deleteVideoChannel,
12 flushAndRunServer,
13 getAccountVideoChannelsList,
14 immutableAssign,
15 makeGetRequest, 14 makeGetRequest,
16 makePostBodyRequest, 15 makePostBodyRequest,
17 makePutBodyRequest, 16 makePutBodyRequest,
18 makeUploadRequest, 17 makeUploadRequest,
19 ServerInfo, 18 PeerTubeServer,
20 setAccessTokensToServers, 19 setAccessTokensToServers
21 userLogin 20} from '@shared/extra-utils'
22} from '../../../../shared/extra-utils' 21import { HttpStatusCode, VideoChannelUpdate } from '@shared/models'
23import {
24 checkBadCountPagination,
25 checkBadSortPagination,
26 checkBadStartPagination
27} from '../../../../shared/extra-utils/requests/check-api-params'
28import { VideoChannelUpdate } from '../../../../shared/models/videos'
29 22
30const expect = chai.expect 23const expect = chai.expect
31 24
32describe('Test video channels API validator', function () { 25describe('Test video channels API validator', function () {
33 const videoChannelPath = '/api/v1/video-channels' 26 const videoChannelPath = '/api/v1/video-channels'
34 let server: ServerInfo 27 let server: PeerTubeServer
35 let accessTokenUser: string 28 let accessTokenUser: string
29 let command: ChannelsCommand
36 30
37 // --------------------------------------------------------------- 31 // ---------------------------------------------------------------
38 32
39 before(async function () { 33 before(async function () {
40 this.timeout(30000) 34 this.timeout(30000)
41 35
42 server = await flushAndRunServer(1) 36 server = await createSingleServer(1)
43 37
44 await setAccessTokensToServers([ server ]) 38 await setAccessTokensToServers([ server ])
45 39
@@ -49,9 +43,11 @@ describe('Test video channels API validator', function () {
49 } 43 }
50 44
51 { 45 {
52 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 46 await server.users.create({ username: user.username, password: user.password })
53 accessTokenUser = await userLogin(server, user) 47 accessTokenUser = await server.login.getAccessToken(user)
54 } 48 }
49
50 command = server.channels
55 }) 51 })
56 52
57 describe('When listing a video channels', function () { 53 describe('When listing a video channels', function () {
@@ -84,14 +80,14 @@ describe('Test video channels API validator', function () {
84 }) 80 })
85 81
86 it('Should fail with a unknown account', async function () { 82 it('Should fail with a unknown account', async function () {
87 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: HttpStatusCode.NOT_FOUND_404 }) 83 await server.channels.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
88 }) 84 })
89 85
90 it('Should succeed with the correct parameters', async function () { 86 it('Should succeed with the correct parameters', async function () {
91 await makeGetRequest({ 87 await makeGetRequest({
92 url: server.url, 88 url: server.url,
93 path: accountChannelPath, 89 path: accountChannelPath,
94 statusCodeExpected: HttpStatusCode.OK_200 90 expectedStatus: HttpStatusCode.OK_200
95 }) 91 })
96 }) 92 })
97 }) 93 })
@@ -110,7 +106,7 @@ describe('Test video channels API validator', function () {
110 path: videoChannelPath, 106 path: videoChannelPath,
111 token: 'none', 107 token: 'none',
112 fields: baseCorrectParams, 108 fields: baseCorrectParams,
113 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 109 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
114 }) 110 })
115 }) 111 })
116 112
@@ -125,7 +121,7 @@ describe('Test video channels API validator', function () {
125 }) 121 })
126 122
127 it('Should fail with a bad name', async function () { 123 it('Should fail with a bad name', async function () {
128 const fields = immutableAssign(baseCorrectParams, { name: 'super name' }) 124 const fields = { ...baseCorrectParams, name: 'super name' }
129 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 125 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
130 }) 126 })
131 127
@@ -135,17 +131,17 @@ describe('Test video channels API validator', function () {
135 }) 131 })
136 132
137 it('Should fail with a long name', async function () { 133 it('Should fail with a long name', async function () {
138 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) 134 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
139 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 135 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
140 }) 136 })
141 137
142 it('Should fail with a long description', async function () { 138 it('Should fail with a long description', async function () {
143 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) 139 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
144 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 140 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
145 }) 141 })
146 142
147 it('Should fail with a long support text', async function () { 143 it('Should fail with a long support text', async function () {
148 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 144 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
149 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) 145 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
150 }) 146 })
151 147
@@ -155,7 +151,7 @@ describe('Test video channels API validator', function () {
155 path: videoChannelPath, 151 path: videoChannelPath,
156 token: server.accessToken, 152 token: server.accessToken,
157 fields: baseCorrectParams, 153 fields: baseCorrectParams,
158 statusCodeExpected: HttpStatusCode.OK_200 154 expectedStatus: HttpStatusCode.OK_200
159 }) 155 })
160 }) 156 })
161 157
@@ -165,7 +161,7 @@ describe('Test video channels API validator', function () {
165 path: videoChannelPath, 161 path: videoChannelPath,
166 token: server.accessToken, 162 token: server.accessToken,
167 fields: baseCorrectParams, 163 fields: baseCorrectParams,
168 statusCodeExpected: HttpStatusCode.CONFLICT_409 164 expectedStatus: HttpStatusCode.CONFLICT_409
169 }) 165 })
170 }) 166 })
171 }) 167 })
@@ -189,7 +185,7 @@ describe('Test video channels API validator', function () {
189 path, 185 path,
190 token: 'hi', 186 token: 'hi',
191 fields: baseCorrectParams, 187 fields: baseCorrectParams,
192 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 188 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
193 }) 189 })
194 }) 190 })
195 191
@@ -199,27 +195,27 @@ describe('Test video channels API validator', function () {
199 path, 195 path,
200 token: accessTokenUser, 196 token: accessTokenUser,
201 fields: baseCorrectParams, 197 fields: baseCorrectParams,
202 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 198 expectedStatus: HttpStatusCode.FORBIDDEN_403
203 }) 199 })
204 }) 200 })
205 201
206 it('Should fail with a long name', async function () { 202 it('Should fail with a long name', async function () {
207 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) }) 203 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
208 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 204 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
209 }) 205 })
210 206
211 it('Should fail with a long description', async function () { 207 it('Should fail with a long description', async function () {
212 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) }) 208 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
213 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 209 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
214 }) 210 })
215 211
216 it('Should fail with a long support text', async function () { 212 it('Should fail with a long support text', async function () {
217 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 213 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
218 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 214 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
219 }) 215 })
220 216
221 it('Should fail with a bad bulkVideosSupportUpdate field', async function () { 217 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
222 const fields = immutableAssign(baseCorrectParams, { bulkVideosSupportUpdate: 'super' }) 218 const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' }
223 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 219 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
224 }) 220 })
225 221
@@ -229,7 +225,7 @@ describe('Test video channels API validator', function () {
229 path, 225 path,
230 token: server.accessToken, 226 token: server.accessToken,
231 fields: baseCorrectParams, 227 fields: baseCorrectParams,
232 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 228 expectedStatus: HttpStatusCode.NO_CONTENT_204
233 }) 229 })
234 }) 230 })
235 }) 231 })
@@ -274,7 +270,7 @@ describe('Test video channels API validator', function () {
274 path: `${path}/${type}/pick`, 270 path: `${path}/${type}/pick`,
275 fields, 271 fields,
276 attaches, 272 attaches,
277 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 273 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
278 }) 274 })
279 } 275 }
280 }) 276 })
@@ -291,7 +287,7 @@ describe('Test video channels API validator', function () {
291 token: server.accessToken, 287 token: server.accessToken,
292 fields, 288 fields,
293 attaches, 289 attaches,
294 statusCodeExpected: HttpStatusCode.OK_200 290 expectedStatus: HttpStatusCode.OK_200
295 }) 291 })
296 } 292 }
297 }) 293 })
@@ -302,7 +298,7 @@ describe('Test video channels API validator', function () {
302 const res = await makeGetRequest({ 298 const res = await makeGetRequest({
303 url: server.url, 299 url: server.url,
304 path: videoChannelPath, 300 path: videoChannelPath,
305 statusCodeExpected: HttpStatusCode.OK_200 301 expectedStatus: HttpStatusCode.OK_200
306 }) 302 })
307 303
308 expect(res.body.data).to.be.an('array') 304 expect(res.body.data).to.be.an('array')
@@ -312,7 +308,7 @@ describe('Test video channels API validator', function () {
312 await makeGetRequest({ 308 await makeGetRequest({
313 url: server.url, 309 url: server.url,
314 path: videoChannelPath + '/super_channel2', 310 path: videoChannelPath + '/super_channel2',
315 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 311 expectedStatus: HttpStatusCode.NOT_FOUND_404
316 }) 312 })
317 }) 313 })
318 314
@@ -320,30 +316,30 @@ describe('Test video channels API validator', function () {
320 await makeGetRequest({ 316 await makeGetRequest({
321 url: server.url, 317 url: server.url,
322 path: videoChannelPath + '/super_channel', 318 path: videoChannelPath + '/super_channel',
323 statusCodeExpected: HttpStatusCode.OK_200 319 expectedStatus: HttpStatusCode.OK_200
324 }) 320 })
325 }) 321 })
326 }) 322 })
327 323
328 describe('When deleting a video channel', function () { 324 describe('When deleting a video channel', function () {
329 it('Should fail with a non authenticated user', async function () { 325 it('Should fail with a non authenticated user', async function () {
330 await deleteVideoChannel(server.url, 'coucou', 'super_channel', HttpStatusCode.UNAUTHORIZED_401) 326 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
331 }) 327 })
332 328
333 it('Should fail with another authenticated user', async function () { 329 it('Should fail with another authenticated user', async function () {
334 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', HttpStatusCode.FORBIDDEN_403) 330 await command.delete({ token: accessTokenUser, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
335 }) 331 })
336 332
337 it('Should fail with an unknown video channel id', async function () { 333 it('Should fail with an unknown video channel id', async function () {
338 await deleteVideoChannel(server.url, server.accessToken, 'super_channel2', HttpStatusCode.NOT_FOUND_404) 334 await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
339 }) 335 })
340 336
341 it('Should succeed with the correct parameters', async function () { 337 it('Should succeed with the correct parameters', async function () {
342 await deleteVideoChannel(server.url, server.accessToken, 'super_channel') 338 await command.delete({ channelName: 'super_channel' })
343 }) 339 })
344 340
345 it('Should fail to delete the last user video channel', async function () { 341 it('Should fail to delete the last user video channel', async function () {
346 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', HttpStatusCode.CONFLICT_409) 342 await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
347 }) 343 })
348 }) 344 })
349 345
diff --git a/server/tests/api/check-params/video-comments.ts b/server/tests/api/check-params/video-comments.ts
index a38420851..2d9ee1e0d 100644
--- a/server/tests/api/check-params/video-comments.ts
+++ b/server/tests/api/check-params/video-comments.ts
@@ -2,33 +2,26 @@
2 2
3import 'mocha' 3import 'mocha'
4import * as chai from 'chai' 4import * as chai from 'chai'
5import { VideoCreateResult } from '@shared/models'
6import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
7import { 5import {
6 checkBadCountPagination,
7 checkBadSortPagination,
8 checkBadStartPagination,
8 cleanupTests, 9 cleanupTests,
9 createUser, 10 createSingleServer,
10 flushAndRunServer,
11 makeDeleteRequest, 11 makeDeleteRequest,
12 makeGetRequest, 12 makeGetRequest,
13 makePostBodyRequest, 13 makePostBodyRequest,
14 ServerInfo, 14 PeerTubeServer,
15 setAccessTokensToServers, 15 setAccessTokensToServers
16 uploadVideo, 16} from '@shared/extra-utils'
17 userLogin 17import { HttpStatusCode, VideoCreateResult } from '@shared/models'
18} from '../../../../shared/extra-utils'
19import {
20 checkBadCountPagination,
21 checkBadSortPagination,
22 checkBadStartPagination
23} from '../../../../shared/extra-utils/requests/check-api-params'
24import { addVideoCommentThread } from '../../../../shared/extra-utils/videos/video-comments'
25 18
26const expect = chai.expect 19const expect = chai.expect
27 20
28describe('Test video comments API validator', function () { 21describe('Test video comments API validator', function () {
29 let pathThread: string 22 let pathThread: string
30 let pathComment: string 23 let pathComment: string
31 let server: ServerInfo 24 let server: PeerTubeServer
32 let video: VideoCreateResult 25 let video: VideoCreateResult
33 let userAccessToken: string 26 let userAccessToken: string
34 let userAccessToken2: string 27 let userAccessToken2: string
@@ -39,32 +32,31 @@ describe('Test video comments API validator', function () {
39 before(async function () { 32 before(async function () {
40 this.timeout(30000) 33 this.timeout(30000)
41 34
42 server = await flushAndRunServer(1) 35 server = await createSingleServer(1)
43 36
44 await setAccessTokensToServers([ server ]) 37 await setAccessTokensToServers([ server ])
45 38
46 { 39 {
47 const res = await uploadVideo(server.url, server.accessToken, {}) 40 video = await server.videos.upload({ attributes: {} })
48 video = res.body.video
49 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' 41 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
50 } 42 }
51 43
52 { 44 {
53 const res = await addVideoCommentThread(server.url, server.accessToken, video.uuid, 'coucou') 45 const created = await server.comments.createThread({ videoId: video.uuid, text: 'coucou' })
54 commentId = res.body.comment.id 46 commentId = created.id
55 pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId 47 pathComment = '/api/v1/videos/' + video.uuid + '/comments/' + commentId
56 } 48 }
57 49
58 { 50 {
59 const user = { username: 'user1', password: 'my super password' } 51 const user = { username: 'user1', password: 'my super password' }
60 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 52 await server.users.create({ username: user.username, password: user.password })
61 userAccessToken = await userLogin(server, user) 53 userAccessToken = await server.login.getAccessToken(user)
62 } 54 }
63 55
64 { 56 {
65 const user = { username: 'user2', password: 'my super password' } 57 const user = { username: 'user2', password: 'my super password' }
66 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 58 await server.users.create({ username: user.username, password: user.password })
67 userAccessToken2 = await userLogin(server, user) 59 userAccessToken2 = await server.login.getAccessToken(user)
68 } 60 }
69 }) 61 })
70 62
@@ -85,7 +77,7 @@ describe('Test video comments API validator', function () {
85 await makeGetRequest({ 77 await makeGetRequest({
86 url: server.url, 78 url: server.url,
87 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads', 79 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads',
88 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 80 expectedStatus: HttpStatusCode.NOT_FOUND_404
89 }) 81 })
90 }) 82 })
91 }) 83 })
@@ -95,7 +87,7 @@ describe('Test video comments API validator', function () {
95 await makeGetRequest({ 87 await makeGetRequest({
96 url: server.url, 88 url: server.url,
97 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId, 89 path: '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comment-threads/' + commentId,
98 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 90 expectedStatus: HttpStatusCode.NOT_FOUND_404
99 }) 91 })
100 }) 92 })
101 93
@@ -103,7 +95,7 @@ describe('Test video comments API validator', function () {
103 await makeGetRequest({ 95 await makeGetRequest({
104 url: server.url, 96 url: server.url,
105 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156', 97 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/156',
106 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 98 expectedStatus: HttpStatusCode.NOT_FOUND_404
107 }) 99 })
108 }) 100 })
109 101
@@ -111,7 +103,7 @@ describe('Test video comments API validator', function () {
111 await makeGetRequest({ 103 await makeGetRequest({
112 url: server.url, 104 url: server.url,
113 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId, 105 path: '/api/v1/videos/' + video.shortUUID + '/comment-threads/' + commentId,
114 statusCodeExpected: HttpStatusCode.OK_200 106 expectedStatus: HttpStatusCode.OK_200
115 }) 107 })
116 }) 108 })
117 }) 109 })
@@ -127,7 +119,7 @@ describe('Test video comments API validator', function () {
127 path: pathThread, 119 path: pathThread,
128 token: 'none', 120 token: 'none',
129 fields, 121 fields,
130 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 122 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
131 }) 123 })
132 }) 124 })
133 125
@@ -160,7 +152,7 @@ describe('Test video comments API validator', function () {
160 path, 152 path,
161 token: server.accessToken, 153 token: server.accessToken,
162 fields, 154 fields,
163 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 155 expectedStatus: HttpStatusCode.NOT_FOUND_404
164 }) 156 })
165 }) 157 })
166 158
@@ -173,7 +165,7 @@ describe('Test video comments API validator', function () {
173 path: pathThread, 165 path: pathThread,
174 token: server.accessToken, 166 token: server.accessToken,
175 fields, 167 fields,
176 statusCodeExpected: HttpStatusCode.OK_200 168 expectedStatus: HttpStatusCode.OK_200
177 }) 169 })
178 }) 170 })
179 }) 171 })
@@ -188,7 +180,7 @@ describe('Test video comments API validator', function () {
188 path: pathComment, 180 path: pathComment,
189 token: 'none', 181 token: 'none',
190 fields, 182 fields,
191 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 183 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
192 }) 184 })
193 }) 185 })
194 186
@@ -221,7 +213,7 @@ describe('Test video comments API validator', function () {
221 path, 213 path,
222 token: server.accessToken, 214 token: server.accessToken,
223 fields, 215 fields,
224 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 216 expectedStatus: HttpStatusCode.NOT_FOUND_404
225 }) 217 })
226 }) 218 })
227 219
@@ -235,7 +227,7 @@ describe('Test video comments API validator', function () {
235 path, 227 path,
236 token: server.accessToken, 228 token: server.accessToken,
237 fields, 229 fields,
238 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 230 expectedStatus: HttpStatusCode.NOT_FOUND_404
239 }) 231 })
240 }) 232 })
241 233
@@ -248,14 +240,14 @@ describe('Test video comments API validator', function () {
248 path: pathComment, 240 path: pathComment,
249 token: server.accessToken, 241 token: server.accessToken,
250 fields, 242 fields,
251 statusCodeExpected: HttpStatusCode.OK_200 243 expectedStatus: HttpStatusCode.OK_200
252 }) 244 })
253 }) 245 })
254 }) 246 })
255 247
256 describe('When removing video comments', function () { 248 describe('When removing video comments', function () {
257 it('Should fail with a non authenticated user', async function () { 249 it('Should fail with a non authenticated user', async function () {
258 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 250 await makeDeleteRequest({ url: server.url, path: pathComment, token: 'none', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
259 }) 251 })
260 252
261 it('Should fail with another user', async function () { 253 it('Should fail with another user', async function () {
@@ -263,32 +255,32 @@ describe('Test video comments API validator', function () {
263 url: server.url, 255 url: server.url,
264 path: pathComment, 256 path: pathComment,
265 token: userAccessToken, 257 token: userAccessToken,
266 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 258 expectedStatus: HttpStatusCode.FORBIDDEN_403
267 }) 259 })
268 }) 260 })
269 261
270 it('Should fail with an incorrect video', async function () { 262 it('Should fail with an incorrect video', async function () {
271 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId 263 const path = '/api/v1/videos/ba708d62-e3d7-45d9-9d73-41b9097cc02d/comments/' + commentId
272 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 264 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
273 }) 265 })
274 266
275 it('Should fail with an incorrect comment', async function () { 267 it('Should fail with an incorrect comment', async function () {
276 const path = '/api/v1/videos/' + video.uuid + '/comments/124' 268 const path = '/api/v1/videos/' + video.uuid + '/comments/124'
277 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, statusCodeExpected: HttpStatusCode.NOT_FOUND_404 }) 269 await makeDeleteRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
278 }) 270 })
279 271
280 it('Should succeed with the same user', async function () { 272 it('Should succeed with the same user', async function () {
281 let commentToDelete: number 273 let commentToDelete: number
282 274
283 { 275 {
284 const res = await addVideoCommentThread(server.url, userAccessToken, video.uuid, 'hello') 276 const created = await server.comments.createThread({ videoId: video.uuid, token: userAccessToken, text: 'hello' })
285 commentToDelete = res.body.comment.id 277 commentToDelete = created.id
286 } 278 }
287 279
288 const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete 280 const path = '/api/v1/videos/' + video.uuid + '/comments/' + commentToDelete
289 281
290 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 282 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
291 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) 283 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
292 }) 284 })
293 285
294 it('Should succeed with the owner of the video', async function () { 286 it('Should succeed with the owner of the video', async function () {
@@ -296,19 +288,19 @@ describe('Test video comments API validator', function () {
296 let anotherVideoUUID: string 288 let anotherVideoUUID: string
297 289
298 { 290 {
299 const res = await uploadVideo(server.url, userAccessToken, { name: 'video' }) 291 const { uuid } = await server.videos.upload({ token: userAccessToken, attributes: { name: 'video' } })
300 anotherVideoUUID = res.body.video.uuid 292 anotherVideoUUID = uuid
301 } 293 }
302 294
303 { 295 {
304 const res = await addVideoCommentThread(server.url, server.accessToken, anotherVideoUUID, 'hello') 296 const created = await server.comments.createThread({ videoId: anotherVideoUUID, text: 'hello' })
305 commentToDelete = res.body.comment.id 297 commentToDelete = created.id
306 } 298 }
307 299
308 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete 300 const path = '/api/v1/videos/' + anotherVideoUUID + '/comments/' + commentToDelete
309 301
310 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, statusCodeExpected: HttpStatusCode.FORBIDDEN_403 }) 302 await makeDeleteRequest({ url: server.url, path, token: userAccessToken2, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
311 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, statusCodeExpected: HttpStatusCode.NO_CONTENT_204 }) 303 await makeDeleteRequest({ url: server.url, path, token: userAccessToken, expectedStatus: HttpStatusCode.NO_CONTENT_204 })
312 }) 304 })
313 305
314 it('Should succeed with the correct parameters', async function () { 306 it('Should succeed with the correct parameters', async function () {
@@ -316,15 +308,14 @@ describe('Test video comments API validator', function () {
316 url: server.url, 308 url: server.url,
317 path: pathComment, 309 path: pathComment,
318 token: server.accessToken, 310 token: server.accessToken,
319 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 311 expectedStatus: HttpStatusCode.NO_CONTENT_204
320 }) 312 })
321 }) 313 })
322 }) 314 })
323 315
324 describe('When a video has comments disabled', function () { 316 describe('When a video has comments disabled', function () {
325 before(async function () { 317 before(async function () {
326 const res = await uploadVideo(server.url, server.accessToken, { commentsEnabled: false }) 318 video = await server.videos.upload({ attributes: { commentsEnabled: false } })
327 video = res.body.video
328 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads' 319 pathThread = '/api/v1/videos/' + video.uuid + '/comment-threads'
329 }) 320 })
330 321
@@ -332,7 +323,7 @@ describe('Test video comments API validator', function () {
332 const res = await makeGetRequest({ 323 const res = await makeGetRequest({
333 url: server.url, 324 url: server.url,
334 path: pathThread, 325 path: pathThread,
335 statusCodeExpected: HttpStatusCode.OK_200 326 expectedStatus: HttpStatusCode.OK_200
336 }) 327 })
337 expect(res.body.total).to.equal(0) 328 expect(res.body.total).to.equal(0)
338 expect(res.body.data).to.have.lengthOf(0) 329 expect(res.body.data).to.have.lengthOf(0)
@@ -349,7 +340,7 @@ describe('Test video comments API validator', function () {
349 path: pathThread, 340 path: pathThread,
350 token: server.accessToken, 341 token: server.accessToken,
351 fields, 342 fields,
352 statusCodeExpected: HttpStatusCode.CONFLICT_409 343 expectedStatus: HttpStatusCode.CONFLICT_409
353 }) 344 })
354 }) 345 })
355 346
@@ -375,7 +366,7 @@ describe('Test video comments API validator', function () {
375 await makeGetRequest({ 366 await makeGetRequest({
376 url: server.url, 367 url: server.url,
377 path, 368 path,
378 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 369 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
379 }) 370 })
380 }) 371 })
381 372
@@ -384,7 +375,7 @@ describe('Test video comments API validator', function () {
384 url: server.url, 375 url: server.url,
385 path, 376 path,
386 token: userAccessToken, 377 token: userAccessToken,
387 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 378 expectedStatus: HttpStatusCode.FORBIDDEN_403
388 }) 379 })
389 }) 380 })
390 381
@@ -399,7 +390,7 @@ describe('Test video comments API validator', function () {
399 searchAccount: 'toto', 390 searchAccount: 'toto',
400 searchVideo: 'toto' 391 searchVideo: 'toto'
401 }, 392 },
402 statusCodeExpected: HttpStatusCode.OK_200 393 expectedStatus: HttpStatusCode.OK_200
403 }) 394 })
404 }) 395 })
405 }) 396 })
diff --git a/server/tests/api/check-params/video-imports.ts b/server/tests/api/check-params/video-imports.ts
index a27b624d0..d6d745488 100644
--- a/server/tests/api/check-params/video-imports.ts
+++ b/server/tests/api/check-params/video-imports.ts
@@ -2,33 +2,25 @@
2 2
3import 'mocha' 3import 'mocha'
4import { omit } from 'lodash' 4import { omit } from 'lodash'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 5import {
7 buildAbsoluteFixturePath, 6 buildAbsoluteFixturePath,
7 checkBadCountPagination,
8 checkBadSortPagination,
9 checkBadStartPagination,
8 cleanupTests, 10 cleanupTests,
9 createUser, 11 createSingleServer,
10 flushAndRunServer, 12 FIXTURE_URLS,
11 getMyUserInformation,
12 immutableAssign,
13 makeGetRequest, 13 makeGetRequest,
14 makePostBodyRequest, 14 makePostBodyRequest,
15 makeUploadRequest, 15 makeUploadRequest,
16 ServerInfo, 16 PeerTubeServer,
17 setAccessTokensToServers, 17 setAccessTokensToServers
18 updateCustomSubConfig, 18} from '@shared/extra-utils'
19 userLogin 19import { HttpStatusCode, VideoPrivacy } from '@shared/models'
20} from '../../../../shared/extra-utils'
21import {
22 checkBadCountPagination,
23 checkBadSortPagination,
24 checkBadStartPagination
25} from '../../../../shared/extra-utils/requests/check-api-params'
26import { getGoodVideoUrl, getMagnetURI } from '../../../../shared/extra-utils/videos/video-imports'
27import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
28 20
29describe('Test video imports API validator', function () { 21describe('Test video imports API validator', function () {
30 const path = '/api/v1/videos/imports' 22 const path = '/api/v1/videos/imports'
31 let server: ServerInfo 23 let server: PeerTubeServer
32 let userAccessToken = '' 24 let userAccessToken = ''
33 let channelId: number 25 let channelId: number
34 26
@@ -37,18 +29,18 @@ describe('Test video imports API validator', function () {
37 before(async function () { 29 before(async function () {
38 this.timeout(30000) 30 this.timeout(30000)
39 31
40 server = await flushAndRunServer(1) 32 server = await createSingleServer(1)
41 33
42 await setAccessTokensToServers([ server ]) 34 await setAccessTokensToServers([ server ])
43 35
44 const username = 'user1' 36 const username = 'user1'
45 const password = 'my super password' 37 const password = 'my super password'
46 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 38 await server.users.create({ username: username, password: password })
47 userAccessToken = await userLogin(server, { username, password }) 39 userAccessToken = await server.login.getAccessToken({ username, password })
48 40
49 { 41 {
50 const res = await getMyUserInformation(server.url, server.accessToken) 42 const { videoChannels } = await server.users.getMyInfo()
51 channelId = res.body.videoChannels[0].id 43 channelId = videoChannels[0].id
52 } 44 }
53 }) 45 })
54 46
@@ -68,7 +60,7 @@ describe('Test video imports API validator', function () {
68 }) 60 })
69 61
70 it('Should success with the correct parameters', async function () { 62 it('Should success with the correct parameters', async function () {
71 await makeGetRequest({ url: server.url, path: myPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) 63 await makeGetRequest({ url: server.url, path: myPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken })
72 }) 64 })
73 }) 65 })
74 66
@@ -77,7 +69,7 @@ describe('Test video imports API validator', function () {
77 69
78 before(function () { 70 before(function () {
79 baseCorrectParams = { 71 baseCorrectParams = {
80 targetUrl: getGoodVideoUrl(), 72 targetUrl: FIXTURE_URLS.goodVideo,
81 name: 'my super name', 73 name: 'my super name',
82 category: 5, 74 category: 5,
83 licence: 1, 75 licence: 1,
@@ -106,48 +98,48 @@ describe('Test video imports API validator', function () {
106 path, 98 path,
107 token: server.accessToken, 99 token: server.accessToken,
108 fields, 100 fields,
109 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 101 expectedStatus: HttpStatusCode.BAD_REQUEST_400
110 }) 102 })
111 }) 103 })
112 104
113 it('Should fail with a bad target url', async function () { 105 it('Should fail with a bad target url', async function () {
114 const fields = immutableAssign(baseCorrectParams, { targetUrl: 'htt://hello' }) 106 const fields = { ...baseCorrectParams, targetUrl: 'htt://hello' }
115 107
116 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 108 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
117 }) 109 })
118 110
119 it('Should fail with a long name', async function () { 111 it('Should fail with a long name', async function () {
120 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 112 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
121 113
122 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 114 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
123 }) 115 })
124 116
125 it('Should fail with a bad category', async function () { 117 it('Should fail with a bad category', async function () {
126 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 118 const fields = { ...baseCorrectParams, category: 125 }
127 119
128 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 120 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
129 }) 121 })
130 122
131 it('Should fail with a bad licence', async function () { 123 it('Should fail with a bad licence', async function () {
132 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 124 const fields = { ...baseCorrectParams, licence: 125 }
133 125
134 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 126 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
135 }) 127 })
136 128
137 it('Should fail with a bad language', async function () { 129 it('Should fail with a bad language', async function () {
138 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 130 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
139 131
140 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 132 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
141 }) 133 })
142 134
143 it('Should fail with a long description', async function () { 135 it('Should fail with a long description', async function () {
144 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 136 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
145 137
146 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 138 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
147 }) 139 })
148 140
149 it('Should fail with a long support text', async function () { 141 it('Should fail with a long support text', async function () {
150 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 142 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
151 143
152 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 144 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
153 }) 145 })
@@ -159,7 +151,7 @@ describe('Test video imports API validator', function () {
159 }) 151 })
160 152
161 it('Should fail with a bad channel', async function () { 153 it('Should fail with a bad channel', async function () {
162 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 154 const fields = { ...baseCorrectParams, channelId: 545454 }
163 155
164 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 156 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
165 }) 157 })
@@ -169,31 +161,31 @@ describe('Test video imports API validator', function () {
169 username: 'fake', 161 username: 'fake',
170 password: 'fake_password' 162 password: 'fake_password'
171 } 163 }
172 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 164 await server.users.create({ username: user.username, password: user.password })
173 165
174 const accessTokenUser = await userLogin(server, user) 166 const accessTokenUser = await server.login.getAccessToken(user)
175 const res = await getMyUserInformation(server.url, accessTokenUser) 167 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
176 const customChannelId = res.body.videoChannels[0].id 168 const customChannelId = videoChannels[0].id
177 169
178 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) 170 const fields = { ...baseCorrectParams, channelId: customChannelId }
179 171
180 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields }) 172 await makePostBodyRequest({ url: server.url, path, token: userAccessToken, fields })
181 }) 173 })
182 174
183 it('Should fail with too many tags', async function () { 175 it('Should fail with too many tags', async function () {
184 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 176 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
185 177
186 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 178 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
187 }) 179 })
188 180
189 it('Should fail with a tag length too low', async function () { 181 it('Should fail with a tag length too low', async function () {
190 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 182 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
191 183
192 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 184 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
193 }) 185 })
194 186
195 it('Should fail with a tag length too big', async function () { 187 it('Should fail with a tag length too big', async function () {
196 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 188 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
197 189
198 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 190 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
199 }) 191 })
@@ -245,7 +237,7 @@ describe('Test video imports API validator', function () {
245 237
246 it('Should fail with an invalid magnet URI', async function () { 238 it('Should fail with an invalid magnet URI', async function () {
247 let fields = omit(baseCorrectParams, 'targetUrl') 239 let fields = omit(baseCorrectParams, 'targetUrl')
248 fields = immutableAssign(fields, { magnetUri: 'blabla' }) 240 fields = { ...fields, magnetUri: 'blabla' }
249 241
250 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields }) 242 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
251 }) 243 })
@@ -258,19 +250,21 @@ describe('Test video imports API validator', function () {
258 path, 250 path,
259 token: server.accessToken, 251 token: server.accessToken,
260 fields: baseCorrectParams, 252 fields: baseCorrectParams,
261 statusCodeExpected: HttpStatusCode.OK_200 253 expectedStatus: HttpStatusCode.OK_200
262 }) 254 })
263 }) 255 })
264 256
265 it('Should forbid to import http videos', async function () { 257 it('Should forbid to import http videos', async function () {
266 await updateCustomSubConfig(server.url, server.accessToken, { 258 await server.config.updateCustomSubConfig({
267 import: { 259 newConfig: {
268 videos: { 260 import: {
269 http: { 261 videos: {
270 enabled: false 262 http: {
271 }, 263 enabled: false
272 torrent: { 264 },
273 enabled: true 265 torrent: {
266 enabled: true
267 }
274 } 268 }
275 } 269 }
276 } 270 }
@@ -281,33 +275,35 @@ describe('Test video imports API validator', function () {
281 path, 275 path,
282 token: server.accessToken, 276 token: server.accessToken,
283 fields: baseCorrectParams, 277 fields: baseCorrectParams,
284 statusCodeExpected: HttpStatusCode.CONFLICT_409 278 expectedStatus: HttpStatusCode.CONFLICT_409
285 }) 279 })
286 }) 280 })
287 281
288 it('Should forbid to import torrent videos', async function () { 282 it('Should forbid to import torrent videos', async function () {
289 await updateCustomSubConfig(server.url, server.accessToken, { 283 await server.config.updateCustomSubConfig({
290 import: { 284 newConfig: {
291 videos: { 285 import: {
292 http: { 286 videos: {
293 enabled: true 287 http: {
294 }, 288 enabled: true
295 torrent: { 289 },
296 enabled: false 290 torrent: {
291 enabled: false
292 }
297 } 293 }
298 } 294 }
299 } 295 }
300 }) 296 })
301 297
302 let fields = omit(baseCorrectParams, 'targetUrl') 298 let fields = omit(baseCorrectParams, 'targetUrl')
303 fields = immutableAssign(fields, { magnetUri: getMagnetURI() }) 299 fields = { ...fields, magnetUri: FIXTURE_URLS.magnet }
304 300
305 await makePostBodyRequest({ 301 await makePostBodyRequest({
306 url: server.url, 302 url: server.url,
307 path, 303 path,
308 token: server.accessToken, 304 token: server.accessToken,
309 fields, 305 fields,
310 statusCodeExpected: HttpStatusCode.CONFLICT_409 306 expectedStatus: HttpStatusCode.CONFLICT_409
311 }) 307 })
312 308
313 fields = omit(fields, 'magnetUri') 309 fields = omit(fields, 'magnetUri')
@@ -321,7 +317,7 @@ describe('Test video imports API validator', function () {
321 token: server.accessToken, 317 token: server.accessToken,
322 fields, 318 fields,
323 attaches, 319 attaches,
324 statusCodeExpected: HttpStatusCode.CONFLICT_409 320 expectedStatus: HttpStatusCode.CONFLICT_409
325 }) 321 })
326 }) 322 })
327 }) 323 })
diff --git a/server/tests/api/check-params/video-playlists.ts b/server/tests/api/check-params/video-playlists.ts
index 18253d11a..e4d541b48 100644
--- a/server/tests/api/check-params/video-playlists.ts
+++ b/server/tests/api/check-params/video-playlists.ts
@@ -1,34 +1,31 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { VideoPlaylistCreateResult, VideoPlaylistPrivacy, VideoPlaylistType } from '@shared/models'
5import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
6import { 4import {
7 addVideoInPlaylist,
8 checkBadCountPagination, 5 checkBadCountPagination,
9 checkBadSortPagination, 6 checkBadSortPagination,
10 checkBadStartPagination, 7 checkBadStartPagination,
11 cleanupTests, 8 cleanupTests,
12 createVideoPlaylist, 9 createSingleServer,
13 deleteVideoPlaylist,
14 flushAndRunServer,
15 generateUserAccessToken,
16 getAccountPlaylistsListWithToken,
17 getVideoPlaylist,
18 immutableAssign,
19 makeGetRequest, 10 makeGetRequest,
20 removeVideoFromPlaylist, 11 PeerTubeServer,
21 reorderVideosPlaylist, 12 PlaylistsCommand,
22 ServerInfo,
23 setAccessTokensToServers, 13 setAccessTokensToServers,
24 setDefaultVideoChannel, 14 setDefaultVideoChannel
25 updateVideoPlaylist, 15} from '@shared/extra-utils'
26 updateVideoPlaylistElement, 16import {
27 uploadVideoAndGetId 17 HttpStatusCode,
28} from '../../../../shared/extra-utils' 18 VideoPlaylistCreate,
19 VideoPlaylistCreateResult,
20 VideoPlaylistElementCreate,
21 VideoPlaylistElementUpdate,
22 VideoPlaylistPrivacy,
23 VideoPlaylistReorder,
24 VideoPlaylistType
25} from '@shared/models'
29 26
30describe('Test video playlists API validator', function () { 27describe('Test video playlists API validator', function () {
31 let server: ServerInfo 28 let server: PeerTubeServer
32 let userAccessToken: string 29 let userAccessToken: string
33 30
34 let playlist: VideoPlaylistCreateResult 31 let playlist: VideoPlaylistCreateResult
@@ -36,49 +33,54 @@ describe('Test video playlists API validator', function () {
36 33
37 let watchLaterPlaylistId: number 34 let watchLaterPlaylistId: number
38 let videoId: number 35 let videoId: number
39 let playlistElementId: number 36 let elementId: number
37
38 let command: PlaylistsCommand
40 39
41 // --------------------------------------------------------------- 40 // ---------------------------------------------------------------
42 41
43 before(async function () { 42 before(async function () {
44 this.timeout(30000) 43 this.timeout(30000)
45 44
46 server = await flushAndRunServer(1) 45 server = await createSingleServer(1)
47 46
48 await setAccessTokensToServers([ server ]) 47 await setAccessTokensToServers([ server ])
49 await setDefaultVideoChannel([ server ]) 48 await setDefaultVideoChannel([ server ])
50 49
51 userAccessToken = await generateUserAccessToken(server, 'user1') 50 userAccessToken = await server.users.generateUserAndToken('user1')
52 videoId = (await uploadVideoAndGetId({ server, videoName: 'video 1' })).id 51 videoId = (await server.videos.quickUpload({ name: 'video 1' })).id
52
53 command = server.playlists
53 54
54 { 55 {
55 const res = await getAccountPlaylistsListWithToken(server.url, server.accessToken, 'root', 0, 5, VideoPlaylistType.WATCH_LATER) 56 const { data } = await command.listByAccount({
56 watchLaterPlaylistId = res.body.data[0].id 57 token: server.accessToken,
58 handle: 'root',
59 start: 0,
60 count: 5,
61 playlistType: VideoPlaylistType.WATCH_LATER
62 })
63 watchLaterPlaylistId = data[0].id
57 } 64 }
58 65
59 { 66 {
60 const res = await createVideoPlaylist({ 67 playlist = await command.create({
61 url: server.url, 68 attributes: {
62 token: server.accessToken,
63 playlistAttrs: {
64 displayName: 'super playlist', 69 displayName: 'super playlist',
65 privacy: VideoPlaylistPrivacy.PUBLIC, 70 privacy: VideoPlaylistPrivacy.PUBLIC,
66 videoChannelId: server.videoChannel.id 71 videoChannelId: server.store.channel.id
67 } 72 }
68 }) 73 })
69 playlist = res.body.videoPlaylist
70 } 74 }
71 75
72 { 76 {
73 const res = await createVideoPlaylist({ 77 const created = await command.create({
74 url: server.url, 78 attributes: {
75 token: server.accessToken,
76 playlistAttrs: {
77 displayName: 'private', 79 displayName: 'private',
78 privacy: VideoPlaylistPrivacy.PRIVATE 80 privacy: VideoPlaylistPrivacy.PRIVATE
79 } 81 }
80 }) 82 })
81 privatePlaylistUUID = res.body.videoPlaylist.uuid 83 privatePlaylistUUID = created.uuid
82 } 84 }
83 }) 85 })
84 86
@@ -117,7 +119,7 @@ describe('Test video playlists API validator', function () {
117 await makeGetRequest({ 119 await makeGetRequest({
118 url: server.url, 120 url: server.url,
119 path: accountPath, 121 path: accountPath,
120 statusCodeExpected: HttpStatusCode.NOT_FOUND_404, 122 expectedStatus: HttpStatusCode.NOT_FOUND_404,
121 token: server.accessToken 123 token: server.accessToken
122 }) 124 })
123 }) 125 })
@@ -128,18 +130,18 @@ describe('Test video playlists API validator', function () {
128 await makeGetRequest({ 130 await makeGetRequest({
129 url: server.url, 131 url: server.url,
130 path: accountPath, 132 path: accountPath,
131 statusCodeExpected: HttpStatusCode.NOT_FOUND_404, 133 expectedStatus: HttpStatusCode.NOT_FOUND_404,
132 token: server.accessToken 134 token: server.accessToken
133 }) 135 })
134 }) 136 })
135 137
136 it('Should success with the correct parameters', async function () { 138 it('Should success with the correct parameters', async function () {
137 await makeGetRequest({ url: server.url, path: globalPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) 139 await makeGetRequest({ url: server.url, path: globalPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken })
138 await makeGetRequest({ url: server.url, path: accountPath, statusCodeExpected: HttpStatusCode.OK_200, token: server.accessToken }) 140 await makeGetRequest({ url: server.url, path: accountPath, expectedStatus: HttpStatusCode.OK_200, token: server.accessToken })
139 await makeGetRequest({ 141 await makeGetRequest({
140 url: server.url, 142 url: server.url,
141 path: videoChannelPath, 143 path: videoChannelPath,
142 statusCodeExpected: HttpStatusCode.OK_200, 144 expectedStatus: HttpStatusCode.OK_200,
143 token: server.accessToken 145 token: server.accessToken
144 }) 146 })
145 }) 147 })
@@ -157,141 +159,144 @@ describe('Test video playlists API validator', function () {
157 }) 159 })
158 160
159 it('Should success with the correct parameters', async function () { 161 it('Should success with the correct parameters', async function () {
160 await makeGetRequest({ url: server.url, path: path + playlist.shortUUID + '/videos', statusCodeExpected: HttpStatusCode.OK_200 }) 162 await makeGetRequest({ url: server.url, path: path + playlist.shortUUID + '/videos', expectedStatus: HttpStatusCode.OK_200 })
161 }) 163 })
162 }) 164 })
163 165
164 describe('When getting a video playlist', function () { 166 describe('When getting a video playlist', function () {
165 it('Should fail with a bad id or uuid', async function () { 167 it('Should fail with a bad id or uuid', async function () {
166 await getVideoPlaylist(server.url, 'toto', HttpStatusCode.BAD_REQUEST_400) 168 await command.get({ playlistId: 'toto', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
167 }) 169 })
168 170
169 it('Should fail with an unknown playlist', async function () { 171 it('Should fail with an unknown playlist', async function () {
170 await getVideoPlaylist(server.url, 42, HttpStatusCode.NOT_FOUND_404) 172 await command.get({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
171 }) 173 })
172 174
173 it('Should fail to get an unlisted playlist with the number id', async function () { 175 it('Should fail to get an unlisted playlist with the number id', async function () {
174 const res = await createVideoPlaylist({ 176 const playlist = await command.create({
175 url: server.url, 177 attributes: {
176 token: server.accessToken,
177 playlistAttrs: {
178 displayName: 'super playlist', 178 displayName: 'super playlist',
179 videoChannelId: server.videoChannel.id, 179 videoChannelId: server.store.channel.id,
180 privacy: VideoPlaylistPrivacy.UNLISTED 180 privacy: VideoPlaylistPrivacy.UNLISTED
181 } 181 }
182 }) 182 })
183 const playlist = res.body.videoPlaylist
184 183
185 await getVideoPlaylist(server.url, playlist.id, HttpStatusCode.NOT_FOUND_404) 184 await command.get({ playlistId: playlist.id, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
186 await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200) 185 await command.get({ playlistId: playlist.uuid, expectedStatus: HttpStatusCode.OK_200 })
187 }) 186 })
188 187
189 it('Should succeed with the correct params', async function () { 188 it('Should succeed with the correct params', async function () {
190 await getVideoPlaylist(server.url, playlist.uuid, HttpStatusCode.OK_200) 189 await command.get({ playlistId: playlist.uuid, expectedStatus: HttpStatusCode.OK_200 })
191 }) 190 })
192 }) 191 })
193 192
194 describe('When creating/updating a video playlist', function () { 193 describe('When creating/updating a video playlist', function () {
195 const getBase = (playlistAttrs: any = {}, wrapper: any = {}) => { 194 const getBase = (
196 return Object.assign({ 195 attributes?: Partial<VideoPlaylistCreate>,
197 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 196 wrapper?: Partial<Parameters<PlaylistsCommand['create']>[0]>
198 url: server.url, 197 ) => {
199 token: server.accessToken, 198 return {
200 playlistAttrs: Object.assign({ 199 attributes: {
201 displayName: 'display name', 200 displayName: 'display name',
202 privacy: VideoPlaylistPrivacy.UNLISTED, 201 privacy: VideoPlaylistPrivacy.UNLISTED,
203 thumbnailfile: 'thumbnail.jpg', 202 thumbnailfile: 'thumbnail.jpg',
204 videoChannelId: server.videoChannel.id 203 videoChannelId: server.store.channel.id,
205 }, playlistAttrs) 204
206 }, wrapper) 205 ...attributes
206 },
207
208 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
209
210 ...wrapper
211 }
207 } 212 }
208 const getUpdate = (params: any, playlistId: number | string) => { 213 const getUpdate = (params: any, playlistId: number | string) => {
209 return immutableAssign(params, { playlistId: playlistId }) 214 return { ...params, playlistId: playlistId }
210 } 215 }
211 216
212 it('Should fail with an unauthenticated user', async function () { 217 it('Should fail with an unauthenticated user', async function () {
213 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 218 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
214 219
215 await createVideoPlaylist(params) 220 await command.create(params)
216 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 221 await command.update(getUpdate(params, playlist.shortUUID))
217 }) 222 })
218 223
219 it('Should fail without displayName', async function () { 224 it('Should fail without displayName', async function () {
220 const params = getBase({ displayName: undefined }) 225 const params = getBase({ displayName: undefined })
221 226
222 await createVideoPlaylist(params) 227 await command.create(params)
223 }) 228 })
224 229
225 it('Should fail with an incorrect display name', async function () { 230 it('Should fail with an incorrect display name', async function () {
226 const params = getBase({ displayName: 's'.repeat(300) }) 231 const params = getBase({ displayName: 's'.repeat(300) })
227 232
228 await createVideoPlaylist(params) 233 await command.create(params)
229 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 234 await command.update(getUpdate(params, playlist.shortUUID))
230 }) 235 })
231 236
232 it('Should fail with an incorrect description', async function () { 237 it('Should fail with an incorrect description', async function () {
233 const params = getBase({ description: 't' }) 238 const params = getBase({ description: 't' })
234 239
235 await createVideoPlaylist(params) 240 await command.create(params)
236 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 241 await command.update(getUpdate(params, playlist.shortUUID))
237 }) 242 })
238 243
239 it('Should fail with an incorrect privacy', async function () { 244 it('Should fail with an incorrect privacy', async function () {
240 const params = getBase({ privacy: 45 }) 245 const params = getBase({ privacy: 45 })
241 246
242 await createVideoPlaylist(params) 247 await command.create(params)
243 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 248 await command.update(getUpdate(params, playlist.shortUUID))
244 }) 249 })
245 250
246 it('Should fail with an unknown video channel id', async function () { 251 it('Should fail with an unknown video channel id', async function () {
247 const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 252 const params = getBase({ videoChannelId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
248 253
249 await createVideoPlaylist(params) 254 await command.create(params)
250 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 255 await command.update(getUpdate(params, playlist.shortUUID))
251 }) 256 })
252 257
253 it('Should fail with an incorrect thumbnail file', async function () { 258 it('Should fail with an incorrect thumbnail file', async function () {
254 const params = getBase({ thumbnailfile: 'video_short.mp4' }) 259 const params = getBase({ thumbnailfile: 'video_short.mp4' })
255 260
256 await createVideoPlaylist(params) 261 await command.create(params)
257 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 262 await command.update(getUpdate(params, playlist.shortUUID))
258 }) 263 })
259 264
260 it('Should fail with a thumbnail file too big', async function () { 265 it('Should fail with a thumbnail file too big', async function () {
261 const params = getBase({ thumbnailfile: 'preview-big.png' }) 266 const params = getBase({ thumbnailfile: 'preview-big.png' })
262 267
263 await createVideoPlaylist(params) 268 await command.create(params)
264 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 269 await command.update(getUpdate(params, playlist.shortUUID))
265 }) 270 })
266 271
267 it('Should fail to set "public" a playlist not assigned to a channel', async function () { 272 it('Should fail to set "public" a playlist not assigned to a channel', async function () {
268 const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: undefined }) 273 const params = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: undefined })
269 const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' }) 274 const params2 = getBase({ privacy: VideoPlaylistPrivacy.PUBLIC, videoChannelId: 'null' as any })
270 const params3 = getBase({ privacy: undefined, videoChannelId: 'null' }) 275 const params3 = getBase({ privacy: undefined, videoChannelId: 'null' as any })
271 276
272 await createVideoPlaylist(params) 277 await command.create(params)
273 await createVideoPlaylist(params2) 278 await command.create(params2)
274 await updateVideoPlaylist(getUpdate(params, privatePlaylistUUID)) 279 await command.update(getUpdate(params, privatePlaylistUUID))
275 await updateVideoPlaylist(getUpdate(params2, playlist.shortUUID)) 280 await command.update(getUpdate(params2, playlist.shortUUID))
276 await updateVideoPlaylist(getUpdate(params3, playlist.shortUUID)) 281 await command.update(getUpdate(params3, playlist.shortUUID))
277 }) 282 })
278 283
279 it('Should fail with an unknown playlist to update', async function () { 284 it('Should fail with an unknown playlist to update', async function () {
280 await updateVideoPlaylist(getUpdate( 285 await command.update(getUpdate(
281 getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }), 286 getBase({}, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }),
282 42 287 42
283 )) 288 ))
284 }) 289 })
285 290
286 it('Should fail to update a playlist of another user', async function () { 291 it('Should fail to update a playlist of another user', async function () {
287 await updateVideoPlaylist(getUpdate( 292 await command.update(getUpdate(
288 getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }), 293 getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }),
289 playlist.shortUUID 294 playlist.shortUUID
290 )) 295 ))
291 }) 296 })
292 297
293 it('Should fail to update the watch later playlist', async function () { 298 it('Should fail to update the watch later playlist', async function () {
294 await updateVideoPlaylist(getUpdate( 299 await command.update(getUpdate(
295 getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }), 300 getBase({}, { expectedStatus: HttpStatusCode.BAD_REQUEST_400 }),
296 watchLaterPlaylistId 301 watchLaterPlaylistId
297 )) 302 ))
@@ -300,146 +305,158 @@ describe('Test video playlists API validator', function () {
300 it('Should succeed with the correct params', async function () { 305 it('Should succeed with the correct params', async function () {
301 { 306 {
302 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 }) 307 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
303 await createVideoPlaylist(params) 308 await command.create(params)
304 } 309 }
305 310
306 { 311 {
307 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) 312 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
308 await updateVideoPlaylist(getUpdate(params, playlist.shortUUID)) 313 await command.update(getUpdate(params, playlist.shortUUID))
309 } 314 }
310 }) 315 })
311 }) 316 })
312 317
313 describe('When adding an element in a playlist', function () { 318 describe('When adding an element in a playlist', function () {
314 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { 319 const getBase = (
315 return Object.assign({ 320 attributes?: Partial<VideoPlaylistElementCreate>,
316 expectedStatus: HttpStatusCode.BAD_REQUEST_400, 321 wrapper?: Partial<Parameters<PlaylistsCommand['addElement']>[0]>
317 url: server.url, 322 ) => {
318 token: server.accessToken, 323 return {
319 playlistId: playlist.id, 324 attributes: {
320 elementAttrs: Object.assign({
321 videoId, 325 videoId,
322 startTimestamp: 2, 326 startTimestamp: 2,
323 stopTimestamp: 3 327 stopTimestamp: 3,
324 }, elementAttrs) 328
325 }, wrapper) 329 ...attributes
330 },
331
332 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
333 playlistId: playlist.id,
334
335 ...wrapper
336 }
326 } 337 }
327 338
328 it('Should fail with an unauthenticated user', async function () { 339 it('Should fail with an unauthenticated user', async function () {
329 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 340 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
330 await addVideoInPlaylist(params) 341 await command.addElement(params)
331 }) 342 })
332 343
333 it('Should fail with the playlist of another user', async function () { 344 it('Should fail with the playlist of another user', async function () {
334 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 345 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
335 await addVideoInPlaylist(params) 346 await command.addElement(params)
336 }) 347 })
337 348
338 it('Should fail with an unknown or incorrect playlist id', async function () { 349 it('Should fail with an unknown or incorrect playlist id', async function () {
339 { 350 {
340 const params = getBase({}, { playlistId: 'toto' }) 351 const params = getBase({}, { playlistId: 'toto' })
341 await addVideoInPlaylist(params) 352 await command.addElement(params)
342 } 353 }
343 354
344 { 355 {
345 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 356 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
346 await addVideoInPlaylist(params) 357 await command.addElement(params)
347 } 358 }
348 }) 359 })
349 360
350 it('Should fail with an unknown or incorrect video id', async function () { 361 it('Should fail with an unknown or incorrect video id', async function () {
351 const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 362 const params = getBase({ videoId: 42 }, { expectedStatus: HttpStatusCode.NOT_FOUND_404 })
352 await addVideoInPlaylist(params) 363 await command.addElement(params)
353 }) 364 })
354 365
355 it('Should fail with a bad start/stop timestamp', async function () { 366 it('Should fail with a bad start/stop timestamp', async function () {
356 { 367 {
357 const params = getBase({ startTimestamp: -42 }) 368 const params = getBase({ startTimestamp: -42 })
358 await addVideoInPlaylist(params) 369 await command.addElement(params)
359 } 370 }
360 371
361 { 372 {
362 const params = getBase({ stopTimestamp: 'toto' as any }) 373 const params = getBase({ stopTimestamp: 'toto' as any })
363 await addVideoInPlaylist(params) 374 await command.addElement(params)
364 } 375 }
365 }) 376 })
366 377
367 it('Succeed with the correct params', async function () { 378 it('Succeed with the correct params', async function () {
368 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 }) 379 const params = getBase({}, { expectedStatus: HttpStatusCode.OK_200 })
369 const res = await addVideoInPlaylist(params) 380 const created = await command.addElement(params)
370 playlistElementId = res.body.videoPlaylistElement.id 381 elementId = created.id
371 }) 382 })
372 }) 383 })
373 384
374 describe('When updating an element in a playlist', function () { 385 describe('When updating an element in a playlist', function () {
375 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { 386 const getBase = (
376 return Object.assign({ 387 attributes?: Partial<VideoPlaylistElementUpdate>,
377 url: server.url, 388 wrapper?: Partial<Parameters<PlaylistsCommand['updateElement']>[0]>
378 token: server.accessToken, 389 ) => {
379 elementAttrs: Object.assign({ 390 return {
391 attributes: {
380 startTimestamp: 1, 392 startTimestamp: 1,
381 stopTimestamp: 2 393 stopTimestamp: 2,
382 }, elementAttrs), 394
383 playlistElementId, 395 ...attributes
396 },
397
398 elementId,
384 playlistId: playlist.id, 399 playlistId: playlist.id,
385 expectedStatus: HttpStatusCode.BAD_REQUEST_400 400 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
386 }, wrapper) 401
402 ...wrapper
403 }
387 } 404 }
388 405
389 it('Should fail with an unauthenticated user', async function () { 406 it('Should fail with an unauthenticated user', async function () {
390 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 407 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
391 await updateVideoPlaylistElement(params) 408 await command.updateElement(params)
392 }) 409 })
393 410
394 it('Should fail with the playlist of another user', async function () { 411 it('Should fail with the playlist of another user', async function () {
395 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 412 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
396 await updateVideoPlaylistElement(params) 413 await command.updateElement(params)
397 }) 414 })
398 415
399 it('Should fail with an unknown or incorrect playlist id', async function () { 416 it('Should fail with an unknown or incorrect playlist id', async function () {
400 { 417 {
401 const params = getBase({}, { playlistId: 'toto' }) 418 const params = getBase({}, { playlistId: 'toto' })
402 await updateVideoPlaylistElement(params) 419 await command.updateElement(params)
403 } 420 }
404 421
405 { 422 {
406 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 423 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
407 await updateVideoPlaylistElement(params) 424 await command.updateElement(params)
408 } 425 }
409 }) 426 })
410 427
411 it('Should fail with an unknown or incorrect playlistElement id', async function () { 428 it('Should fail with an unknown or incorrect playlistElement id', async function () {
412 { 429 {
413 const params = getBase({}, { playlistElementId: 'toto' }) 430 const params = getBase({}, { elementId: 'toto' })
414 await updateVideoPlaylistElement(params) 431 await command.updateElement(params)
415 } 432 }
416 433
417 { 434 {
418 const params = getBase({}, { playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 435 const params = getBase({}, { elementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
419 await updateVideoPlaylistElement(params) 436 await command.updateElement(params)
420 } 437 }
421 }) 438 })
422 439
423 it('Should fail with a bad start/stop timestamp', async function () { 440 it('Should fail with a bad start/stop timestamp', async function () {
424 { 441 {
425 const params = getBase({ startTimestamp: 'toto' as any }) 442 const params = getBase({ startTimestamp: 'toto' as any })
426 await updateVideoPlaylistElement(params) 443 await command.updateElement(params)
427 } 444 }
428 445
429 { 446 {
430 const params = getBase({ stopTimestamp: -42 }) 447 const params = getBase({ stopTimestamp: -42 })
431 await updateVideoPlaylistElement(params) 448 await command.updateElement(params)
432 } 449 }
433 }) 450 })
434 451
435 it('Should fail with an unknown element', async function () { 452 it('Should fail with an unknown element', async function () {
436 const params = getBase({}, { playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 453 const params = getBase({}, { elementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
437 await updateVideoPlaylistElement(params) 454 await command.updateElement(params)
438 }) 455 })
439 456
440 it('Succeed with the correct params', async function () { 457 it('Succeed with the correct params', async function () {
441 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) 458 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
442 await updateVideoPlaylistElement(params) 459 await command.updateElement(params)
443 }) 460 })
444 }) 461 })
445 462
@@ -447,110 +464,111 @@ describe('Test video playlists API validator', function () {
447 let videoId3: number 464 let videoId3: number
448 let videoId4: number 465 let videoId4: number
449 466
450 const getBase = (elementAttrs: any = {}, wrapper: any = {}) => { 467 const getBase = (
451 return Object.assign({ 468 attributes?: Partial<VideoPlaylistReorder>,
452 url: server.url, 469 wrapper?: Partial<Parameters<PlaylistsCommand['reorderElements']>[0]>
453 token: server.accessToken, 470 ) => {
454 playlistId: playlist.shortUUID, 471 return {
455 elementAttrs: Object.assign({ 472 attributes: {
456 startPosition: 1, 473 startPosition: 1,
457 insertAfterPosition: 2, 474 insertAfterPosition: 2,
458 reorderLength: 3 475 reorderLength: 3,
459 }, elementAttrs), 476
460 expectedStatus: HttpStatusCode.BAD_REQUEST_400 477 ...attributes
461 }, wrapper) 478 },
479
480 playlistId: playlist.shortUUID,
481 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
482
483 ...wrapper
484 }
462 } 485 }
463 486
464 before(async function () { 487 before(async function () {
465 videoId3 = (await uploadVideoAndGetId({ server, videoName: 'video 3' })).id 488 videoId3 = (await server.videos.quickUpload({ name: 'video 3' })).id
466 videoId4 = (await uploadVideoAndGetId({ server, videoName: 'video 4' })).id 489 videoId4 = (await server.videos.quickUpload({ name: 'video 4' })).id
467 490
468 for (const id of [ videoId3, videoId4 ]) { 491 for (const id of [ videoId3, videoId4 ]) {
469 await addVideoInPlaylist({ 492 await command.addElement({ playlistId: playlist.shortUUID, attributes: { videoId: id } })
470 url: server.url,
471 token: server.accessToken,
472 playlistId: playlist.shortUUID,
473 elementAttrs: { videoId: id }
474 })
475 } 493 }
476 }) 494 })
477 495
478 it('Should fail with an unauthenticated user', async function () { 496 it('Should fail with an unauthenticated user', async function () {
479 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 497 const params = getBase({}, { token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
480 await reorderVideosPlaylist(params) 498 await command.reorderElements(params)
481 }) 499 })
482 500
483 it('Should fail with the playlist of another user', async function () { 501 it('Should fail with the playlist of another user', async function () {
484 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 502 const params = getBase({}, { token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
485 await reorderVideosPlaylist(params) 503 await command.reorderElements(params)
486 }) 504 })
487 505
488 it('Should fail with an invalid playlist', async function () { 506 it('Should fail with an invalid playlist', async function () {
489 { 507 {
490 const params = getBase({}, { playlistId: 'toto' }) 508 const params = getBase({}, { playlistId: 'toto' })
491 await reorderVideosPlaylist(params) 509 await command.reorderElements(params)
492 } 510 }
493 511
494 { 512 {
495 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 513 const params = getBase({}, { playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
496 await reorderVideosPlaylist(params) 514 await command.reorderElements(params)
497 } 515 }
498 }) 516 })
499 517
500 it('Should fail with an invalid start position', async function () { 518 it('Should fail with an invalid start position', async function () {
501 { 519 {
502 const params = getBase({ startPosition: -1 }) 520 const params = getBase({ startPosition: -1 })
503 await reorderVideosPlaylist(params) 521 await command.reorderElements(params)
504 } 522 }
505 523
506 { 524 {
507 const params = getBase({ startPosition: 'toto' as any }) 525 const params = getBase({ startPosition: 'toto' as any })
508 await reorderVideosPlaylist(params) 526 await command.reorderElements(params)
509 } 527 }
510 528
511 { 529 {
512 const params = getBase({ startPosition: 42 }) 530 const params = getBase({ startPosition: 42 })
513 await reorderVideosPlaylist(params) 531 await command.reorderElements(params)
514 } 532 }
515 }) 533 })
516 534
517 it('Should fail with an invalid insert after position', async function () { 535 it('Should fail with an invalid insert after position', async function () {
518 { 536 {
519 const params = getBase({ insertAfterPosition: 'toto' as any }) 537 const params = getBase({ insertAfterPosition: 'toto' as any })
520 await reorderVideosPlaylist(params) 538 await command.reorderElements(params)
521 } 539 }
522 540
523 { 541 {
524 const params = getBase({ insertAfterPosition: -2 }) 542 const params = getBase({ insertAfterPosition: -2 })
525 await reorderVideosPlaylist(params) 543 await command.reorderElements(params)
526 } 544 }
527 545
528 { 546 {
529 const params = getBase({ insertAfterPosition: 42 }) 547 const params = getBase({ insertAfterPosition: 42 })
530 await reorderVideosPlaylist(params) 548 await command.reorderElements(params)
531 } 549 }
532 }) 550 })
533 551
534 it('Should fail with an invalid reorder length', async function () { 552 it('Should fail with an invalid reorder length', async function () {
535 { 553 {
536 const params = getBase({ reorderLength: 'toto' as any }) 554 const params = getBase({ reorderLength: 'toto' as any })
537 await reorderVideosPlaylist(params) 555 await command.reorderElements(params)
538 } 556 }
539 557
540 { 558 {
541 const params = getBase({ reorderLength: -2 }) 559 const params = getBase({ reorderLength: -2 })
542 await reorderVideosPlaylist(params) 560 await command.reorderElements(params)
543 } 561 }
544 562
545 { 563 {
546 const params = getBase({ reorderLength: 42 }) 564 const params = getBase({ reorderLength: 42 })
547 await reorderVideosPlaylist(params) 565 await command.reorderElements(params)
548 } 566 }
549 }) 567 })
550 568
551 it('Succeed with the correct params', async function () { 569 it('Succeed with the correct params', async function () {
552 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 }) 570 const params = getBase({}, { expectedStatus: HttpStatusCode.NO_CONTENT_204 })
553 await reorderVideosPlaylist(params) 571 await command.reorderElements(params)
554 }) 572 })
555 }) 573 })
556 574
@@ -562,7 +580,7 @@ describe('Test video playlists API validator', function () {
562 url: server.url, 580 url: server.url,
563 path, 581 path,
564 query: { videoIds: [ 1, 2 ] }, 582 query: { videoIds: [ 1, 2 ] },
565 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 583 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
566 }) 584 })
567 }) 585 })
568 586
@@ -595,82 +613,82 @@ describe('Test video playlists API validator', function () {
595 token: server.accessToken, 613 token: server.accessToken,
596 path, 614 path,
597 query: { videoIds: [ 1, 2 ] }, 615 query: { videoIds: [ 1, 2 ] },
598 statusCodeExpected: HttpStatusCode.OK_200 616 expectedStatus: HttpStatusCode.OK_200
599 }) 617 })
600 }) 618 })
601 }) 619 })
602 620
603 describe('When deleting an element in a playlist', function () { 621 describe('When deleting an element in a playlist', function () {
604 const getBase = (wrapper: any = {}) => { 622 const getBase = (wrapper: Partial<Parameters<PlaylistsCommand['removeElement']>[0]>) => {
605 return Object.assign({ 623 return {
606 url: server.url, 624 elementId,
607 token: server.accessToken,
608 playlistElementId,
609 playlistId: playlist.uuid, 625 playlistId: playlist.uuid,
610 expectedStatus: HttpStatusCode.BAD_REQUEST_400 626 expectedStatus: HttpStatusCode.BAD_REQUEST_400,
611 }, wrapper) 627
628 ...wrapper
629 }
612 } 630 }
613 631
614 it('Should fail with an unauthenticated user', async function () { 632 it('Should fail with an unauthenticated user', async function () {
615 const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) 633 const params = getBase({ token: null, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
616 await removeVideoFromPlaylist(params) 634 await command.removeElement(params)
617 }) 635 })
618 636
619 it('Should fail with the playlist of another user', async function () { 637 it('Should fail with the playlist of another user', async function () {
620 const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) 638 const params = getBase({ token: userAccessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
621 await removeVideoFromPlaylist(params) 639 await command.removeElement(params)
622 }) 640 })
623 641
624 it('Should fail with an unknown or incorrect playlist id', async function () { 642 it('Should fail with an unknown or incorrect playlist id', async function () {
625 { 643 {
626 const params = getBase({ playlistId: 'toto' }) 644 const params = getBase({ playlistId: 'toto' })
627 await removeVideoFromPlaylist(params) 645 await command.removeElement(params)
628 } 646 }
629 647
630 { 648 {
631 const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 649 const params = getBase({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
632 await removeVideoFromPlaylist(params) 650 await command.removeElement(params)
633 } 651 }
634 }) 652 })
635 653
636 it('Should fail with an unknown or incorrect video id', async function () { 654 it('Should fail with an unknown or incorrect video id', async function () {
637 { 655 {
638 const params = getBase({ playlistElementId: 'toto' }) 656 const params = getBase({ elementId: 'toto' as any })
639 await removeVideoFromPlaylist(params) 657 await command.removeElement(params)
640 } 658 }
641 659
642 { 660 {
643 const params = getBase({ playlistElementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 661 const params = getBase({ elementId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
644 await removeVideoFromPlaylist(params) 662 await command.removeElement(params)
645 } 663 }
646 }) 664 })
647 665
648 it('Should fail with an unknown element', async function () { 666 it('Should fail with an unknown element', async function () {
649 const params = getBase({ playlistElementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 }) 667 const params = getBase({ elementId: 888, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
650 await removeVideoFromPlaylist(params) 668 await command.removeElement(params)
651 }) 669 })
652 670
653 it('Succeed with the correct params', async function () { 671 it('Succeed with the correct params', async function () {
654 const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 }) 672 const params = getBase({ expectedStatus: HttpStatusCode.NO_CONTENT_204 })
655 await removeVideoFromPlaylist(params) 673 await command.removeElement(params)
656 }) 674 })
657 }) 675 })
658 676
659 describe('When deleting a playlist', function () { 677 describe('When deleting a playlist', function () {
660 it('Should fail with an unknown playlist', async function () { 678 it('Should fail with an unknown playlist', async function () {
661 await deleteVideoPlaylist(server.url, server.accessToken, 42, HttpStatusCode.NOT_FOUND_404) 679 await command.delete({ playlistId: 42, expectedStatus: HttpStatusCode.NOT_FOUND_404 })
662 }) 680 })
663 681
664 it('Should fail with a playlist of another user', async function () { 682 it('Should fail with a playlist of another user', async function () {
665 await deleteVideoPlaylist(server.url, userAccessToken, playlist.uuid, HttpStatusCode.FORBIDDEN_403) 683 await command.delete({ token: userAccessToken, playlistId: playlist.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
666 }) 684 })
667 685
668 it('Should fail with the watch later playlist', async function () { 686 it('Should fail with the watch later playlist', async function () {
669 await deleteVideoPlaylist(server.url, server.accessToken, watchLaterPlaylistId, HttpStatusCode.BAD_REQUEST_400) 687 await command.delete({ playlistId: watchLaterPlaylistId, expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
670 }) 688 })
671 689
672 it('Should succeed with the correct params', async function () { 690 it('Should succeed with the correct params', async function () {
673 await deleteVideoPlaylist(server.url, server.accessToken, playlist.uuid) 691 await command.delete({ playlistId: playlist.uuid })
674 }) 692 })
675 }) 693 })
676 694
diff --git a/server/tests/api/check-params/videos-filter.ts b/server/tests/api/check-params/videos-filter.ts
index 4d54a4fd0..d08570bbe 100644
--- a/server/tests/api/check-params/videos-filter.ts
+++ b/server/tests/api/check-params/videos-filter.ts
@@ -3,18 +3,15 @@
3import 'mocha' 3import 'mocha'
4import { 4import {
5 cleanupTests, 5 cleanupTests,
6 createUser, 6 createSingleServer,
7 flushAndRunServer,
8 makeGetRequest, 7 makeGetRequest,
9 ServerInfo, 8 PeerTubeServer,
10 setAccessTokensToServers, 9 setAccessTokensToServers,
11 setDefaultVideoChannel, 10 setDefaultVideoChannel
12 userLogin 11} from '@shared/extra-utils'
13} from '../../../../shared/extra-utils' 12import { HttpStatusCode, UserRole } from '@shared/models'
14import { UserRole } from '../../../../shared/models/users'
15import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
16 13
17async function testEndpoints (server: ServerInfo, token: string, filter: string, statusCodeExpected: HttpStatusCode) { 14async function testEndpoints (server: PeerTubeServer, token: string, filter: string, expectedStatus: HttpStatusCode) {
18 const paths = [ 15 const paths = [
19 '/api/v1/video-channels/root_channel/videos', 16 '/api/v1/video-channels/root_channel/videos',
20 '/api/v1/accounts/root/videos', 17 '/api/v1/accounts/root/videos',
@@ -30,13 +27,13 @@ async function testEndpoints (server: ServerInfo, token: string, filter: string,
30 query: { 27 query: {
31 filter 28 filter
32 }, 29 },
33 statusCodeExpected 30 expectedStatus
34 }) 31 })
35 } 32 }
36} 33}
37 34
38describe('Test video filters validators', function () { 35describe('Test video filters validators', function () {
39 let server: ServerInfo 36 let server: PeerTubeServer
40 let userAccessToken: string 37 let userAccessToken: string
41 let moderatorAccessToken: string 38 let moderatorAccessToken: string
42 39
@@ -45,28 +42,19 @@ describe('Test video filters validators', function () {
45 before(async function () { 42 before(async function () {
46 this.timeout(30000) 43 this.timeout(30000)
47 44
48 server = await flushAndRunServer(1) 45 server = await createSingleServer(1)
49 46
50 await setAccessTokensToServers([ server ]) 47 await setAccessTokensToServers([ server ])
51 await setDefaultVideoChannel([ server ]) 48 await setDefaultVideoChannel([ server ])
52 49
53 const user = { username: 'user1', password: 'my super password' } 50 const user = { username: 'user1', password: 'my super password' }
54 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 51 await server.users.create({ username: user.username, password: user.password })
55 userAccessToken = await userLogin(server, user) 52 userAccessToken = await server.login.getAccessToken(user)
56 53
57 const moderator = { username: 'moderator', password: 'my super password' } 54 const moderator = { username: 'moderator', password: 'my super password' }
58 await createUser( 55 await server.users.create({ username: moderator.username, password: moderator.password, role: UserRole.MODERATOR })
59 { 56
60 url: server.url, 57 moderatorAccessToken = await server.login.getAccessToken(moderator)
61 accessToken: server.accessToken,
62 username: moderator.username,
63 password: moderator.password,
64 videoQuota: undefined,
65 videoQuotaDaily: undefined,
66 role: UserRole.MODERATOR
67 }
68 )
69 moderatorAccessToken = await userLogin(server, moderator)
70 }) 58 })
71 59
72 describe('When setting a video filter', function () { 60 describe('When setting a video filter', function () {
@@ -100,7 +88,7 @@ describe('Test video filters validators', function () {
100 await makeGetRequest({ 88 await makeGetRequest({
101 url: server.url, 89 url: server.url,
102 path: '/feeds/videos.json', 90 path: '/feeds/videos.json',
103 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401, 91 expectedStatus: HttpStatusCode.UNAUTHORIZED_401,
104 query: { 92 query: {
105 filter 93 filter
106 } 94 }
@@ -112,7 +100,7 @@ describe('Test video filters validators', function () {
112 await makeGetRequest({ 100 await makeGetRequest({
113 url: server.url, 101 url: server.url,
114 path: '/feeds/videos.json', 102 path: '/feeds/videos.json',
115 statusCodeExpected: HttpStatusCode.OK_200, 103 expectedStatus: HttpStatusCode.OK_200,
116 query: { 104 query: {
117 filter: 'local' 105 filter: 'local'
118 } 106 }
diff --git a/server/tests/api/check-params/videos-history.ts b/server/tests/api/check-params/videos-history.ts
index 0e91fe0a8..c3c309ed2 100644
--- a/server/tests/api/check-params/videos-history.ts
+++ b/server/tests/api/check-params/videos-history.ts
@@ -5,42 +5,39 @@ import {
5 checkBadCountPagination, 5 checkBadCountPagination,
6 checkBadStartPagination, 6 checkBadStartPagination,
7 cleanupTests, 7 cleanupTests,
8 flushAndRunServer, 8 createSingleServer,
9 makeGetRequest, 9 makeGetRequest,
10 makePostBodyRequest, 10 makePostBodyRequest,
11 makePutBodyRequest, 11 makePutBodyRequest,
12 ServerInfo, 12 PeerTubeServer,
13 setAccessTokensToServers, 13 setAccessTokensToServers
14 uploadVideo 14} from '@shared/extra-utils'
15} from '../../../../shared/extra-utils' 15import { HttpStatusCode } from '@shared/models'
16import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
17 16
18describe('Test videos history API validator', function () { 17describe('Test videos history API validator', function () {
19 const myHistoryPath = '/api/v1/users/me/history/videos' 18 const myHistoryPath = '/api/v1/users/me/history/videos'
20 const myHistoryRemove = myHistoryPath + '/remove' 19 const myHistoryRemove = myHistoryPath + '/remove'
21 let watchingPath: string 20 let watchingPath: string
22 let server: ServerInfo 21 let server: PeerTubeServer
23 22
24 // --------------------------------------------------------------- 23 // ---------------------------------------------------------------
25 24
26 before(async function () { 25 before(async function () {
27 this.timeout(30000) 26 this.timeout(30000)
28 27
29 server = await flushAndRunServer(1) 28 server = await createSingleServer(1)
30 29
31 await setAccessTokensToServers([ server ]) 30 await setAccessTokensToServers([ server ])
32 31
33 const res = await uploadVideo(server.url, server.accessToken, {}) 32 const { uuid } = await server.videos.upload()
34 const videoUUID = res.body.video.uuid 33 watchingPath = '/api/v1/videos/' + uuid + '/watching'
35
36 watchingPath = '/api/v1/videos/' + videoUUID + '/watching'
37 }) 34 })
38 35
39 describe('When notifying a user is watching a video', function () { 36 describe('When notifying a user is watching a video', function () {
40 37
41 it('Should fail with an unauthenticated user', async function () { 38 it('Should fail with an unauthenticated user', async function () {
42 const fields = { currentTime: 5 } 39 const fields = { currentTime: 5 }
43 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 40 await makePutBodyRequest({ url: server.url, path: watchingPath, fields, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
44 }) 41 })
45 42
46 it('Should fail with an incorrect video id', async function () { 43 it('Should fail with an incorrect video id', async function () {
@@ -51,7 +48,7 @@ describe('Test videos history API validator', function () {
51 path, 48 path,
52 fields, 49 fields,
53 token: server.accessToken, 50 token: server.accessToken,
54 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 51 expectedStatus: HttpStatusCode.BAD_REQUEST_400
55 }) 52 })
56 }) 53 })
57 54
@@ -64,7 +61,7 @@ describe('Test videos history API validator', function () {
64 path, 61 path,
65 fields, 62 fields,
66 token: server.accessToken, 63 token: server.accessToken,
67 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 64 expectedStatus: HttpStatusCode.NOT_FOUND_404
68 }) 65 })
69 }) 66 })
70 67
@@ -75,7 +72,7 @@ describe('Test videos history API validator', function () {
75 path: watchingPath, 72 path: watchingPath,
76 fields, 73 fields,
77 token: server.accessToken, 74 token: server.accessToken,
78 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 75 expectedStatus: HttpStatusCode.BAD_REQUEST_400
79 }) 76 })
80 }) 77 })
81 78
@@ -87,7 +84,7 @@ describe('Test videos history API validator', function () {
87 path: watchingPath, 84 path: watchingPath,
88 fields, 85 fields,
89 token: server.accessToken, 86 token: server.accessToken,
90 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 87 expectedStatus: HttpStatusCode.NO_CONTENT_204
91 }) 88 })
92 }) 89 })
93 }) 90 })
@@ -102,17 +99,17 @@ describe('Test videos history API validator', function () {
102 }) 99 })
103 100
104 it('Should fail with an unauthenticated user', async function () { 101 it('Should fail with an unauthenticated user', async function () {
105 await makeGetRequest({ url: server.url, path: myHistoryPath, statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 102 await makeGetRequest({ url: server.url, path: myHistoryPath, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
106 }) 103 })
107 104
108 it('Should succeed with the correct params', async function () { 105 it('Should succeed with the correct params', async function () {
109 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, statusCodeExpected: HttpStatusCode.OK_200 }) 106 await makeGetRequest({ url: server.url, token: server.accessToken, path: myHistoryPath, expectedStatus: HttpStatusCode.OK_200 })
110 }) 107 })
111 }) 108 })
112 109
113 describe('When removing user videos history', function () { 110 describe('When removing user videos history', function () {
114 it('Should fail with an unauthenticated user', async function () { 111 it('Should fail with an unauthenticated user', async function () {
115 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401 }) 112 await makePostBodyRequest({ url: server.url, path: myHistoryPath + '/remove', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
116 }) 113 })
117 114
118 it('Should fail with a bad beforeDate parameter', async function () { 115 it('Should fail with a bad beforeDate parameter', async function () {
@@ -122,7 +119,7 @@ describe('Test videos history API validator', function () {
122 token: server.accessToken, 119 token: server.accessToken,
123 path: myHistoryRemove, 120 path: myHistoryRemove,
124 fields: body, 121 fields: body,
125 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 122 expectedStatus: HttpStatusCode.BAD_REQUEST_400
126 }) 123 })
127 }) 124 })
128 125
@@ -133,7 +130,7 @@ describe('Test videos history API validator', function () {
133 token: server.accessToken, 130 token: server.accessToken,
134 path: myHistoryRemove, 131 path: myHistoryRemove,
135 fields: body, 132 fields: body,
136 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 133 expectedStatus: HttpStatusCode.NO_CONTENT_204
137 }) 134 })
138 }) 135 })
139 136
@@ -142,7 +139,7 @@ describe('Test videos history API validator', function () {
142 url: server.url, 139 url: server.url,
143 token: server.accessToken, 140 token: server.accessToken,
144 path: myHistoryRemove, 141 path: myHistoryRemove,
145 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 142 expectedStatus: HttpStatusCode.NO_CONTENT_204
146 }) 143 })
147 }) 144 })
148 }) 145 })
diff --git a/server/tests/api/check-params/videos-overviews.ts b/server/tests/api/check-params/videos-overviews.ts
index 69d7fc471..c2139d74b 100644
--- a/server/tests/api/check-params/videos-overviews.ts
+++ b/server/tests/api/check-params/videos-overviews.ts
@@ -1,29 +1,28 @@
1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
2 2
3import 'mocha' 3import 'mocha'
4import { cleanupTests, flushAndRunServer, ServerInfo } from '../../../../shared/extra-utils' 4import { cleanupTests, createSingleServer, PeerTubeServer } from '@shared/extra-utils'
5import { getVideosOverview } from '@shared/extra-utils/overviews/overviews'
6 5
7describe('Test videos overview', function () { 6describe('Test videos overview', function () {
8 let server: ServerInfo 7 let server: PeerTubeServer
9 8
10 // --------------------------------------------------------------- 9 // ---------------------------------------------------------------
11 10
12 before(async function () { 11 before(async function () {
13 this.timeout(30000) 12 this.timeout(30000)
14 13
15 server = await flushAndRunServer(1) 14 server = await createSingleServer(1)
16 }) 15 })
17 16
18 describe('When getting videos overview', function () { 17 describe('When getting videos overview', function () {
19 18
20 it('Should fail with a bad pagination', async function () { 19 it('Should fail with a bad pagination', async function () {
21 await getVideosOverview(server.url, 0, 400) 20 await server.overviews.getVideos({ page: 0, expectedStatus: 400 })
22 await getVideosOverview(server.url, 100, 400) 21 await server.overviews.getVideos({ page: 100, expectedStatus: 400 })
23 }) 22 })
24 23
25 it('Should succeed with a good pagination', async function () { 24 it('Should succeed with a good pagination', async function () {
26 await getVideosOverview(server.url, 1) 25 await server.overviews.getVideos({ page: 1 })
27 }) 26 })
28 }) 27 })
29 28
diff --git a/server/tests/api/check-params/videos.ts b/server/tests/api/check-params/videos.ts
index 4d7a9a23b..e11ca0c82 100644
--- a/server/tests/api/check-params/videos.ts
+++ b/server/tests/api/check-params/videos.ts
@@ -5,39 +5,28 @@ import * as chai from 'chai'
5import { omit } from 'lodash' 5import { omit } from 'lodash'
6import { join } from 'path' 6import { join } from 'path'
7import { randomInt } from '@shared/core-utils' 7import { randomInt } from '@shared/core-utils'
8import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models'
9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
10import { 8import {
9 checkBadCountPagination,
10 checkBadSortPagination,
11 checkBadStartPagination,
11 checkUploadVideoParam, 12 checkUploadVideoParam,
12 cleanupTests, 13 cleanupTests,
13 createUser, 14 createSingleServer,
14 flushAndRunServer,
15 getMyUserInformation,
16 getVideo,
17 getVideosList,
18 immutableAssign,
19 makeDeleteRequest, 15 makeDeleteRequest,
20 makeGetRequest, 16 makeGetRequest,
21 makePutBodyRequest, 17 makePutBodyRequest,
22 makeUploadRequest, 18 makeUploadRequest,
23 removeVideo, 19 PeerTubeServer,
24 root, 20 root,
25 ServerInfo, 21 setAccessTokensToServers
26 setAccessTokensToServers, 22} from '@shared/extra-utils'
27 userLogin 23import { HttpStatusCode, PeerTubeProblemDocument, VideoCreateResult, VideoPrivacy } from '@shared/models'
28} from '../../../../shared/extra-utils'
29import {
30 checkBadCountPagination,
31 checkBadSortPagination,
32 checkBadStartPagination
33} from '../../../../shared/extra-utils/requests/check-api-params'
34import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
35 24
36const expect = chai.expect 25const expect = chai.expect
37 26
38describe('Test videos API validator', function () { 27describe('Test videos API validator', function () {
39 const path = '/api/v1/videos/' 28 const path = '/api/v1/videos/'
40 let server: ServerInfo 29 let server: PeerTubeServer
41 let userAccessToken = '' 30 let userAccessToken = ''
42 let accountName: string 31 let accountName: string
43 let channelId: number 32 let channelId: number
@@ -49,20 +38,20 @@ describe('Test videos API validator', function () {
49 before(async function () { 38 before(async function () {
50 this.timeout(30000) 39 this.timeout(30000)
51 40
52 server = await flushAndRunServer(1) 41 server = await createSingleServer(1)
53 42
54 await setAccessTokensToServers([ server ]) 43 await setAccessTokensToServers([ server ])
55 44
56 const username = 'user1' 45 const username = 'user1'
57 const password = 'my super password' 46 const password = 'my super password'
58 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password }) 47 await server.users.create({ username: username, password: password })
59 userAccessToken = await userLogin(server, { username, password }) 48 userAccessToken = await server.login.getAccessToken({ username, password })
60 49
61 { 50 {
62 const res = await getMyUserInformation(server.url, server.accessToken) 51 const body = await server.users.getMyInfo()
63 channelId = res.body.videoChannels[0].id 52 channelId = body.videoChannels[0].id
64 channelName = res.body.videoChannels[0].name 53 channelName = body.videoChannels[0].name
65 accountName = res.body.account.name + '@' + res.body.account.host 54 accountName = body.account.name + '@' + body.account.host
66 } 55 }
67 }) 56 })
68 57
@@ -80,11 +69,11 @@ describe('Test videos API validator', function () {
80 }) 69 })
81 70
82 it('Should fail with a bad skipVideos query', async function () { 71 it('Should fail with a bad skipVideos query', async function () {
83 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } }) 72 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
84 }) 73 })
85 74
86 it('Should success with the correct parameters', async function () { 75 it('Should success with the correct parameters', async function () {
87 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } }) 76 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200, query: { skipCount: false } })
88 }) 77 })
89 }) 78 })
90 79
@@ -94,7 +83,7 @@ describe('Test videos API validator', function () {
94 await makeGetRequest({ 83 await makeGetRequest({
95 url: server.url, 84 url: server.url,
96 path: join(path, 'search'), 85 path: join(path, 'search'),
97 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 86 expectedStatus: HttpStatusCode.BAD_REQUEST_400
98 }) 87 })
99 }) 88 })
100 89
@@ -111,7 +100,7 @@ describe('Test videos API validator', function () {
111 }) 100 })
112 101
113 it('Should success with the correct parameters', async function () { 102 it('Should success with the correct parameters', async function () {
114 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) 103 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 })
115 }) 104 })
116 }) 105 })
117 106
@@ -131,7 +120,7 @@ describe('Test videos API validator', function () {
131 }) 120 })
132 121
133 it('Should success with the correct parameters', async function () { 122 it('Should success with the correct parameters', async function () {
134 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 }) 123 await makeGetRequest({ url: server.url, token: server.accessToken, path, expectedStatus: HttpStatusCode.OK_200 })
135 }) 124 })
136 }) 125 })
137 126
@@ -155,7 +144,7 @@ describe('Test videos API validator', function () {
155 }) 144 })
156 145
157 it('Should success with the correct parameters', async function () { 146 it('Should success with the correct parameters', async function () {
158 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) 147 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 })
159 }) 148 })
160 }) 149 })
161 150
@@ -179,7 +168,7 @@ describe('Test videos API validator', function () {
179 }) 168 })
180 169
181 it('Should success with the correct parameters', async function () { 170 it('Should success with the correct parameters', async function () {
182 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 }) 171 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.OK_200 })
183 }) 172 })
184 }) 173 })
185 174
@@ -214,70 +203,70 @@ describe('Test videos API validator', function () {
214 it('Should fail with nothing', async function () { 203 it('Should fail with nothing', async function () {
215 const fields = {} 204 const fields = {}
216 const attaches = {} 205 const attaches = {}
217 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 206 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
218 }) 207 })
219 208
220 it('Should fail without name', async function () { 209 it('Should fail without name', async function () {
221 const fields = omit(baseCorrectParams, 'name') 210 const fields = omit(baseCorrectParams, 'name')
222 const attaches = baseCorrectAttaches 211 const attaches = baseCorrectAttaches
223 212
224 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 213 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
225 }) 214 })
226 215
227 it('Should fail with a long name', async function () { 216 it('Should fail with a long name', async function () {
228 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 217 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
229 const attaches = baseCorrectAttaches 218 const attaches = baseCorrectAttaches
230 219
231 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 220 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
232 }) 221 })
233 222
234 it('Should fail with a bad category', async function () { 223 it('Should fail with a bad category', async function () {
235 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 224 const fields = { ...baseCorrectParams, category: 125 }
236 const attaches = baseCorrectAttaches 225 const attaches = baseCorrectAttaches
237 226
238 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 227 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
239 }) 228 })
240 229
241 it('Should fail with a bad licence', async function () { 230 it('Should fail with a bad licence', async function () {
242 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 231 const fields = { ...baseCorrectParams, licence: 125 }
243 const attaches = baseCorrectAttaches 232 const attaches = baseCorrectAttaches
244 233
245 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 234 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
246 }) 235 })
247 236
248 it('Should fail with a bad language', async function () { 237 it('Should fail with a bad language', async function () {
249 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 238 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
250 const attaches = baseCorrectAttaches 239 const attaches = baseCorrectAttaches
251 240
252 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 241 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
253 }) 242 })
254 243
255 it('Should fail with a long description', async function () { 244 it('Should fail with a long description', async function () {
256 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 245 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
257 const attaches = baseCorrectAttaches 246 const attaches = baseCorrectAttaches
258 247
259 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 248 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
260 }) 249 })
261 250
262 it('Should fail with a long support text', async function () { 251 it('Should fail with a long support text', async function () {
263 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 252 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
264 const attaches = baseCorrectAttaches 253 const attaches = baseCorrectAttaches
265 254
266 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 255 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
267 }) 256 })
268 257
269 it('Should fail without a channel', async function () { 258 it('Should fail without a channel', async function () {
270 const fields = omit(baseCorrectParams, 'channelId') 259 const fields = omit(baseCorrectParams, 'channelId')
271 const attaches = baseCorrectAttaches 260 const attaches = baseCorrectAttaches
272 261
273 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 262 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
274 }) 263 })
275 264
276 it('Should fail with a bad channel', async function () { 265 it('Should fail with a bad channel', async function () {
277 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 266 const fields = { ...baseCorrectParams, channelId: 545454 }
278 const attaches = baseCorrectAttaches 267 const attaches = baseCorrectAttaches
279 268
280 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 269 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
281 }) 270 })
282 271
283 it('Should fail with another user channel', async function () { 272 it('Should fail with another user channel', async function () {
@@ -285,69 +274,71 @@ describe('Test videos API validator', function () {
285 username: 'fake' + randomInt(0, 1500), 274 username: 'fake' + randomInt(0, 1500),
286 password: 'fake_password' 275 password: 'fake_password'
287 } 276 }
288 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password }) 277 await server.users.create({ username: user.username, password: user.password })
289 278
290 const accessTokenUser = await userLogin(server, user) 279 const accessTokenUser = await server.login.getAccessToken(user)
291 const res = await getMyUserInformation(server.url, accessTokenUser) 280 const { videoChannels } = await server.users.getMyInfo({ token: accessTokenUser })
292 const customChannelId = res.body.videoChannels[0].id 281 const customChannelId = videoChannels[0].id
293 282
294 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) 283 const fields = { ...baseCorrectParams, channelId: customChannelId }
295 const attaches = baseCorrectAttaches 284 const attaches = baseCorrectAttaches
296 285
297 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 286 await checkUploadVideoParam(server, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
298 }) 287 })
299 288
300 it('Should fail with too many tags', async function () { 289 it('Should fail with too many tags', async function () {
301 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 290 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
302 const attaches = baseCorrectAttaches 291 const attaches = baseCorrectAttaches
303 292
304 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 293 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
305 }) 294 })
306 295
307 it('Should fail with a tag length too low', async function () { 296 it('Should fail with a tag length too low', async function () {
308 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 297 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
309 const attaches = baseCorrectAttaches 298 const attaches = baseCorrectAttaches
310 299
311 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 300 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
312 }) 301 })
313 302
314 it('Should fail with a tag length too big', async function () { 303 it('Should fail with a tag length too big', async function () {
315 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 304 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
316 const attaches = baseCorrectAttaches 305 const attaches = baseCorrectAttaches
317 306
318 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 307 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
319 }) 308 })
320 309
321 it('Should fail with a bad schedule update (miss updateAt)', async function () { 310 it('Should fail with a bad schedule update (miss updateAt)', async function () {
322 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) 311 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
323 const attaches = baseCorrectAttaches 312 const attaches = baseCorrectAttaches
324 313
325 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 314 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
326 }) 315 })
327 316
328 it('Should fail with a bad schedule update (wrong updateAt)', async function () { 317 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
329 const fields = immutableAssign(baseCorrectParams, { 318 const fields = {
319 ...baseCorrectParams,
320
330 scheduleUpdate: { 321 scheduleUpdate: {
331 privacy: VideoPrivacy.PUBLIC, 322 privacy: VideoPrivacy.PUBLIC,
332 updateAt: 'toto' 323 updateAt: 'toto'
333 } 324 }
334 }) 325 }
335 const attaches = baseCorrectAttaches 326 const attaches = baseCorrectAttaches
336 327
337 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 328 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
338 }) 329 })
339 330
340 it('Should fail with a bad originally published at attribute', async function () { 331 it('Should fail with a bad originally published at attribute', async function () {
341 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) 332 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
342 const attaches = baseCorrectAttaches 333 const attaches = baseCorrectAttaches
343 334
344 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 335 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
345 }) 336 })
346 337
347 it('Should fail without an input file', async function () { 338 it('Should fail without an input file', async function () {
348 const fields = baseCorrectParams 339 const fields = baseCorrectParams
349 const attaches = {} 340 const attaches = {}
350 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 341 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
351 }) 342 })
352 343
353 it('Should fail with an incorrect input file', async function () { 344 it('Should fail with an incorrect input file', async function () {
@@ -355,7 +346,7 @@ describe('Test videos API validator', function () {
355 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') } 346 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
356 347
357 await checkUploadVideoParam( 348 await checkUploadVideoParam(
358 server.url, 349 server,
359 server.accessToken, 350 server.accessToken,
360 { ...fields, ...attaches }, 351 { ...fields, ...attaches },
361 HttpStatusCode.UNPROCESSABLE_ENTITY_422, 352 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
@@ -364,7 +355,7 @@ describe('Test videos API validator', function () {
364 355
365 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') } 356 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
366 await checkUploadVideoParam( 357 await checkUploadVideoParam(
367 server.url, 358 server,
368 server.accessToken, 359 server.accessToken,
369 { ...fields, ...attaches }, 360 { ...fields, ...attaches },
370 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415, 361 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
@@ -379,7 +370,7 @@ describe('Test videos API validator', function () {
379 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 370 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
380 } 371 }
381 372
382 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 373 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
383 }) 374 })
384 375
385 it('Should fail with a big thumbnail file', async function () { 376 it('Should fail with a big thumbnail file', async function () {
@@ -389,7 +380,7 @@ describe('Test videos API validator', function () {
389 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 380 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
390 } 381 }
391 382
392 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 383 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
393 }) 384 })
394 385
395 it('Should fail with an incorrect preview file', async function () { 386 it('Should fail with an incorrect preview file', async function () {
@@ -399,7 +390,7 @@ describe('Test videos API validator', function () {
399 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 390 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
400 } 391 }
401 392
402 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 393 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
403 }) 394 })
404 395
405 it('Should fail with a big preview file', async function () { 396 it('Should fail with a big preview file', async function () {
@@ -409,17 +400,17 @@ describe('Test videos API validator', function () {
409 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 400 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
410 } 401 }
411 402
412 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode) 403 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
413 }) 404 })
414 405
415 it('Should report the appropriate error', async function () { 406 it('Should report the appropriate error', async function () {
416 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 407 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
417 const attaches = baseCorrectAttaches 408 const attaches = baseCorrectAttaches
418 409
419 const attributes = { ...fields, ...attaches } 410 const attributes = { ...fields, ...attaches }
420 const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode) 411 const body = await checkUploadVideoParam(server, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
421 412
422 const error = res.body as PeerTubeProblemDocument 413 const error = body as unknown as PeerTubeProblemDocument
423 414
424 if (mode === 'legacy') { 415 if (mode === 'legacy') {
425 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy') 416 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
@@ -444,23 +435,27 @@ describe('Test videos API validator', function () {
444 435
445 { 436 {
446 const attaches = baseCorrectAttaches 437 const attaches = baseCorrectAttaches
447 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 438 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
448 } 439 }
449 440
450 { 441 {
451 const attaches = immutableAssign(baseCorrectAttaches, { 442 const attaches = {
443 ...baseCorrectAttaches,
444
452 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4') 445 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
453 }) 446 }
454 447
455 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 448 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
456 } 449 }
457 450
458 { 451 {
459 const attaches = immutableAssign(baseCorrectAttaches, { 452 const attaches = {
453 ...baseCorrectAttaches,
454
460 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv') 455 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
461 }) 456 }
462 457
463 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode) 458 await checkUploadVideoParam(server, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
464 } 459 }
465 }) 460 })
466 } 461 }
@@ -489,8 +484,8 @@ describe('Test videos API validator', function () {
489 } 484 }
490 485
491 before(async function () { 486 before(async function () {
492 const res = await getVideosList(server.url) 487 const { data } = await server.videos.list()
493 video = res.body.data[0] 488 video = data[0]
494 }) 489 })
495 490
496 it('Should fail with nothing', async function () { 491 it('Should fail with nothing', async function () {
@@ -511,84 +506,84 @@ describe('Test videos API validator', function () {
511 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', 506 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
512 token: server.accessToken, 507 token: server.accessToken,
513 fields, 508 fields,
514 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 509 expectedStatus: HttpStatusCode.NOT_FOUND_404
515 }) 510 })
516 }) 511 })
517 512
518 it('Should fail with a long name', async function () { 513 it('Should fail with a long name', async function () {
519 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) 514 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
520 515
521 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 516 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
522 }) 517 })
523 518
524 it('Should fail with a bad category', async function () { 519 it('Should fail with a bad category', async function () {
525 const fields = immutableAssign(baseCorrectParams, { category: 125 }) 520 const fields = { ...baseCorrectParams, category: 125 }
526 521
527 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 522 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
528 }) 523 })
529 524
530 it('Should fail with a bad licence', async function () { 525 it('Should fail with a bad licence', async function () {
531 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 526 const fields = { ...baseCorrectParams, licence: 125 }
532 527
533 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 528 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
534 }) 529 })
535 530
536 it('Should fail with a bad language', async function () { 531 it('Should fail with a bad language', async function () {
537 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) 532 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
538 533
539 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 534 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
540 }) 535 })
541 536
542 it('Should fail with a long description', async function () { 537 it('Should fail with a long description', async function () {
543 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) 538 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
544 539
545 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 540 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
546 }) 541 })
547 542
548 it('Should fail with a long support text', async function () { 543 it('Should fail with a long support text', async function () {
549 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) }) 544 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
550 545
551 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 546 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
552 }) 547 })
553 548
554 it('Should fail with a bad channel', async function () { 549 it('Should fail with a bad channel', async function () {
555 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) 550 const fields = { ...baseCorrectParams, channelId: 545454 }
556 551
557 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 552 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
558 }) 553 })
559 554
560 it('Should fail with too many tags', async function () { 555 it('Should fail with too many tags', async function () {
561 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) 556 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
562 557
563 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 558 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
564 }) 559 })
565 560
566 it('Should fail with a tag length too low', async function () { 561 it('Should fail with a tag length too low', async function () {
567 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) 562 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
568 563
569 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 564 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
570 }) 565 })
571 566
572 it('Should fail with a tag length too big', async function () { 567 it('Should fail with a tag length too big', async function () {
573 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) 568 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
574 569
575 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 570 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
576 }) 571 })
577 572
578 it('Should fail with a bad schedule update (miss updateAt)', async function () { 573 it('Should fail with a bad schedule update (miss updateAt)', async function () {
579 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) 574 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
580 575
581 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 576 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
582 }) 577 })
583 578
584 it('Should fail with a bad schedule update (wrong updateAt)', async function () { 579 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
585 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }) 580 const fields = { ...baseCorrectParams, scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }
586 581
587 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 582 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
588 }) 583 })
589 584
590 it('Should fail with a bad originally published at param', async function () { 585 it('Should fail with a bad originally published at param', async function () {
591 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' }) 586 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
592 587
593 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 588 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
594 }) 589 })
@@ -665,14 +660,14 @@ describe('Test videos API validator', function () {
665 path: path + video.shortUUID, 660 path: path + video.shortUUID,
666 token: userAccessToken, 661 token: userAccessToken,
667 fields, 662 fields,
668 statusCodeExpected: HttpStatusCode.FORBIDDEN_403 663 expectedStatus: HttpStatusCode.FORBIDDEN_403
669 }) 664 })
670 }) 665 })
671 666
672 it('Should fail with a video of another server') 667 it('Should fail with a video of another server')
673 668
674 it('Shoud report the appropriate error', async function () { 669 it('Shoud report the appropriate error', async function () {
675 const fields = immutableAssign(baseCorrectParams, { licence: 125 }) 670 const fields = { ...baseCorrectParams, licence: 125 }
676 671
677 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields }) 672 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
678 const error = res.body as PeerTubeProblemDocument 673 const error = res.body as PeerTubeProblemDocument
@@ -697,7 +692,7 @@ describe('Test videos API validator', function () {
697 path: path + video.shortUUID, 692 path: path + video.shortUUID,
698 token: server.accessToken, 693 token: server.accessToken,
699 fields, 694 fields,
700 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 695 expectedStatus: HttpStatusCode.NO_CONTENT_204
701 }) 696 })
702 }) 697 })
703 }) 698 })
@@ -707,7 +702,7 @@ describe('Test videos API validator', function () {
707 const res = await makeGetRequest({ 702 const res = await makeGetRequest({
708 url: server.url, 703 url: server.url,
709 path, 704 path,
710 statusCodeExpected: HttpStatusCode.OK_200 705 expectedStatus: HttpStatusCode.OK_200
711 }) 706 })
712 707
713 expect(res.body.data).to.be.an('array') 708 expect(res.body.data).to.be.an('array')
@@ -715,16 +710,16 @@ describe('Test videos API validator', function () {
715 }) 710 })
716 711
717 it('Should fail without a correct uuid', async function () { 712 it('Should fail without a correct uuid', async function () {
718 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400) 713 await server.videos.get({ id: 'coucou', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
719 }) 714 })
720 715
721 it('Should return 404 with an incorrect video', async function () { 716 it('Should return 404 with an incorrect video', async function () {
722 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 717 await server.videos.get({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
723 }) 718 })
724 719
725 it('Shoud report the appropriate error', async function () { 720 it('Shoud report the appropriate error', async function () {
726 const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400) 721 const body = await server.videos.get({ id: 'hi', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
727 const error = res.body as PeerTubeProblemDocument 722 const error = body as unknown as PeerTubeProblemDocument
728 723
729 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo') 724 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
730 725
@@ -739,16 +734,16 @@ describe('Test videos API validator', function () {
739 }) 734 })
740 735
741 it('Should succeed with the correct parameters', async function () { 736 it('Should succeed with the correct parameters', async function () {
742 await getVideo(server.url, video.shortUUID) 737 await server.videos.get({ id: video.shortUUID })
743 }) 738 })
744 }) 739 })
745 740
746 describe('When rating a video', function () { 741 describe('When rating a video', function () {
747 let videoId 742 let videoId: number
748 743
749 before(async function () { 744 before(async function () {
750 const res = await getVideosList(server.url) 745 const { data } = await server.videos.list()
751 videoId = res.body.data[0].id 746 videoId = data[0].id
752 }) 747 })
753 748
754 it('Should fail without a valid uuid', async function () { 749 it('Should fail without a valid uuid', async function () {
@@ -767,7 +762,7 @@ describe('Test videos API validator', function () {
767 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', 762 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
768 token: server.accessToken, 763 token: server.accessToken,
769 fields, 764 fields,
770 statusCodeExpected: HttpStatusCode.NOT_FOUND_404 765 expectedStatus: HttpStatusCode.NOT_FOUND_404
771 }) 766 })
772 }) 767 })
773 768
@@ -787,7 +782,7 @@ describe('Test videos API validator', function () {
787 path: path + videoId + '/rate', 782 path: path + videoId + '/rate',
788 token: server.accessToken, 783 token: server.accessToken,
789 fields, 784 fields,
790 statusCodeExpected: HttpStatusCode.NO_CONTENT_204 785 expectedStatus: HttpStatusCode.NO_CONTENT_204
791 }) 786 })
792 }) 787 })
793 }) 788 })
@@ -797,27 +792,27 @@ describe('Test videos API validator', function () {
797 await makeDeleteRequest({ 792 await makeDeleteRequest({
798 url: server.url, 793 url: server.url,
799 path, 794 path,
800 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400 795 expectedStatus: HttpStatusCode.BAD_REQUEST_400
801 }) 796 })
802 }) 797 })
803 798
804 it('Should fail without a correct uuid', async function () { 799 it('Should fail without a correct uuid', async function () {
805 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) 800 await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
806 }) 801 })
807 802
808 it('Should fail with a video which does not exist', async function () { 803 it('Should fail with a video which does not exist', async function () {
809 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404) 804 await server.videos.remove({ id: '4da6fde3-88f7-4d16-b119-108df5630b06', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
810 }) 805 })
811 806
812 it('Should fail with a video of another user without the appropriate right', async function () { 807 it('Should fail with a video of another user without the appropriate right', async function () {
813 await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403) 808 await server.videos.remove({ token: userAccessToken, id: video.uuid, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
814 }) 809 })
815 810
816 it('Should fail with a video of another server') 811 it('Should fail with a video of another server')
817 812
818 it('Shoud report the appropriate error', async function () { 813 it('Shoud report the appropriate error', async function () {
819 const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400) 814 const body = await server.videos.remove({ id: 'hello', expectedStatus: HttpStatusCode.BAD_REQUEST_400 })
820 const error = res.body as PeerTubeProblemDocument 815 const error = body as PeerTubeProblemDocument
821 816
822 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo') 817 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
823 818
@@ -832,7 +827,7 @@ describe('Test videos API validator', function () {
832 }) 827 })
833 828
834 it('Should succeed with the correct parameters', async function () { 829 it('Should succeed with the correct parameters', async function () {
835 await removeVideo(server.url, server.accessToken, video.uuid) 830 await server.videos.remove({ id: video.uuid })
836 }) 831 })
837 }) 832 })
838 833