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