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