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