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