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