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