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