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