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