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