]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos.ts
Introduce server commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / videos.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
0e1dc3e7 2
f6d6e7f8 3import 'mocha'
0e1dc3e7 4import * as chai from 'chai'
11ba2ab3 5import { omit } from 'lodash'
11ba2ab3 6import { join } from 'path'
e030bfb5 7import { randomInt } from '@shared/core-utils'
d4a8e7a6 8import { PeerTubeProblemDocument, VideoCreateResult } from '@shared/models'
f6d6e7f8 9import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
0e1dc3e7 10import {
f6d6e7f8 11 checkUploadVideoParam,
7c3b7976
C
12 cleanupTests,
13 createUser,
14 flushAndRunServer,
15 getMyUserInformation,
16 getVideo,
17 getVideosList,
7c3b7976
C
18 makeDeleteRequest,
19 makeGetRequest,
20 makePutBodyRequest,
21 makeUploadRequest,
22 removeVideo,
f6d6e7f8 23 root,
7c3b7976
C
24 ServerInfo,
25 setAccessTokensToServers,
f6d6e7f8 26 userLogin
94565d52 27} from '../../../../shared/extra-utils'
9639bd17 28import {
29 checkBadCountPagination,
30 checkBadSortPagination,
31 checkBadStartPagination
94565d52 32} from '../../../../shared/extra-utils/requests/check-api-params'
f6d6e7f8 33import { VideoPrivacy } from '../../../../shared/models/videos/video-privacy.enum'
11ba2ab3
C
34
35const expect = chai.expect
0e1dc3e7
C
36
37describe('Test videos API validator', function () {
38 const path = '/api/v1/videos/'
39 let server: ServerInfo
6221f311 40 let userAccessToken = ''
ad9e39fb 41 let accountName: string
5f04dd2f 42 let channelId: number
f6eebcb3 43 let channelName: string
d4a8e7a6 44 let video: VideoCreateResult
0e1dc3e7
C
45
46 // ---------------------------------------------------------------
47
48 before(async function () {
e212f887 49 this.timeout(30000)
0e1dc3e7 50
210feb6c 51 server = await flushAndRunServer(1)
0e1dc3e7
C
52
53 await setAccessTokensToServers([ server ])
5f04dd2f 54
6221f311
C
55 const username = 'user1'
56 const password = 'my super password'
1eddc9a7 57 await createUser({ url: server.url, accessToken: server.accessToken, username: username, password: password })
6221f311
C
58 userAccessToken = await userLogin(server, { username, password })
59
6b738c7a
C
60 {
61 const res = await getMyUserInformation(server.url, server.accessToken)
a1587156
C
62 channelId = res.body.videoChannels[0].id
63 channelName = res.body.videoChannels[0].name
ad9e39fb 64 accountName = res.body.account.name + '@' + res.body.account.host
6b738c7a 65 }
0e1dc3e7
C
66 })
67
bfbd9128 68 describe('When listing videos', function () {
0e1dc3e7 69 it('Should fail with a bad start pagination', async function () {
11ba2ab3 70 await checkBadStartPagination(server.url, path)
0e1dc3e7
C
71 })
72
73 it('Should fail with a bad count pagination', async function () {
11ba2ab3 74 await checkBadCountPagination(server.url, path)
0e1dc3e7
C
75 })
76
77 it('Should fail with an incorrect sort', async function () {
11ba2ab3 78 await checkBadSortPagination(server.url, path)
0e1dc3e7 79 })
6b738c7a 80
fe987656 81 it('Should fail with a bad skipVideos query', async function () {
2d53be02 82 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: 'toto' } })
fe987656
C
83 })
84
6b738c7a 85 it('Should success with the correct parameters', async function () {
2d53be02 86 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200, query: { skipCount: false } })
6b738c7a 87 })
0e1dc3e7
C
88 })
89
90 describe('When searching a video', function () {
11ba2ab3 91
0e1dc3e7 92 it('Should fail with nothing', async function () {
11ba2ab3
C
93 await makeGetRequest({
94 url: server.url,
95 path: join(path, 'search'),
2d53be02 96 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
11ba2ab3 97 })
0e1dc3e7
C
98 })
99
100 it('Should fail with a bad start pagination', async function () {
11ba2ab3 101 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
0e1dc3e7
C
102 })
103
104 it('Should fail with a bad count pagination', async function () {
11ba2ab3 105 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
0e1dc3e7
C
106 })
107
108 it('Should fail with an incorrect sort', async function () {
11ba2ab3 109 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
0e1dc3e7 110 })
6b738c7a
C
111
112 it('Should success with the correct parameters', async function () {
2d53be02 113 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
6b738c7a 114 })
0e1dc3e7
C
115 })
116
11474c3c
C
117 describe('When listing my videos', function () {
118 const path = '/api/v1/users/me/videos'
119
120 it('Should fail with a bad start pagination', async function () {
11ba2ab3 121 await checkBadStartPagination(server.url, path, server.accessToken)
11474c3c
C
122 })
123
124 it('Should fail with a bad count pagination', async function () {
11ba2ab3 125 await checkBadCountPagination(server.url, path, server.accessToken)
11474c3c
C
126 })
127
128 it('Should fail with an incorrect sort', async function () {
11ba2ab3 129 await checkBadSortPagination(server.url, path, server.accessToken)
11474c3c 130 })
6b738c7a
C
131
132 it('Should success with the correct parameters', async function () {
2d53be02 133 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: HttpStatusCode.OK_200 })
6b738c7a
C
134 })
135 })
136
137 describe('When listing account videos', function () {
138 let path: string
139
140 before(async function () {
ad9e39fb 141 path = '/api/v1/accounts/' + accountName + '/videos'
6b738c7a
C
142 })
143
144 it('Should fail with a bad start pagination', async function () {
145 await checkBadStartPagination(server.url, path, server.accessToken)
146 })
147
148 it('Should fail with a bad count pagination', async function () {
149 await checkBadCountPagination(server.url, path, server.accessToken)
150 })
151
152 it('Should fail with an incorrect sort', async function () {
153 await checkBadSortPagination(server.url, path, server.accessToken)
154 })
155
156 it('Should success with the correct parameters', async function () {
2d53be02 157 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
6b738c7a
C
158 })
159 })
160
161 describe('When listing video channel videos', function () {
162 let path: string
163
164 before(async function () {
f6eebcb3 165 path = '/api/v1/video-channels/' + channelName + '/videos'
6b738c7a
C
166 })
167
168 it('Should fail with a bad start pagination', async function () {
169 await checkBadStartPagination(server.url, path, server.accessToken)
170 })
171
172 it('Should fail with a bad count pagination', async function () {
173 await checkBadCountPagination(server.url, path, server.accessToken)
174 })
175
176 it('Should fail with an incorrect sort', async function () {
177 await checkBadSortPagination(server.url, path, server.accessToken)
178 })
179
180 it('Should success with the correct parameters', async function () {
2d53be02 181 await makeGetRequest({ url: server.url, path, statusCodeExpected: HttpStatusCode.OK_200 })
6b738c7a 182 })
11474c3c
C
183 })
184
0e1dc3e7 185 describe('When adding a video', function () {
11ba2ab3
C
186 let baseCorrectParams
187 const baseCorrectAttaches = {
f6d6e7f8 188 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.webm')
11ba2ab3
C
189 }
190
191 before(function () {
192 // Put in before to have channelId
193 baseCorrectParams = {
194 name: 'my super name',
195 category: 5,
196 licence: 1,
9d3ef9fe 197 language: 'pt',
11ba2ab3 198 nsfw: false,
47564bbe 199 commentsEnabled: true,
7f2cfe3a 200 downloadEnabled: true,
2186386c 201 waitTranscoding: true,
11ba2ab3 202 description: 'my super description',
2422c46b 203 support: 'my super support text',
11ba2ab3
C
204 tags: [ 'tag1', 'tag2' ],
205 privacy: VideoPrivacy.PUBLIC,
7519127b
C
206 channelId: channelId,
207 originallyPublishedAt: new Date().toISOString()
11ba2ab3
C
208 }
209 })
210
f6d6e7f8 211 function runSuite (mode: 'legacy' | 'resumable') {
0e1dc3e7 212
f6d6e7f8 213 it('Should fail with nothing', async function () {
214 const fields = {}
215 const attaches = {}
216 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
217 })
11474c3c 218
f6d6e7f8 219 it('Should fail without name', async function () {
220 const fields = omit(baseCorrectParams, 'name')
221 const attaches = baseCorrectAttaches
0e1dc3e7 222
f6d6e7f8 223 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
224 })
11474c3c 225
f6d6e7f8 226 it('Should fail with a long name', async function () {
6c5065a0 227 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
f6d6e7f8 228 const attaches = baseCorrectAttaches
0e1dc3e7 229
f6d6e7f8 230 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
231 })
11474c3c 232
f6d6e7f8 233 it('Should fail with a bad category', async function () {
6c5065a0 234 const fields = { ...baseCorrectParams, category: 125 }
f6d6e7f8 235 const attaches = baseCorrectAttaches
0e1dc3e7 236
f6d6e7f8 237 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
238 })
11474c3c 239
f6d6e7f8 240 it('Should fail with a bad licence', async function () {
6c5065a0 241 const fields = { ...baseCorrectParams, licence: 125 }
f6d6e7f8 242 const attaches = baseCorrectAttaches
0e1dc3e7 243
f6d6e7f8 244 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
245 })
11474c3c 246
f6d6e7f8 247 it('Should fail with a bad language', async function () {
6c5065a0 248 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
f6d6e7f8 249 const attaches = baseCorrectAttaches
0e1dc3e7 250
f6d6e7f8 251 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
252 })
2422c46b 253
f6d6e7f8 254 it('Should fail with a long description', async function () {
6c5065a0 255 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
f6d6e7f8 256 const attaches = baseCorrectAttaches
2422c46b 257
f6d6e7f8 258 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
259 })
11474c3c 260
f6d6e7f8 261 it('Should fail with a long support text', async function () {
6c5065a0 262 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
f6d6e7f8 263 const attaches = baseCorrectAttaches
5f04dd2f 264
f6d6e7f8 265 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
266 })
11474c3c 267
f6d6e7f8 268 it('Should fail without a channel', async function () {
269 const fields = omit(baseCorrectParams, 'channelId')
270 const attaches = baseCorrectAttaches
0e1dc3e7 271
f6d6e7f8 272 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
273 })
11474c3c 274
f6d6e7f8 275 it('Should fail with a bad channel', async function () {
6c5065a0 276 const fields = { ...baseCorrectParams, channelId: 545454 }
f6d6e7f8 277 const attaches = baseCorrectAttaches
5f04dd2f 278
f6d6e7f8 279 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
280 })
5f04dd2f 281
f6d6e7f8 282 it('Should fail with another user channel', async function () {
283 const user = {
284 username: 'fake' + randomInt(0, 1500),
285 password: 'fake_password'
286 }
287 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
11474c3c 288
f6d6e7f8 289 const accessTokenUser = await userLogin(server, user)
290 const res = await getMyUserInformation(server.url, accessTokenUser)
291 const customChannelId = res.body.videoChannels[0].id
11474c3c 292
6c5065a0 293 const fields = { ...baseCorrectParams, channelId: customChannelId }
f6d6e7f8 294 const attaches = baseCorrectAttaches
5f04dd2f 295
f6d6e7f8 296 await checkUploadVideoParam(server.url, userAccessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
297 })
11474c3c 298
f6d6e7f8 299 it('Should fail with too many tags', async function () {
6c5065a0 300 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
f6d6e7f8 301 const attaches = baseCorrectAttaches
0e1dc3e7 302
f6d6e7f8 303 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
304 })
11474c3c 305
f6d6e7f8 306 it('Should fail with a tag length too low', async function () {
6c5065a0 307 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
f6d6e7f8 308 const attaches = baseCorrectAttaches
0e1dc3e7 309
f6d6e7f8 310 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
311 })
11474c3c 312
f6d6e7f8 313 it('Should fail with a tag length too big', async function () {
6c5065a0 314 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
f6d6e7f8 315 const attaches = baseCorrectAttaches
0e1dc3e7 316
f6d6e7f8 317 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
318 })
bbe0f064 319
f6d6e7f8 320 it('Should fail with a bad schedule update (miss updateAt)', async function () {
6c5065a0 321 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
f6d6e7f8 322 const attaches = baseCorrectAttaches
bbe0f064 323
f6d6e7f8 324 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
bbe0f064 325 })
bbe0f064 326
f6d6e7f8 327 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
6c5065a0
C
328 const fields = {
329 ...baseCorrectParams,
330
f6d6e7f8 331 scheduleUpdate: {
332 privacy: VideoPrivacy.PUBLIC,
333 updateAt: 'toto'
334 }
6c5065a0 335 }
f6d6e7f8 336 const attaches = baseCorrectAttaches
bbe0f064 337
f6d6e7f8 338 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
339 })
7519127b 340
f6d6e7f8 341 it('Should fail with a bad originally published at attribute', async function () {
6c5065a0 342 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
f6d6e7f8 343 const attaches = baseCorrectAttaches
7519127b 344
f6d6e7f8 345 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
346 })
0e1dc3e7 347
f6d6e7f8 348 it('Should fail without an input file', async function () {
349 const fields = baseCorrectParams
350 const attaches = {}
351 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
f2eb23cd 352 })
14e2014a 353
f6d6e7f8 354 it('Should fail with an incorrect input file', async function () {
355 const fields = baseCorrectParams
356 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
357
358 await checkUploadVideoParam(
359 server.url,
360 server.accessToken,
361 { ...fields, ...attaches },
362 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
363 mode
364 )
365
366 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
367 await checkUploadVideoParam(
368 server.url,
369 server.accessToken,
370 { ...fields, ...attaches },
371 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
372 mode
373 )
f2eb23cd 374 })
ac81d1a0 375
f6d6e7f8 376 it('Should fail with an incorrect thumbnail file', async function () {
377 const fields = baseCorrectParams
378 const attaches = {
379 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
380 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
381 }
ac81d1a0 382
f6d6e7f8 383 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
384 })
ac81d1a0 385
f6d6e7f8 386 it('Should fail with a big thumbnail file', async function () {
387 const fields = baseCorrectParams
388 const attaches = {
389 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
390 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
391 }
ac81d1a0 392
f6d6e7f8 393 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
394 })
ac81d1a0 395
f6d6e7f8 396 it('Should fail with an incorrect preview file', async function () {
397 const fields = baseCorrectParams
398 const attaches = {
399 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
400 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
401 }
ac81d1a0 402
f6d6e7f8 403 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
404 })
ac81d1a0 405
f6d6e7f8 406 it('Should fail with a big preview file', async function () {
407 const fields = baseCorrectParams
408 const attaches = {
409 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
410 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
411 }
ac81d1a0 412
f6d6e7f8 413 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
414 })
0e1dc3e7 415
e030bfb5 416 it('Should report the appropriate error', async function () {
6c5065a0 417 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
e030bfb5
C
418 const attaches = baseCorrectAttaches
419
420 const attributes = { ...fields, ...attaches }
421 const res = await checkUploadVideoParam(server.url, server.accessToken, attributes, HttpStatusCode.BAD_REQUEST_400, mode)
422
423 const error = res.body as PeerTubeProblemDocument
424
425 if (mode === 'legacy') {
426 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadLegacy')
427 } else {
428 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/uploadResumableInit')
429 }
430
431 expect(error.type).to.equal('about:blank')
432 expect(error.title).to.equal('Bad Request')
433
434 expect(error.detail).to.equal('Incorrect request parameters: language')
435 expect(error.error).to.equal('Incorrect request parameters: language')
436
437 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
438 expect(error['invalid-params'].language).to.exist
439 })
440
f6d6e7f8 441 it('Should succeed with the correct parameters', async function () {
442 this.timeout(10000)
0e1dc3e7 443
f6d6e7f8 444 const fields = baseCorrectParams
11ba2ab3 445
f6d6e7f8 446 {
447 const attaches = baseCorrectAttaches
448 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
449 }
0e1dc3e7 450
f6d6e7f8 451 {
6c5065a0
C
452 const attaches = {
453 ...baseCorrectAttaches,
454
f6d6e7f8 455 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
6c5065a0 456 }
11ba2ab3 457
f6d6e7f8 458 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
459 }
0e1dc3e7 460
f6d6e7f8 461 {
6c5065a0
C
462 const attaches = {
463 ...baseCorrectAttaches,
464
f6d6e7f8 465 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
6c5065a0 466 }
11ba2ab3 467
f6d6e7f8 468 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
469 }
470 })
471 }
472
473 describe('Resumable upload', function () {
474 runSuite('resumable')
475 })
476
477 describe('Legacy upload', function () {
478 runSuite('legacy')
0e1dc3e7
C
479 })
480 })
481
482 describe('When updating a video', function () {
11ba2ab3
C
483 const baseCorrectParams = {
484 name: 'my super name',
485 category: 5,
486 licence: 2,
9d3ef9fe 487 language: 'pt',
11ba2ab3 488 nsfw: false,
47564bbe 489 commentsEnabled: false,
7f2cfe3a 490 downloadEnabled: false,
11ba2ab3
C
491 description: 'my super description',
492 privacy: VideoPrivacy.PUBLIC,
493 tags: [ 'tag1', 'tag2' ]
494 }
0e1dc3e7
C
495
496 before(async function () {
497 const res = await getVideosList(server.url)
d4a8e7a6 498 video = res.body.data[0]
0e1dc3e7
C
499 })
500
501 it('Should fail with nothing', async function () {
502 const fields = {}
503 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
504 })
505
506 it('Should fail without a valid uuid', async function () {
11ba2ab3 507 const fields = baseCorrectParams
0e1dc3e7
C
508 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
509 })
510
511 it('Should fail with an unknown id', async function () {
11ba2ab3 512 const fields = baseCorrectParams
11474c3c 513
0e1dc3e7
C
514 await makePutBodyRequest({
515 url: server.url,
516 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
517 token: server.accessToken,
518 fields,
2d53be02 519 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
0e1dc3e7
C
520 })
521 })
522
523 it('Should fail with a long name', async function () {
6c5065a0 524 const fields = { ...baseCorrectParams, name: 'super'.repeat(65) }
11474c3c 525
d4a8e7a6 526 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
527 })
528
529 it('Should fail with a bad category', async function () {
6c5065a0 530 const fields = { ...baseCorrectParams, category: 125 }
11474c3c 531
d4a8e7a6 532 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
533 })
534
535 it('Should fail with a bad licence', async function () {
6c5065a0 536 const fields = { ...baseCorrectParams, licence: 125 }
11474c3c 537
d4a8e7a6 538 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
539 })
540
541 it('Should fail with a bad language', async function () {
6c5065a0 542 const fields = { ...baseCorrectParams, language: 'a'.repeat(15) }
11474c3c 543
d4a8e7a6 544 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
545 })
546
0e1dc3e7 547 it('Should fail with a long description', async function () {
6c5065a0 548 const fields = { ...baseCorrectParams, description: 'super'.repeat(2500) }
2422c46b 549
d4a8e7a6 550 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
2422c46b
C
551 })
552
553 it('Should fail with a long support text', async function () {
6c5065a0 554 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
11474c3c 555
d4a8e7a6 556 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
557 })
558
7fb39378 559 it('Should fail with a bad channel', async function () {
6c5065a0 560 const fields = { ...baseCorrectParams, channelId: 545454 }
7fb39378 561
d4a8e7a6 562 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
7fb39378
C
563 })
564
0e1dc3e7 565 it('Should fail with too many tags', async function () {
6c5065a0 566 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }
11474c3c 567
d4a8e7a6 568 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
569 })
570
571 it('Should fail with a tag length too low', async function () {
6c5065a0 572 const fields = { ...baseCorrectParams, tags: [ 'tag1', 't' ] }
11474c3c 573
d4a8e7a6 574 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
575 })
576
577 it('Should fail with a tag length too big', async function () {
6c5065a0 578 const fields = { ...baseCorrectParams, tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }
11474c3c 579
d4a8e7a6 580 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
0e1dc3e7
C
581 })
582
bbe0f064 583 it('Should fail with a bad schedule update (miss updateAt)', async function () {
6c5065a0 584 const fields = { ...baseCorrectParams, scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }
bbe0f064 585
d4a8e7a6 586 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
bbe0f064
C
587 })
588
589 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
6c5065a0 590 const fields = { ...baseCorrectParams, scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }
bbe0f064 591
d4a8e7a6 592 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
bbe0f064
C
593 })
594
7519127b 595 it('Should fail with a bad originally published at param', async function () {
6c5065a0 596 const fields = { ...baseCorrectParams, originallyPublishedAt: 'toto' }
7519127b 597
d4a8e7a6 598 await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
7519127b
C
599 })
600
ac81d1a0
C
601 it('Should fail with an incorrect thumbnail file', async function () {
602 const fields = baseCorrectParams
603 const attaches = {
e9cb361c 604 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
ac81d1a0
C
605 }
606
607 await makeUploadRequest({
608 url: server.url,
609 method: 'PUT',
d4a8e7a6 610 path: path + video.shortUUID,
ac81d1a0
C
611 token: server.accessToken,
612 fields,
613 attaches
614 })
615 })
616
617 it('Should fail with a big thumbnail file', async function () {
618 const fields = baseCorrectParams
619 const attaches = {
e9cb361c 620 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
ac81d1a0
C
621 }
622
623 await makeUploadRequest({
624 url: server.url,
625 method: 'PUT',
d4a8e7a6 626 path: path + video.shortUUID,
ac81d1a0
C
627 token: server.accessToken,
628 fields,
629 attaches
630 })
631 })
632
633 it('Should fail with an incorrect preview file', async function () {
634 const fields = baseCorrectParams
635 const attaches = {
e9cb361c 636 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
ac81d1a0
C
637 }
638
639 await makeUploadRequest({
640 url: server.url,
641 method: 'PUT',
d4a8e7a6 642 path: path + video.shortUUID,
ac81d1a0
C
643 token: server.accessToken,
644 fields,
645 attaches
646 })
647 })
648
649 it('Should fail with a big preview file', async function () {
650 const fields = baseCorrectParams
651 const attaches = {
e9cb361c 652 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
ac81d1a0
C
653 }
654
655 await makeUploadRequest({
656 url: server.url,
657 method: 'PUT',
d4a8e7a6 658 path: path + video.shortUUID,
ac81d1a0
C
659 token: server.accessToken,
660 fields,
661 attaches
662 })
663 })
664
6221f311
C
665 it('Should fail with a video of another user without the appropriate right', async function () {
666 const fields = baseCorrectParams
667
2d53be02
RK
668 await makePutBodyRequest({
669 url: server.url,
d4a8e7a6 670 path: path + video.shortUUID,
2d53be02
RK
671 token: userAccessToken,
672 fields,
673 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
674 })
6221f311 675 })
0e1dc3e7 676
9a27cdc2 677 it('Should fail with a video of another server')
11474c3c 678
e030bfb5 679 it('Shoud report the appropriate error', async function () {
6c5065a0 680 const fields = { ...baseCorrectParams, licence: 125 }
e030bfb5 681
d4a8e7a6 682 const res = await makePutBodyRequest({ url: server.url, path: path + video.shortUUID, token: server.accessToken, fields })
e030bfb5
C
683 const error = res.body as PeerTubeProblemDocument
684
685 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/putVideo')
686
687 expect(error.type).to.equal('about:blank')
688 expect(error.title).to.equal('Bad Request')
689
690 expect(error.detail).to.equal('Incorrect request parameters: licence')
691 expect(error.error).to.equal('Incorrect request parameters: licence')
692
693 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
694 expect(error['invalid-params'].licence).to.exist
695 })
696
11474c3c 697 it('Should succeed with the correct parameters', async function () {
11ba2ab3 698 const fields = baseCorrectParams
11474c3c 699
2d53be02
RK
700 await makePutBodyRequest({
701 url: server.url,
d4a8e7a6 702 path: path + video.shortUUID,
2d53be02
RK
703 token: server.accessToken,
704 fields,
705 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
706 })
11474c3c 707 })
0e1dc3e7
C
708 })
709
710 describe('When getting a video', function () {
711 it('Should return the list of the videos with nothing', async function () {
11ba2ab3
C
712 const res = await makeGetRequest({
713 url: server.url,
714 path,
2d53be02 715 statusCodeExpected: HttpStatusCode.OK_200
11ba2ab3 716 })
0e1dc3e7
C
717
718 expect(res.body.data).to.be.an('array')
f6d6e7f8 719 expect(res.body.data.length).to.equal(6)
0e1dc3e7
C
720 })
721
722 it('Should fail without a correct uuid', async function () {
2d53be02 723 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
0e1dc3e7
C
724 })
725
726 it('Should return 404 with an incorrect video', async function () {
2d53be02 727 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
0e1dc3e7
C
728 })
729
e030bfb5
C
730 it('Shoud report the appropriate error', async function () {
731 const res = await getVideo(server.url, 'hi', HttpStatusCode.BAD_REQUEST_400)
732 const error = res.body as PeerTubeProblemDocument
733
734 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/getVideo')
735
736 expect(error.type).to.equal('about:blank')
737 expect(error.title).to.equal('Bad Request')
738
739 expect(error.detail).to.equal('Incorrect request parameters: id')
740 expect(error.error).to.equal('Incorrect request parameters: id')
741
742 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
743 expect(error['invalid-params'].id).to.exist
744 })
745
6221f311 746 it('Should succeed with the correct parameters', async function () {
d4a8e7a6 747 await getVideo(server.url, video.shortUUID)
6221f311 748 })
0e1dc3e7
C
749 })
750
751 describe('When rating a video', function () {
752 let videoId
753
754 before(async function () {
755 const res = await getVideosList(server.url)
756 videoId = res.body.data[0].id
757 })
758
759 it('Should fail without a valid uuid', async function () {
760 const fields = {
761 rating: 'like'
762 }
763 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
764 })
765
766 it('Should fail with an unknown id', async function () {
767 const fields = {
768 rating: 'like'
769 }
770 await makePutBodyRequest({
771 url: server.url,
772 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
773 token: server.accessToken,
774 fields,
2d53be02 775 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
0e1dc3e7
C
776 })
777 })
778
779 it('Should fail with a wrong rating', async function () {
780 const fields = {
781 rating: 'likes'
782 }
783 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
784 })
785
786 it('Should succeed with the correct parameters', async function () {
787 const fields = {
788 rating: 'like'
789 }
790 await makePutBodyRequest({
791 url: server.url,
792 path: path + videoId + '/rate',
793 token: server.accessToken,
794 fields,
2d53be02 795 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
0e1dc3e7
C
796 })
797 })
798 })
799
800 describe('When removing a video', function () {
801 it('Should have 404 with nothing', async function () {
11ba2ab3
C
802 await makeDeleteRequest({
803 url: server.url,
804 path,
2d53be02 805 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
11ba2ab3 806 })
0e1dc3e7
C
807 })
808
809 it('Should fail without a correct uuid', async function () {
2d53be02 810 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
0e1dc3e7
C
811 })
812
813 it('Should fail with a video which does not exist', async function () {
2d53be02 814 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
0e1dc3e7
C
815 })
816
6221f311 817 it('Should fail with a video of another user without the appropriate right', async function () {
d4a8e7a6 818 await removeVideo(server.url, userAccessToken, video.uuid, HttpStatusCode.FORBIDDEN_403)
6221f311 819 })
0e1dc3e7 820
9a27cdc2 821 it('Should fail with a video of another server')
0e1dc3e7 822
e030bfb5
C
823 it('Shoud report the appropriate error', async function () {
824 const res = await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
825 const error = res.body as PeerTubeProblemDocument
826
827 expect(error.docs).to.equal('https://docs.joinpeertube.org/api-rest-reference.html#operation/delVideo')
828
829 expect(error.type).to.equal('about:blank')
830 expect(error.title).to.equal('Bad Request')
831
832 expect(error.detail).to.equal('Incorrect request parameters: id')
833 expect(error.error).to.equal('Incorrect request parameters: id')
834
835 expect(error.status).to.equal(HttpStatusCode.BAD_REQUEST_400)
836 expect(error['invalid-params'].id).to.exist
837 })
838
6221f311 839 it('Should succeed with the correct parameters', async function () {
d4a8e7a6 840 await removeVideo(server.url, server.accessToken, video.uuid)
6221f311 841 })
0e1dc3e7
C
842 })
843
7c3b7976
C
844 after(async function () {
845 await cleanupTests([ server ])
0e1dc3e7
C
846 })
847})