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