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