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