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