]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/videos.ts
Move utils to /shared
[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
9639bd17 11} from '../../../../shared/utils'
12import {
13 checkBadCountPagination,
14 checkBadSortPagination,
15 checkBadStartPagination
16} from '../../../../shared/utils/requests/check-api-params'
17import { getAccountsList } from '../../../../shared/utils/users/accounts'
11ba2ab3
C
18
19const expect = chai.expect
0e1dc3e7
C
20
21describe('Test videos API validator', function () {
22 const path = '/api/v1/videos/'
23 let server: ServerInfo
6221f311 24 let userAccessToken = ''
ad9e39fb 25 let accountName: string
5f04dd2f 26 let channelId: number
f6eebcb3 27 let channelName: string
6221f311 28 let videoId
0e1dc3e7
C
29
30 // ---------------------------------------------------------------
31
32 before(async function () {
e212f887 33 this.timeout(30000)
0e1dc3e7
C
34
35 await flushTests()
36
37 server = await runServer(1)
38
39 await setAccessTokensToServers([ server ])
5f04dd2f 40
6221f311
C
41 const username = 'user1'
42 const password = 'my super password'
43 await createUser(server.url, server.accessToken, username, password)
44 userAccessToken = await userLogin(server, { username, password })
45
6b738c7a
C
46 {
47 const res = await getMyUserInformation(server.url, server.accessToken)
48 channelId = res.body.videoChannels[ 0 ].id
f6eebcb3 49 channelName = res.body.videoChannels[ 0 ].name
ad9e39fb 50 accountName = res.body.account.name + '@' + res.body.account.host
6b738c7a 51 }
0e1dc3e7
C
52 })
53
54 describe('When listing a video', function () {
55 it('Should fail with a bad start pagination', async function () {
11ba2ab3 56 await checkBadStartPagination(server.url, path)
0e1dc3e7
C
57 })
58
59 it('Should fail with a bad count pagination', async function () {
11ba2ab3 60 await checkBadCountPagination(server.url, path)
0e1dc3e7
C
61 })
62
63 it('Should fail with an incorrect sort', async function () {
11ba2ab3 64 await checkBadSortPagination(server.url, path)
0e1dc3e7 65 })
6b738c7a
C
66
67 it('Should success with the correct parameters', async function () {
68 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
69 })
0e1dc3e7
C
70 })
71
72 describe('When searching a video', function () {
11ba2ab3 73
0e1dc3e7 74 it('Should fail with nothing', async function () {
11ba2ab3
C
75 await makeGetRequest({
76 url: server.url,
77 path: join(path, 'search'),
78 statusCodeExpected: 400
79 })
0e1dc3e7
C
80 })
81
82 it('Should fail with a bad start pagination', async function () {
11ba2ab3 83 await checkBadStartPagination(server.url, join(path, 'search', 'test'))
0e1dc3e7
C
84 })
85
86 it('Should fail with a bad count pagination', async function () {
11ba2ab3 87 await checkBadCountPagination(server.url, join(path, 'search', 'test'))
0e1dc3e7
C
88 })
89
90 it('Should fail with an incorrect sort', async function () {
11ba2ab3 91 await checkBadSortPagination(server.url, join(path, 'search', 'test'))
0e1dc3e7 92 })
6b738c7a
C
93
94 it('Should success with the correct parameters', async function () {
95 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
96 })
0e1dc3e7
C
97 })
98
11474c3c
C
99 describe('When listing my videos', function () {
100 const path = '/api/v1/users/me/videos'
101
102 it('Should fail with a bad start pagination', async function () {
11ba2ab3 103 await checkBadStartPagination(server.url, path, server.accessToken)
11474c3c
C
104 })
105
106 it('Should fail with a bad count pagination', async function () {
11ba2ab3 107 await checkBadCountPagination(server.url, path, server.accessToken)
11474c3c
C
108 })
109
110 it('Should fail with an incorrect sort', async function () {
11ba2ab3 111 await checkBadSortPagination(server.url, path, server.accessToken)
11474c3c 112 })
6b738c7a
C
113
114 it('Should success with the correct parameters', async function () {
115 await makeGetRequest({ url: server.url, token: server.accessToken, path, statusCodeExpected: 200 })
116 })
117 })
118
119 describe('When listing account videos', function () {
120 let path: string
121
122 before(async function () {
ad9e39fb 123 path = '/api/v1/accounts/' + accountName + '/videos'
6b738c7a
C
124 })
125
126 it('Should fail with a bad start pagination', async function () {
127 await checkBadStartPagination(server.url, path, server.accessToken)
128 })
129
130 it('Should fail with a bad count pagination', async function () {
131 await checkBadCountPagination(server.url, path, server.accessToken)
132 })
133
134 it('Should fail with an incorrect sort', async function () {
135 await checkBadSortPagination(server.url, path, server.accessToken)
136 })
137
138 it('Should success with the correct parameters', async function () {
139 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
140 })
141 })
142
143 describe('When listing video channel videos', function () {
144 let path: string
145
146 before(async function () {
f6eebcb3 147 path = '/api/v1/video-channels/' + channelName + '/videos'
6b738c7a
C
148 })
149
150 it('Should fail with a bad start pagination', async function () {
151 await checkBadStartPagination(server.url, path, server.accessToken)
152 })
153
154 it('Should fail with a bad count pagination', async function () {
155 await checkBadCountPagination(server.url, path, server.accessToken)
156 })
157
158 it('Should fail with an incorrect sort', async function () {
159 await checkBadSortPagination(server.url, path, server.accessToken)
160 })
161
162 it('Should success with the correct parameters', async function () {
163 await makeGetRequest({ url: server.url, path, statusCodeExpected: 200 })
164 })
11474c3c
C
165 })
166
0e1dc3e7 167 describe('When adding a video', function () {
11ba2ab3
C
168 let baseCorrectParams
169 const baseCorrectAttaches = {
99d10301 170 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm')
11ba2ab3
C
171 }
172
173 before(function () {
174 // Put in before to have channelId
175 baseCorrectParams = {
176 name: 'my super name',
177 category: 5,
178 licence: 1,
9d3ef9fe 179 language: 'pt',
11ba2ab3 180 nsfw: false,
47564bbe 181 commentsEnabled: true,
2186386c 182 waitTranscoding: true,
11ba2ab3 183 description: 'my super description',
2422c46b 184 support: 'my super support text',
11ba2ab3
C
185 tags: [ 'tag1', 'tag2' ],
186 privacy: VideoPrivacy.PUBLIC,
6b738c7a 187 channelId: channelId
11ba2ab3
C
188 }
189 })
190
0e1dc3e7
C
191 it('Should fail with nothing', async function () {
192 const fields = {}
193 const attaches = {}
ac81d1a0 194 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
195 })
196
197 it('Should fail without name', async function () {
11ba2ab3
C
198 const fields = omit(baseCorrectParams, 'name')
199 const attaches = baseCorrectAttaches
11474c3c 200
ac81d1a0 201 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
202 })
203
204 it('Should fail with a long name', async function () {
11ba2ab3
C
205 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
206 const attaches = baseCorrectAttaches
11474c3c 207
ac81d1a0 208 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
209 })
210
0e1dc3e7 211 it('Should fail with a bad category', async function () {
11ba2ab3
C
212 const fields = immutableAssign(baseCorrectParams, { category: 125 })
213 const attaches = baseCorrectAttaches
11474c3c 214
ac81d1a0 215 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
216 })
217
0e1dc3e7 218 it('Should fail with a bad licence', async function () {
11ba2ab3
C
219 const fields = immutableAssign(baseCorrectParams, { licence: 125 })
220 const attaches = baseCorrectAttaches
11474c3c 221
ac81d1a0 222 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
223 })
224
225 it('Should fail with a bad language', async function () {
9d3ef9fe 226 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
11ba2ab3 227 const attaches = baseCorrectAttaches
11474c3c 228
ac81d1a0 229 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
230 })
231
0e1dc3e7 232 it('Should fail with a long description', async function () {
2422c46b
C
233 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
234 const attaches = baseCorrectAttaches
235
236 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
237 })
238
239 it('Should fail with a long support text', async function () {
d23e6a1c 240 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
11ba2ab3 241 const attaches = baseCorrectAttaches
11474c3c 242
ac81d1a0 243 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
5f04dd2f
C
244 })
245
246 it('Should fail without a channel', async function () {
11ba2ab3
C
247 const fields = omit(baseCorrectParams, 'channelId')
248 const attaches = baseCorrectAttaches
11474c3c 249
ac81d1a0 250 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
251 })
252
5f04dd2f 253 it('Should fail with a bad channel', async function () {
11ba2ab3
C
254 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
255 const attaches = baseCorrectAttaches
11474c3c 256
ac81d1a0 257 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
5f04dd2f
C
258 })
259
260 it('Should fail with another user channel', async function () {
261 const user = {
262 username: 'fake',
263 password: 'fake_password'
264 }
265 await createUser(server.url, server.accessToken, user.username, user.password)
266
eec63bbc 267 const accessTokenUser = await userLogin(server, user)
5f04dd2f 268 const res = await getMyUserInformation(server.url, accessTokenUser)
11474c3c
C
269 const customChannelId = res.body.videoChannels[0].id
270
11ba2ab3
C
271 const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId })
272 const attaches = baseCorrectAttaches
11474c3c 273
6200d8d9 274 await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches })
5f04dd2f
C
275 })
276
0e1dc3e7 277 it('Should fail with too many tags', async function () {
11ba2ab3
C
278 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
279 const attaches = baseCorrectAttaches
11474c3c 280
ac81d1a0 281 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
282 })
283
284 it('Should fail with a tag length too low', async function () {
11ba2ab3
C
285 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
286 const attaches = baseCorrectAttaches
11474c3c 287
ac81d1a0 288 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
289 })
290
291 it('Should fail with a tag length too big', async function () {
11ba2ab3
C
292 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
293 const attaches = baseCorrectAttaches
11474c3c 294
ac81d1a0 295 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
296 })
297
bbe0f064
C
298 it('Should fail with a bad schedule update (miss updateAt)', async function () {
299 const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC })
300 const attaches = baseCorrectAttaches
301
302 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
303 })
304
305 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
306 const fields = immutableAssign(baseCorrectParams, {
307 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC,
308 'scheduleUpdate[updateAt]': 'toto'
309 })
310 const attaches = baseCorrectAttaches
311
312 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
313 })
314
0e1dc3e7 315 it('Should fail without an input file', async function () {
11ba2ab3 316 const fields = baseCorrectParams
0e1dc3e7 317 const attaches = {}
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 incorrect input file', async function () {
11ba2ab3 322 const fields = baseCorrectParams
0e1dc3e7 323 const attaches = {
99d10301 324 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm')
0e1dc3e7 325 }
ac81d1a0
C
326 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
327 })
328
329 it('Should fail with an incorrect thumbnail file', async function () {
330 const fields = baseCorrectParams
331 const attaches = {
99d10301 332 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
0c237b19 333 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
ac81d1a0
C
334 }
335
336 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
337 })
338
339 it('Should fail with a big thumbnail file', async function () {
340 const fields = baseCorrectParams
341 const attaches = {
99d10301 342 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
0c237b19 343 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
ac81d1a0
C
344 }
345
346 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
347 })
348
349 it('Should fail with an incorrect preview file', async function () {
350 const fields = baseCorrectParams
351 const attaches = {
99d10301 352 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'),
0c237b19 353 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
ac81d1a0
C
354 }
355
356 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
357 })
358
359 it('Should fail with a big preview file', async function () {
360 const fields = baseCorrectParams
361 const attaches = {
99d10301 362 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'),
0c237b19 363 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
ac81d1a0
C
364 }
365
366 await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches })
0e1dc3e7
C
367 })
368
0e1dc3e7
C
369 it('Should succeed with the correct parameters', async function () {
370 this.timeout(10000)
371
11ba2ab3
C
372 const fields = baseCorrectParams
373
374 {
375 const attaches = baseCorrectAttaches
ac81d1a0 376 await makeUploadRequest({
11ba2ab3
C
377 url: server.url,
378 path: path + '/upload',
379 token: server.accessToken,
380 fields,
381 attaches,
382 statusCodeExpected: 200
383 })
384 }
0e1dc3e7 385
11ba2ab3
C
386 {
387 const attaches = immutableAssign(baseCorrectAttaches, {
99d10301 388 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
11ba2ab3
C
389 })
390
ac81d1a0 391 await makeUploadRequest({
11ba2ab3
C
392 url: server.url,
393 path: path + '/upload',
394 token: server.accessToken,
395 fields,
396 attaches,
397 statusCodeExpected: 200
398 })
399 }
0e1dc3e7 400
11ba2ab3
C
401 {
402 const attaches = immutableAssign(baseCorrectAttaches, {
99d10301 403 videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv')
11ba2ab3
C
404 })
405
ac81d1a0 406 await makeUploadRequest({
11ba2ab3
C
407 url: server.url,
408 path: path + '/upload',
409 token: server.accessToken,
410 fields,
411 attaches,
412 statusCodeExpected: 200
413 })
414 }
0e1dc3e7
C
415 })
416 })
417
418 describe('When updating a video', function () {
11ba2ab3
C
419 const baseCorrectParams = {
420 name: 'my super name',
421 category: 5,
422 licence: 2,
9d3ef9fe 423 language: 'pt',
11ba2ab3 424 nsfw: false,
47564bbe 425 commentsEnabled: false,
11ba2ab3
C
426 description: 'my super description',
427 privacy: VideoPrivacy.PUBLIC,
428 tags: [ 'tag1', 'tag2' ]
429 }
0e1dc3e7
C
430
431 before(async function () {
432 const res = await getVideosList(server.url)
6221f311 433 videoId = res.body.data[0].uuid
0e1dc3e7
C
434 })
435
436 it('Should fail with nothing', async function () {
437 const fields = {}
438 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
439 })
440
441 it('Should fail without a valid uuid', async function () {
11ba2ab3 442 const fields = baseCorrectParams
0e1dc3e7
C
443 await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields })
444 })
445
446 it('Should fail with an unknown id', async function () {
11ba2ab3 447 const fields = baseCorrectParams
11474c3c 448
0e1dc3e7
C
449 await makePutBodyRequest({
450 url: server.url,
451 path: path + '4da6fde3-88f7-4d16-b119-108df5630b06',
452 token: server.accessToken,
453 fields,
454 statusCodeExpected: 404
455 })
456 })
457
458 it('Should fail with a long name', async function () {
11ba2ab3 459 const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) })
11474c3c 460
0e1dc3e7
C
461 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
462 })
463
464 it('Should fail with a bad category', async function () {
11ba2ab3 465 const fields = immutableAssign(baseCorrectParams, { category: 125 })
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 licence', async function () {
11ba2ab3 471 const fields = immutableAssign(baseCorrectParams, { licence: 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 language', async function () {
9d3ef9fe 477 const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) })
11474c3c 478
0e1dc3e7
C
479 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
480 })
481
0e1dc3e7 482 it('Should fail with a long description', async function () {
2422c46b
C
483 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) })
484
485 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
486 })
487
488 it('Should fail with a long support text', async function () {
d23e6a1c 489 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
11474c3c 490
0e1dc3e7
C
491 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
492 })
493
7fb39378
C
494 it('Should fail with a bad channel', async function () {
495 const fields = immutableAssign(baseCorrectParams, { channelId: 545454 })
496
497 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
498 })
499
0e1dc3e7 500 it('Should fail with too many tags', async function () {
11ba2ab3 501 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] })
11474c3c 502
0e1dc3e7
C
503 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
504 })
505
506 it('Should fail with a tag length too low', async function () {
11ba2ab3 507 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] })
11474c3c 508
0e1dc3e7
C
509 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
510 })
511
512 it('Should fail with a tag length too big', async function () {
11ba2ab3 513 const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] })
11474c3c 514
0e1dc3e7
C
515 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
516 })
517
bbe0f064
C
518 it('Should fail with a bad schedule update (miss updateAt)', async function () {
519 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } })
520
521 await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields })
522 })
523
524 it('Should fail with a bad schedule update (wrong updateAt)', async function () {
525 const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } })
526
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 = {
99d10301 533 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
ac81d1a0
C
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 = {
99d10301 549 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
ac81d1a0
C
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 = {
99d10301 565 'previewfile': join(__dirname, '..', '..', '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 preview file', async function () {
579 const fields = baseCorrectParams
580 const attaches = {
99d10301 581 'previewfile': join(__dirname, '..', '..', '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
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})