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