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