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