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