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