]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos.ts
Merge branch 'release/3.2.0' into develop
[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'
f6d6e7f8 7import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
0e1dc3e7 8import {
f6d6e7f8 9 checkUploadVideoParam,
7c3b7976
C
10 cleanupTests,
11 createUser,
12 flushAndRunServer,
13 getMyUserInformation,
14 getVideo,
15 getVideosList,
16 immutableAssign,
17 makeDeleteRequest,
18 makeGetRequest,
19 makePutBodyRequest,
20 makeUploadRequest,
21 removeVideo,
f6d6e7f8 22 root,
7c3b7976
C
23 ServerInfo,
24 setAccessTokensToServers,
f6d6e7f8 25 userLogin
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'
33import { randomInt } from '@shared/core-utils'
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
6221f311 44 let videoId
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 () {
227 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
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 () {
234 const fields = immutableAssign(baseCorrectParams, { category: 125 })
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 () {
241 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
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 () {
248 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
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 () {
255 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
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 () {
262 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
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 () {
276 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
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
f6d6e7f8 293 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
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 () {
300 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
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 () {
307 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
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 () {
314 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
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 () {
321 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
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 () {
328 const fields = immutableAssign(baseCorrectParams, {
329 scheduleUpdate: {
330 privacy: VideoPrivacy.PUBLIC,
331 updateAt: 'toto'
332 }
333 })
334 const attaches = baseCorrectAttaches
bbe0f064 335
f6d6e7f8 336 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
337 })
7519127b 338
f6d6e7f8 339 it('Should fail with a bad originally published at attribute', async function () {
340 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
341 const attaches = baseCorrectAttaches
7519127b 342
f6d6e7f8 343 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
344 })
0e1dc3e7 345
f6d6e7f8 346 it('Should fail without an input file', async function () {
347 const fields = baseCorrectParams
348 const attaches = {}
349 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
f2eb23cd 350 })
14e2014a 351
f6d6e7f8 352 it('Should fail with an incorrect input file', async function () {
353 const fields = baseCorrectParams
354 let attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short_fake.webm') }
355
356 await checkUploadVideoParam(
357 server.url,
358 server.accessToken,
359 { ...fields, ...attaches },
360 HttpStatusCode.UNPROCESSABLE_ENTITY_422,
361 mode
362 )
363
364 attaches = { fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mkv') }
365 await checkUploadVideoParam(
366 server.url,
367 server.accessToken,
368 { ...fields, ...attaches },
369 HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415,
370 mode
371 )
f2eb23cd 372 })
ac81d1a0 373
f6d6e7f8 374 it('Should fail with an incorrect thumbnail file', async function () {
375 const fields = baseCorrectParams
376 const attaches = {
377 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
378 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
379 }
ac81d1a0 380
f6d6e7f8 381 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
382 })
ac81d1a0 383
f6d6e7f8 384 it('Should fail with a big thumbnail file', async function () {
385 const fields = baseCorrectParams
386 const attaches = {
387 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
388 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
389 }
ac81d1a0 390
f6d6e7f8 391 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
392 })
ac81d1a0 393
f6d6e7f8 394 it('Should fail with an incorrect preview file', async function () {
395 const fields = baseCorrectParams
396 const attaches = {
397 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4'),
398 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
399 }
ac81d1a0 400
f6d6e7f8 401 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
402 })
ac81d1a0 403
f6d6e7f8 404 it('Should fail with a big preview file', async function () {
405 const fields = baseCorrectParams
406 const attaches = {
407 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png'),
408 fixture: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
409 }
ac81d1a0 410
f6d6e7f8 411 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.BAD_REQUEST_400, mode)
412 })
0e1dc3e7 413
f6d6e7f8 414 it('Should succeed with the correct parameters', async function () {
415 this.timeout(10000)
0e1dc3e7 416
f6d6e7f8 417 const fields = baseCorrectParams
11ba2ab3 418
f6d6e7f8 419 {
420 const attaches = baseCorrectAttaches
421 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
422 }
0e1dc3e7 423
f6d6e7f8 424 {
425 const attaches = immutableAssign(baseCorrectAttaches, {
426 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
427 })
11ba2ab3 428
f6d6e7f8 429 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
430 }
0e1dc3e7 431
f6d6e7f8 432 {
433 const attaches = immutableAssign(baseCorrectAttaches, {
434 videofile: join(root(), 'server', 'tests', 'fixtures', 'video_short.ogv')
435 })
11ba2ab3 436
f6d6e7f8 437 await checkUploadVideoParam(server.url, server.accessToken, { ...fields, ...attaches }, HttpStatusCode.OK_200, mode)
438 }
439 })
440 }
441
442 describe('Resumable upload', function () {
443 runSuite('resumable')
444 })
445
446 describe('Legacy upload', function () {
447 runSuite('legacy')
0e1dc3e7
C
448 })
449 })
450
451 describe('When updating a video', function () {
11ba2ab3
C
452 const baseCorrectParams = {
453 name: 'my super name',
454 category: 5,
455 licence: 2,
9d3ef9fe 456 language: 'pt',
11ba2ab3 457 nsfw: false,
47564bbe 458 commentsEnabled: false,
7f2cfe3a 459 downloadEnabled: false,
11ba2ab3
C
460 description: 'my super description',
461 privacy: VideoPrivacy.PUBLIC,
462 tags: [ 'tag1', 'tag2' ]
463 }
0e1dc3e7
C
464
465 before(async function () {
466 const res = await getVideosList(server.url)
6221f311 467 videoId = res.body.data[0].uuid
0e1dc3e7
C
468 })
469
470 it('Should fail with nothing', async function () {
471 const fields = {}
472 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
473 })
474
475 it('Should fail without a valid uuid', async function () {
11ba2ab3 476 const fields = baseCorrectParams
0e1dc3e7
C
477 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
478 })
479
480 it('Should fail with an unknown id', async function () {
11ba2ab3 481 const fields = baseCorrectParams
11474c3c 482
0e1dc3e7
C
483 await makePutBodyRequest({
484 url: server.url,
485 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
486 token: server.accessToken,
487 fields,
2d53be02 488 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
0e1dc3e7
C
489 })
490 })
491
492 it('Should fail with a long name', async function () {
11ba2ab3 493 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
11474c3c 494
0e1dc3e7
C
495 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
496 })
497
498 it('Should fail with a bad category', async function () {
11ba2ab3 499 const fields = immutableAssign(baseCorrectParams, { category: 125 })
11474c3c 500
0e1dc3e7
C
501 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
502 })
503
504 it('Should fail with a bad licence', async function () {
11ba2ab3 505 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
11474c3c 506
0e1dc3e7
C
507 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
508 })
509
510 it('Should fail with a bad language', async function () {
9d3ef9fe 511 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
11474c3c 512
0e1dc3e7
C
513 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
514 })
515
0e1dc3e7 516 it('Should fail with a long description', async function () {
2422c46b
C
517 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
518
519 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
520 })
521
522 it('Should fail with a long support text', async function () {
d23e6a1c 523 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
11474c3c 524
0e1dc3e7
C
525 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
526 })
527
7fb39378
C
528 it('Should fail with a bad channel', async function () {
529 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
530
531 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
532 })
533
0e1dc3e7 534 it('Should fail with too many tags', async function () {
11ba2ab3 535 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
11474c3c 536
0e1dc3e7
C
537 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
538 })
539
540 it('Should fail with a tag length too low', async function () {
11ba2ab3 541 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
11474c3c 542
0e1dc3e7
C
543 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
544 })
545
546 it('Should fail with a tag length too big', async function () {
11ba2ab3 547 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
11474c3c 548
0e1dc3e7
C
549 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
550 })
551
bbe0f064
C
552 it('Should fail with a bad schedule update (miss updateAt)', async function () {
553 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
554
555 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
556 })
557
558 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
559 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
560
561 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
562 })
563
7519127b
C
564 it('Should fail with a bad originally published at param', async function () {
565 const fields = immutableAssign(baseCorrectParams, { originallyPublishedAt: 'toto' })
566
567 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
568 })
569
ac81d1a0
C
570 it('Should fail with an incorrect thumbnail file', async function () {
571 const fields = baseCorrectParams
572 const attaches = {
e9cb361c 573 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
ac81d1a0
C
574 }
575
576 await makeUploadRequest({
577 url: server.url,
578 method: 'PUT',
579 path: path + videoId,
580 token: server.accessToken,
581 fields,
582 attaches
583 })
584 })
585
586 it('Should fail with a big thumbnail file', async function () {
587 const fields = baseCorrectParams
588 const attaches = {
e9cb361c 589 thumbnailfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
ac81d1a0
C
590 }
591
592 await makeUploadRequest({
593 url: server.url,
594 method: 'PUT',
595 path: path + videoId,
596 token: server.accessToken,
597 fields,
598 attaches
599 })
600 })
601
602 it('Should fail with an incorrect preview file', async function () {
603 const fields = baseCorrectParams
604 const attaches = {
e9cb361c 605 previewfile: join(root(), 'server', 'tests', 'fixtures', 'video_short.mp4')
ac81d1a0
C
606 }
607
608 await makeUploadRequest({
609 url: server.url,
610 method: 'PUT',
611 path: path + videoId,
612 token: server.accessToken,
613 fields,
614 attaches
615 })
616 })
617
618 it('Should fail with a big preview file', async function () {
619 const fields = baseCorrectParams
620 const attaches = {
e9cb361c 621 previewfile: join(root(), 'server', 'tests', 'fixtures', 'preview-big.png')
ac81d1a0
C
622 }
623
624 await makeUploadRequest({
625 url: server.url,
626 method: 'PUT',
627 path: path + videoId,
628 token: server.accessToken,
629 fields,
630 attaches
631 })
632 })
633
6221f311
C
634 it('Should fail with a video of another user without the appropriate right', async function () {
635 const fields = baseCorrectParams
636
2d53be02
RK
637 await makePutBodyRequest({
638 url: server.url,
639 path: path + videoId,
640 token: userAccessToken,
641 fields,
642 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
643 })
6221f311 644 })
0e1dc3e7 645
9a27cdc2 646 it('Should fail with a video of another server')
11474c3c
C
647
648 it('Should succeed with the correct parameters', async function () {
11ba2ab3 649 const fields = baseCorrectParams
11474c3c 650
2d53be02
RK
651 await makePutBodyRequest({
652 url: server.url,
653 path: path + videoId,
654 token: server.accessToken,
655 fields,
656 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
657 })
11474c3c 658 })
0e1dc3e7
C
659 })
660
661 describe('When getting a video', function () {
662 it('Should return the list of the videos with nothing', async function () {
11ba2ab3
C
663 const res = await makeGetRequest({
664 url: server.url,
665 path,
2d53be02 666 statusCodeExpected: HttpStatusCode.OK_200
11ba2ab3 667 })
0e1dc3e7
C
668
669 expect(res.body.data).to.be.an('array')
f6d6e7f8 670 expect(res.body.data.length).to.equal(6)
0e1dc3e7
C
671 })
672
673 it('Should fail without a correct uuid', async function () {
2d53be02 674 await getVideo(server.url, 'coucou', HttpStatusCode.BAD_REQUEST_400)
0e1dc3e7
C
675 })
676
677 it('Should return 404 with an incorrect video', async function () {
2d53be02 678 await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
0e1dc3e7
C
679 })
680
6221f311
C
681 it('Should succeed with the correct parameters', async function () {
682 await getVideo(server.url, videoId)
683 })
0e1dc3e7
C
684 })
685
686 describe('When rating a video', function () {
687 let videoId
688
689 before(async function () {
690 const res = await getVideosList(server.url)
691 videoId = res.body.data[0].id
692 })
693
694 it('Should fail without a valid uuid', async function () {
695 const fields = {
696 rating: 'like'
697 }
698 await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields })
699 })
700
701 it('Should fail with an unknown id', async function () {
702 const fields = {
703 rating: 'like'
704 }
705 await makePutBodyRequest({
706 url: server.url,
707 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate',
708 token: server.accessToken,
709 fields,
2d53be02 710 statusCodeExpected: HttpStatusCode.NOT_FOUND_404
0e1dc3e7
C
711 })
712 })
713
714 it('Should fail with a wrong rating', async function () {
715 const fields = {
716 rating: 'likes'
717 }
718 await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields })
719 })
720
721 it('Should succeed with the correct parameters', async function () {
722 const fields = {
723 rating: 'like'
724 }
725 await makePutBodyRequest({
726 url: server.url,
727 path: path + videoId + '/rate',
728 token: server.accessToken,
729 fields,
2d53be02 730 statusCodeExpected: HttpStatusCode.NO_CONTENT_204
0e1dc3e7
C
731 })
732 })
733 })
734
735 describe('When removing a video', function () {
736 it('Should have 404 with nothing', async function () {
11ba2ab3
C
737 await makeDeleteRequest({
738 url: server.url,
739 path,
2d53be02 740 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
11ba2ab3 741 })
0e1dc3e7
C
742 })
743
744 it('Should fail without a correct uuid', async function () {
2d53be02 745 await removeVideo(server.url, server.accessToken, 'hello', HttpStatusCode.BAD_REQUEST_400)
0e1dc3e7
C
746 })
747
748 it('Should fail with a video which does not exist', async function () {
2d53be02 749 await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', HttpStatusCode.NOT_FOUND_404)
0e1dc3e7
C
750 })
751
6221f311 752 it('Should fail with a video of another user without the appropriate right', async function () {
2d53be02 753 await removeVideo(server.url, userAccessToken, videoId, HttpStatusCode.FORBIDDEN_403)
6221f311 754 })
0e1dc3e7 755
9a27cdc2 756 it('Should fail with a video of another server')
0e1dc3e7 757
6221f311
C
758 it('Should succeed with the correct parameters', async function () {
759 await removeVideo(server.url, server.accessToken, videoId)
760 })
0e1dc3e7
C
761 })
762
7c3b7976
C
763 after(async function () {
764 await cleanupTests([ server ])
0e1dc3e7
C
765 })
766})