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