]>
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 C |
9 | createUser, flushTests, getMyUserInformation, getVideo, getVideosList, immutableAssign, killallServers, makeDeleteRequest, |
10 | makeGetRequest, makePostUploadRequest, makePutBodyRequest, removeVideo, runServer, ServerInfo, setAccessTokensToServers, userLogin | |
0e1dc3e7 | 11 | } from '../../utils' |
11ba2ab3 C |
12 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params' |
13 | ||
14 | const expect = chai.expect | |
0e1dc3e7 C |
15 | |
16 | describe('Test videos API validator', function () { | |
17 | const path = '/api/v1/videos/' | |
18 | let server: ServerInfo | |
5f04dd2f | 19 | let channelId: number |
0e1dc3e7 C |
20 | |
21 | // --------------------------------------------------------------- | |
22 | ||
23 | before(async function () { | |
24 | this.timeout(20000) | |
25 | ||
26 | await flushTests() | |
27 | ||
28 | server = await runServer(1) | |
29 | ||
30 | await setAccessTokensToServers([ server ]) | |
5f04dd2f C |
31 | |
32 | const res = await getMyUserInformation(server.url, server.accessToken) | |
33 | channelId = res.body.videoChannels[0].id | |
0e1dc3e7 C |
34 | }) |
35 | ||
36 | describe('When listing a video', function () { | |
37 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 38 | await checkBadStartPagination(server.url, path) |
0e1dc3e7 C |
39 | }) |
40 | ||
41 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 42 | await checkBadCountPagination(server.url, path) |
0e1dc3e7 C |
43 | }) |
44 | ||
45 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 46 | await checkBadSortPagination(server.url, path) |
0e1dc3e7 C |
47 | }) |
48 | }) | |
49 | ||
50 | describe('When searching a video', function () { | |
11ba2ab3 | 51 | |
0e1dc3e7 | 52 | it('Should fail with nothing', async function () { |
11ba2ab3 C |
53 | await makeGetRequest({ |
54 | url: server.url, | |
55 | path: join(path, 'search'), | |
56 | statusCodeExpected: 400 | |
57 | }) | |
0e1dc3e7 C |
58 | }) |
59 | ||
60 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 61 | await checkBadStartPagination(server.url, join(path, 'search', 'test')) |
0e1dc3e7 C |
62 | }) |
63 | ||
64 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 65 | await checkBadCountPagination(server.url, join(path, 'search', 'test')) |
0e1dc3e7 C |
66 | }) |
67 | ||
68 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 69 | await checkBadSortPagination(server.url, join(path, 'search', 'test')) |
0e1dc3e7 C |
70 | }) |
71 | }) | |
72 | ||
11474c3c C |
73 | describe('When listing my videos', function () { |
74 | const path = '/api/v1/users/me/videos' | |
75 | ||
76 | it('Should fail with a bad start pagination', async function () { | |
11ba2ab3 | 77 | await checkBadStartPagination(server.url, path, server.accessToken) |
11474c3c C |
78 | }) |
79 | ||
80 | it('Should fail with a bad count pagination', async function () { | |
11ba2ab3 | 81 | await checkBadCountPagination(server.url, path, server.accessToken) |
11474c3c C |
82 | }) |
83 | ||
84 | it('Should fail with an incorrect sort', async function () { | |
11ba2ab3 | 85 | await checkBadSortPagination(server.url, path, server.accessToken) |
11474c3c C |
86 | }) |
87 | }) | |
88 | ||
0e1dc3e7 | 89 | describe('When adding a video', function () { |
11ba2ab3 C |
90 | let baseCorrectParams |
91 | const baseCorrectAttaches = { | |
92 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short.webm') | |
93 | } | |
94 | ||
95 | before(function () { | |
96 | // Put in before to have channelId | |
97 | baseCorrectParams = { | |
98 | name: 'my super name', | |
99 | category: 5, | |
100 | licence: 1, | |
101 | language: 6, | |
102 | nsfw: false, | |
103 | description: 'my super description', | |
104 | tags: [ 'tag1', 'tag2' ], | |
105 | privacy: VideoPrivacy.PUBLIC, | |
106 | channelId | |
107 | } | |
108 | }) | |
109 | ||
0e1dc3e7 C |
110 | it('Should fail with nothing', async function () { |
111 | const fields = {} | |
112 | const attaches = {} | |
e95561cd | 113 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
114 | }) |
115 | ||
116 | it('Should fail without name', async function () { | |
11ba2ab3 C |
117 | const fields = omit(baseCorrectParams, 'name') |
118 | const attaches = baseCorrectAttaches | |
11474c3c | 119 | |
e95561cd | 120 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
121 | }) |
122 | ||
123 | it('Should fail with a long name', async function () { | |
11ba2ab3 C |
124 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) |
125 | const attaches = baseCorrectAttaches | |
11474c3c | 126 | |
e95561cd | 127 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
128 | }) |
129 | ||
0e1dc3e7 | 130 | it('Should fail with a bad category', async function () { |
11ba2ab3 C |
131 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) |
132 | const attaches = baseCorrectAttaches | |
11474c3c | 133 | |
e95561cd | 134 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
135 | }) |
136 | ||
0e1dc3e7 | 137 | it('Should fail with a bad licence', async function () { |
11ba2ab3 C |
138 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) |
139 | const attaches = baseCorrectAttaches | |
11474c3c | 140 | |
e95561cd | 141 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
142 | }) |
143 | ||
144 | it('Should fail with a bad language', async function () { | |
11ba2ab3 C |
145 | const fields = immutableAssign(baseCorrectParams, { language: 125 }) |
146 | const attaches = baseCorrectAttaches | |
11474c3c | 147 | |
e95561cd | 148 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
149 | }) |
150 | ||
151 | it('Should fail without nsfw attribute', async function () { | |
11ba2ab3 C |
152 | const fields = omit(baseCorrectParams, 'nsfw') |
153 | const attaches = baseCorrectAttaches | |
11474c3c | 154 | |
e95561cd | 155 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
156 | }) |
157 | ||
5f04dd2f | 158 | it('Should fail with a bad nsfw attribute', async function () { |
11ba2ab3 C |
159 | const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) |
160 | const attaches = baseCorrectAttaches | |
11474c3c | 161 | |
e95561cd | 162 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
163 | }) |
164 | ||
0e1dc3e7 | 165 | it('Should fail with a long description', async function () { |
11ba2ab3 C |
166 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) |
167 | const attaches = baseCorrectAttaches | |
11474c3c | 168 | |
5f04dd2f C |
169 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
170 | }) | |
171 | ||
172 | it('Should fail without a channel', async function () { | |
11ba2ab3 C |
173 | const fields = omit(baseCorrectParams, 'channelId') |
174 | const attaches = baseCorrectAttaches | |
11474c3c | 175 | |
e95561cd | 176 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
177 | }) |
178 | ||
5f04dd2f | 179 | it('Should fail with a bad channel', async function () { |
11ba2ab3 C |
180 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) |
181 | const attaches = baseCorrectAttaches | |
11474c3c | 182 | |
5f04dd2f C |
183 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
184 | }) | |
185 | ||
186 | it('Should fail with another user channel', async function () { | |
187 | const user = { | |
188 | username: 'fake', | |
189 | password: 'fake_password' | |
190 | } | |
191 | await createUser(server.url, server.accessToken, user.username, user.password) | |
192 | ||
eec63bbc | 193 | const accessTokenUser = await userLogin(server, user) |
5f04dd2f | 194 | const res = await getMyUserInformation(server.url, accessTokenUser) |
11474c3c C |
195 | const customChannelId = res.body.videoChannels[0].id |
196 | ||
11ba2ab3 C |
197 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) |
198 | const attaches = baseCorrectAttaches | |
11474c3c | 199 | |
5f04dd2f C |
200 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
201 | }) | |
202 | ||
0e1dc3e7 | 203 | it('Should fail with too many tags', async function () { |
11ba2ab3 C |
204 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) |
205 | const attaches = baseCorrectAttaches | |
11474c3c | 206 | |
e95561cd | 207 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
208 | }) |
209 | ||
210 | it('Should fail with a tag length too low', async function () { | |
11ba2ab3 C |
211 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) |
212 | const attaches = baseCorrectAttaches | |
11474c3c | 213 | |
e95561cd | 214 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
215 | }) |
216 | ||
217 | it('Should fail with a tag length too big', async function () { | |
11ba2ab3 C |
218 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) |
219 | const attaches = baseCorrectAttaches | |
11474c3c | 220 | |
e95561cd | 221 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
222 | }) |
223 | ||
224 | it('Should fail without an input file', async function () { | |
11ba2ab3 | 225 | const fields = baseCorrectParams |
0e1dc3e7 | 226 | const attaches = {} |
e95561cd | 227 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
228 | }) |
229 | ||
230 | it('Should fail without an incorrect input file', async function () { | |
11ba2ab3 | 231 | const fields = baseCorrectParams |
0e1dc3e7 C |
232 | const attaches = { |
233 | 'videofile': join(__dirname, '..', 'fixtures', 'video_short_fake.webm') | |
234 | } | |
e95561cd | 235 | await makePostUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
236 | }) |
237 | ||
0e1dc3e7 C |
238 | it('Should succeed with the correct parameters', async function () { |
239 | this.timeout(10000) | |
240 | ||
11ba2ab3 C |
241 | const fields = baseCorrectParams |
242 | ||
243 | { | |
244 | const attaches = baseCorrectAttaches | |
245 | await makePostUploadRequest({ | |
246 | url: server.url, | |
247 | path: path + '/upload', | |
248 | token: server.accessToken, | |
249 | fields, | |
250 | attaches, | |
251 | statusCodeExpected: 200 | |
252 | }) | |
253 | } | |
0e1dc3e7 | 254 | |
11ba2ab3 C |
255 | { |
256 | const attaches = immutableAssign(baseCorrectAttaches, { | |
257 | videofile: join(__dirname, '..', 'fixtures', 'video_short.mp4') | |
258 | }) | |
259 | ||
260 | await makePostUploadRequest({ | |
261 | url: server.url, | |
262 | path: path + '/upload', | |
263 | token: server.accessToken, | |
264 | fields, | |
265 | attaches, | |
266 | statusCodeExpected: 200 | |
267 | }) | |
268 | } | |
0e1dc3e7 | 269 | |
11ba2ab3 C |
270 | { |
271 | const attaches = immutableAssign(baseCorrectAttaches, { | |
272 | videofile: join(__dirname, '..', 'fixtures', 'video_short.ogv') | |
273 | }) | |
274 | ||
275 | await makePostUploadRequest({ | |
276 | url: server.url, | |
277 | path: path + '/upload', | |
278 | token: server.accessToken, | |
279 | fields, | |
280 | attaches, | |
281 | statusCodeExpected: 200 | |
282 | }) | |
283 | } | |
0e1dc3e7 C |
284 | }) |
285 | }) | |
286 | ||
287 | describe('When updating a video', function () { | |
11ba2ab3 C |
288 | const baseCorrectParams = { |
289 | name: 'my super name', | |
290 | category: 5, | |
291 | licence: 2, | |
292 | language: 6, | |
293 | nsfw: false, | |
294 | description: 'my super description', | |
295 | privacy: VideoPrivacy.PUBLIC, | |
296 | tags: [ 'tag1', 'tag2' ] | |
297 | } | |
0e1dc3e7 C |
298 | let videoId |
299 | ||
300 | before(async function () { | |
301 | const res = await getVideosList(server.url) | |
302 | videoId = res.body.data[0].id | |
303 | }) | |
304 | ||
305 | it('Should fail with nothing', async function () { | |
306 | const fields = {} | |
307 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
308 | }) | |
309 | ||
310 | it('Should fail without a valid uuid', async function () { | |
11ba2ab3 | 311 | const fields = baseCorrectParams |
0e1dc3e7 C |
312 | await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) |
313 | }) | |
314 | ||
315 | it('Should fail with an unknown id', async function () { | |
11ba2ab3 | 316 | const fields = baseCorrectParams |
11474c3c | 317 | |
0e1dc3e7 C |
318 | await makePutBodyRequest({ |
319 | url: server.url, | |
320 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', | |
321 | token: server.accessToken, | |
322 | fields, | |
323 | statusCodeExpected: 404 | |
324 | }) | |
325 | }) | |
326 | ||
327 | it('Should fail with a long name', async function () { | |
11ba2ab3 | 328 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) |
11474c3c | 329 | |
0e1dc3e7 C |
330 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
331 | }) | |
332 | ||
333 | it('Should fail with a bad category', async function () { | |
11ba2ab3 | 334 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) |
11474c3c | 335 | |
0e1dc3e7 C |
336 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
337 | }) | |
338 | ||
339 | it('Should fail with a bad licence', async function () { | |
11ba2ab3 | 340 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) |
11474c3c | 341 | |
0e1dc3e7 C |
342 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
343 | }) | |
344 | ||
345 | it('Should fail with a bad language', async function () { | |
11ba2ab3 | 346 | const fields = immutableAssign(baseCorrectParams, { language: 125 }) |
11474c3c | 347 | |
0e1dc3e7 C |
348 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
349 | }) | |
350 | ||
351 | it('Should fail with a bad nsfw attribute', async function () { | |
11ba2ab3 | 352 | const fields = immutableAssign(baseCorrectParams, { nsfw: 2 }) |
11474c3c | 353 | |
0e1dc3e7 C |
354 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
355 | }) | |
356 | ||
357 | it('Should fail with a long description', async function () { | |
11ba2ab3 | 358 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(1500) }) |
11474c3c | 359 | |
0e1dc3e7 C |
360 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
361 | }) | |
362 | ||
363 | it('Should fail with too many tags', async function () { | |
11ba2ab3 | 364 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) |
11474c3c | 365 | |
0e1dc3e7 C |
366 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
367 | }) | |
368 | ||
369 | it('Should fail with a tag length too low', async function () { | |
11ba2ab3 | 370 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) |
11474c3c | 371 | |
0e1dc3e7 C |
372 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
373 | }) | |
374 | ||
375 | it('Should fail with a tag length too big', async function () { | |
11ba2ab3 | 376 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) |
11474c3c | 377 | |
0e1dc3e7 C |
378 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
379 | }) | |
380 | ||
381 | it('Should fail with a video of another user') | |
382 | ||
9a27cdc2 | 383 | it('Should fail with a video of another server') |
11474c3c C |
384 | |
385 | it('Should succeed with the correct parameters', async function () { | |
11ba2ab3 | 386 | const fields = baseCorrectParams |
11474c3c C |
387 | |
388 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
389 | }) | |
0e1dc3e7 C |
390 | }) |
391 | ||
392 | describe('When getting a video', function () { | |
393 | it('Should return the list of the videos with nothing', async function () { | |
11ba2ab3 C |
394 | const res = await makeGetRequest({ |
395 | url: server.url, | |
396 | path, | |
397 | statusCodeExpected: 200 | |
398 | }) | |
0e1dc3e7 C |
399 | |
400 | expect(res.body.data).to.be.an('array') | |
401 | expect(res.body.data.length).to.equal(3) | |
402 | }) | |
403 | ||
404 | it('Should fail without a correct uuid', async function () { | |
11ba2ab3 | 405 | await getVideo(server.url, 'coucou', 400) |
0e1dc3e7 C |
406 | }) |
407 | ||
408 | it('Should return 404 with an incorrect video', async function () { | |
11ba2ab3 | 409 | await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
410 | }) |
411 | ||
412 | it('Should succeed with the correct parameters') | |
413 | }) | |
414 | ||
415 | describe('When rating a video', function () { | |
416 | let videoId | |
417 | ||
418 | before(async function () { | |
419 | const res = await getVideosList(server.url) | |
420 | videoId = res.body.data[0].id | |
421 | }) | |
422 | ||
423 | it('Should fail without a valid uuid', async function () { | |
424 | const fields = { | |
425 | rating: 'like' | |
426 | } | |
427 | await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields }) | |
428 | }) | |
429 | ||
430 | it('Should fail with an unknown id', async function () { | |
431 | const fields = { | |
432 | rating: 'like' | |
433 | } | |
434 | await makePutBodyRequest({ | |
435 | url: server.url, | |
436 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', | |
437 | token: server.accessToken, | |
438 | fields, | |
439 | statusCodeExpected: 404 | |
440 | }) | |
441 | }) | |
442 | ||
443 | it('Should fail with a wrong rating', async function () { | |
444 | const fields = { | |
445 | rating: 'likes' | |
446 | } | |
447 | await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields }) | |
448 | }) | |
449 | ||
450 | it('Should succeed with the correct parameters', async function () { | |
451 | const fields = { | |
452 | rating: 'like' | |
453 | } | |
454 | await makePutBodyRequest({ | |
455 | url: server.url, | |
456 | path: path + videoId + '/rate', | |
457 | token: server.accessToken, | |
458 | fields, | |
459 | statusCodeExpected: 204 | |
460 | }) | |
461 | }) | |
462 | }) | |
463 | ||
464 | describe('When removing a video', function () { | |
465 | it('Should have 404 with nothing', async function () { | |
11ba2ab3 C |
466 | await makeDeleteRequest({ |
467 | url: server.url, | |
468 | path, | |
469 | statusCodeExpected: 400 | |
470 | }) | |
0e1dc3e7 C |
471 | }) |
472 | ||
473 | it('Should fail without a correct uuid', async function () { | |
11ba2ab3 | 474 | await removeVideo(server.url, server.accessToken, 'hello', 400) |
0e1dc3e7 C |
475 | }) |
476 | ||
477 | it('Should fail with a video which does not exist', async function () { | |
11ba2ab3 | 478 | await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
479 | }) |
480 | ||
481 | it('Should fail with a video of another user') | |
482 | ||
9a27cdc2 | 483 | it('Should fail with a video of another server') |
0e1dc3e7 C |
484 | |
485 | it('Should succeed with the correct parameters') | |
486 | }) | |
487 | ||
488 | after(async function () { | |
489 | killallServers([ server ]) | |
490 | ||
491 | // Keep the logs if the test failed | |
492 | if (this['ok']) { | |
493 | await flushTests() | |
494 | } | |
495 | }) | |
496 | }) |