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