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