]>
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 = '' |
ad9e39fb | 21 | let accountName: 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 | |
ad9e39fb | 46 | accountName = res.body.account.name + '@' + res.body.account.host |
6b738c7a | 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 () { | |
ad9e39fb | 119 | path = '/api/v1/accounts/' + accountName + '/videos' |
6b738c7a C |
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 = { | |
99d10301 | 166 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.webm') |
11ba2ab3 C |
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, |
2186386c | 178 | waitTranscoding: true, |
11ba2ab3 | 179 | description: 'my super description', |
2422c46b | 180 | support: 'my super support text', |
11ba2ab3 C |
181 | tags: [ 'tag1', 'tag2' ], |
182 | privacy: VideoPrivacy.PUBLIC, | |
6b738c7a | 183 | channelId: channelId |
11ba2ab3 C |
184 | } |
185 | }) | |
186 | ||
0e1dc3e7 C |
187 | it('Should fail with nothing', async function () { |
188 | const fields = {} | |
189 | const attaches = {} | |
ac81d1a0 | 190 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
191 | }) |
192 | ||
193 | it('Should fail without name', async function () { | |
11ba2ab3 C |
194 | const fields = omit(baseCorrectParams, 'name') |
195 | const attaches = baseCorrectAttaches | |
11474c3c | 196 | |
ac81d1a0 | 197 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
198 | }) |
199 | ||
200 | it('Should fail with a long name', async function () { | |
11ba2ab3 C |
201 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) |
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 | ||
0e1dc3e7 | 207 | it('Should fail with a bad category', async function () { |
11ba2ab3 C |
208 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) |
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 licence', async function () { |
11ba2ab3 C |
215 | const fields = immutableAssign(baseCorrectParams, { licence: 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 | ||
221 | it('Should fail with a bad language', async function () { | |
9d3ef9fe | 222 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) |
11ba2ab3 | 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 | ||
0e1dc3e7 | 228 | it('Should fail with a long description', async function () { |
2422c46b C |
229 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) |
230 | const attaches = baseCorrectAttaches | |
231 | ||
232 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
233 | }) | |
234 | ||
235 | it('Should fail with a long support text', async function () { | |
9419b013 | 236 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) |
11ba2ab3 | 237 | const attaches = baseCorrectAttaches |
11474c3c | 238 | |
ac81d1a0 | 239 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
5f04dd2f C |
240 | }) |
241 | ||
242 | it('Should fail without a channel', async function () { | |
11ba2ab3 C |
243 | const fields = omit(baseCorrectParams, 'channelId') |
244 | const attaches = baseCorrectAttaches | |
11474c3c | 245 | |
ac81d1a0 | 246 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
247 | }) |
248 | ||
5f04dd2f | 249 | it('Should fail with a bad channel', async function () { |
11ba2ab3 C |
250 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) |
251 | const attaches = baseCorrectAttaches | |
11474c3c | 252 | |
ac81d1a0 | 253 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
5f04dd2f C |
254 | }) |
255 | ||
256 | it('Should fail with another user channel', async function () { | |
257 | const user = { | |
258 | username: 'fake', | |
259 | password: 'fake_password' | |
260 | } | |
261 | await createUser(server.url, server.accessToken, user.username, user.password) | |
262 | ||
eec63bbc | 263 | const accessTokenUser = await userLogin(server, user) |
5f04dd2f | 264 | const res = await getMyUserInformation(server.url, accessTokenUser) |
11474c3c C |
265 | const customChannelId = res.body.videoChannels[0].id |
266 | ||
11ba2ab3 C |
267 | const fields = immutableAssign(baseCorrectParams, { channelId: customChannelId }) |
268 | const attaches = baseCorrectAttaches | |
11474c3c | 269 | |
6200d8d9 | 270 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: userAccessToken, fields, attaches }) |
5f04dd2f C |
271 | }) |
272 | ||
0e1dc3e7 | 273 | it('Should fail with too many tags', async function () { |
11ba2ab3 C |
274 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) |
275 | const attaches = baseCorrectAttaches | |
11474c3c | 276 | |
ac81d1a0 | 277 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
278 | }) |
279 | ||
280 | it('Should fail with a tag length too low', async function () { | |
11ba2ab3 C |
281 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) |
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 big', async function () { | |
11ba2ab3 C |
288 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) |
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 | ||
bbe0f064 C |
294 | it('Should fail with a bad schedule update (miss updateAt)', async function () { |
295 | const fields = immutableAssign(baseCorrectParams, { 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC }) | |
296 | const attaches = baseCorrectAttaches | |
297 | ||
298 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
299 | }) | |
300 | ||
301 | it('Should fail with a bad schedule update (wrong updateAt)', async function () { | |
302 | const fields = immutableAssign(baseCorrectParams, { | |
303 | 'scheduleUpdate[privacy]': VideoPrivacy.PUBLIC, | |
304 | 'scheduleUpdate[updateAt]': 'toto' | |
305 | }) | |
306 | const attaches = baseCorrectAttaches | |
307 | ||
308 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
309 | }) | |
310 | ||
0e1dc3e7 | 311 | it('Should fail without an input file', async function () { |
11ba2ab3 | 312 | const fields = baseCorrectParams |
0e1dc3e7 | 313 | const attaches = {} |
ac81d1a0 | 314 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
0e1dc3e7 C |
315 | }) |
316 | ||
317 | it('Should fail without an incorrect input file', async function () { | |
11ba2ab3 | 318 | const fields = baseCorrectParams |
0e1dc3e7 | 319 | const attaches = { |
99d10301 | 320 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short_fake.webm') |
0e1dc3e7 | 321 | } |
ac81d1a0 C |
322 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) |
323 | }) | |
324 | ||
325 | it('Should fail with an incorrect thumbnail file', async function () { | |
326 | const fields = baseCorrectParams | |
327 | const attaches = { | |
99d10301 | 328 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), |
0c237b19 | 329 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
ac81d1a0 C |
330 | } |
331 | ||
332 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
333 | }) | |
334 | ||
335 | it('Should fail with a big thumbnail file', async function () { | |
336 | const fields = baseCorrectParams | |
337 | const attaches = { | |
99d10301 | 338 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), |
0c237b19 | 339 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
ac81d1a0 C |
340 | } |
341 | ||
342 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
343 | }) | |
344 | ||
345 | it('Should fail with an incorrect preview file', async function () { | |
346 | const fields = baseCorrectParams | |
347 | const attaches = { | |
99d10301 | 348 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png'), |
0c237b19 | 349 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
ac81d1a0 C |
350 | } |
351 | ||
352 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
353 | }) | |
354 | ||
355 | it('Should fail with a big preview file', async function () { | |
356 | const fields = baseCorrectParams | |
357 | const attaches = { | |
99d10301 | 358 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png'), |
0c237b19 | 359 | 'videofile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
ac81d1a0 C |
360 | } |
361 | ||
362 | await makeUploadRequest({ url: server.url, path: path + '/upload', token: server.accessToken, fields, attaches }) | |
0e1dc3e7 C |
363 | }) |
364 | ||
0e1dc3e7 C |
365 | it('Should succeed with the correct parameters', async function () { |
366 | this.timeout(10000) | |
367 | ||
11ba2ab3 C |
368 | const fields = baseCorrectParams |
369 | ||
370 | { | |
371 | const attaches = baseCorrectAttaches | |
ac81d1a0 | 372 | await makeUploadRequest({ |
11ba2ab3 C |
373 | url: server.url, |
374 | path: path + '/upload', | |
375 | token: server.accessToken, | |
376 | fields, | |
377 | attaches, | |
378 | statusCodeExpected: 200 | |
379 | }) | |
380 | } | |
0e1dc3e7 | 381 | |
11ba2ab3 C |
382 | { |
383 | const attaches = immutableAssign(baseCorrectAttaches, { | |
99d10301 | 384 | videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.mp4') |
11ba2ab3 C |
385 | }) |
386 | ||
ac81d1a0 | 387 | await makeUploadRequest({ |
11ba2ab3 C |
388 | url: server.url, |
389 | path: path + '/upload', | |
390 | token: server.accessToken, | |
391 | fields, | |
392 | attaches, | |
393 | statusCodeExpected: 200 | |
394 | }) | |
395 | } | |
0e1dc3e7 | 396 | |
11ba2ab3 C |
397 | { |
398 | const attaches = immutableAssign(baseCorrectAttaches, { | |
99d10301 | 399 | videofile: join(__dirname, '..', '..', 'fixtures', 'video_short.ogv') |
11ba2ab3 C |
400 | }) |
401 | ||
ac81d1a0 | 402 | await makeUploadRequest({ |
11ba2ab3 C |
403 | url: server.url, |
404 | path: path + '/upload', | |
405 | token: server.accessToken, | |
406 | fields, | |
407 | attaches, | |
408 | statusCodeExpected: 200 | |
409 | }) | |
410 | } | |
0e1dc3e7 C |
411 | }) |
412 | }) | |
413 | ||
414 | describe('When updating a video', function () { | |
11ba2ab3 C |
415 | const baseCorrectParams = { |
416 | name: 'my super name', | |
417 | category: 5, | |
418 | licence: 2, | |
9d3ef9fe | 419 | language: 'pt', |
11ba2ab3 | 420 | nsfw: false, |
47564bbe | 421 | commentsEnabled: false, |
11ba2ab3 C |
422 | description: 'my super description', |
423 | privacy: VideoPrivacy.PUBLIC, | |
424 | tags: [ 'tag1', 'tag2' ] | |
425 | } | |
0e1dc3e7 C |
426 | |
427 | before(async function () { | |
428 | const res = await getVideosList(server.url) | |
6221f311 | 429 | videoId = res.body.data[0].uuid |
0e1dc3e7 C |
430 | }) |
431 | ||
432 | it('Should fail with nothing', async function () { | |
433 | const fields = {} | |
434 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) | |
435 | }) | |
436 | ||
437 | it('Should fail without a valid uuid', async function () { | |
11ba2ab3 | 438 | const fields = baseCorrectParams |
0e1dc3e7 C |
439 | await makePutBodyRequest({ url: server.url, path: path + 'blabla', token: server.accessToken, fields }) |
440 | }) | |
441 | ||
442 | it('Should fail with an unknown id', async function () { | |
11ba2ab3 | 443 | const fields = baseCorrectParams |
11474c3c | 444 | |
0e1dc3e7 C |
445 | await makePutBodyRequest({ |
446 | url: server.url, | |
447 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06', | |
448 | token: server.accessToken, | |
449 | fields, | |
450 | statusCodeExpected: 404 | |
451 | }) | |
452 | }) | |
453 | ||
454 | it('Should fail with a long name', async function () { | |
11ba2ab3 | 455 | const fields = immutableAssign(baseCorrectParams, { name: 'super'.repeat(65) }) |
11474c3c | 456 | |
0e1dc3e7 C |
457 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
458 | }) | |
459 | ||
460 | it('Should fail with a bad category', async function () { | |
11ba2ab3 | 461 | const fields = immutableAssign(baseCorrectParams, { category: 125 }) |
11474c3c | 462 | |
0e1dc3e7 C |
463 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
464 | }) | |
465 | ||
466 | it('Should fail with a bad licence', async function () { | |
11ba2ab3 | 467 | const fields = immutableAssign(baseCorrectParams, { licence: 125 }) |
11474c3c | 468 | |
0e1dc3e7 C |
469 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
470 | }) | |
471 | ||
472 | it('Should fail with a bad language', async function () { | |
9d3ef9fe | 473 | const fields = immutableAssign(baseCorrectParams, { language: 'a'.repeat(15) }) |
11474c3c | 474 | |
0e1dc3e7 C |
475 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
476 | }) | |
477 | ||
0e1dc3e7 | 478 | it('Should fail with a long description', async function () { |
2422c46b C |
479 | const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(2500) }) |
480 | ||
481 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
482 | }) | |
483 | ||
484 | it('Should fail with a long support text', async function () { | |
9419b013 | 485 | const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) }) |
11474c3c | 486 | |
0e1dc3e7 C |
487 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
488 | }) | |
489 | ||
7fb39378 C |
490 | it('Should fail with a bad channel', async function () { |
491 | const fields = immutableAssign(baseCorrectParams, { channelId: 545454 }) | |
492 | ||
493 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
494 | }) | |
495 | ||
0e1dc3e7 | 496 | it('Should fail with too many tags', async function () { |
11ba2ab3 | 497 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'tag2', 'tag3', 'tag4', 'tag5', 'tag6' ] }) |
11474c3c | 498 | |
0e1dc3e7 C |
499 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
500 | }) | |
501 | ||
502 | it('Should fail with a tag length too low', async function () { | |
11ba2ab3 | 503 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 't' ] }) |
11474c3c | 504 | |
0e1dc3e7 C |
505 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
506 | }) | |
507 | ||
508 | it('Should fail with a tag length too big', async function () { | |
11ba2ab3 | 509 | const fields = immutableAssign(baseCorrectParams, { tags: [ 'tag1', 'my_super_tag_too_long_long_long_long_long_long' ] }) |
11474c3c | 510 | |
0e1dc3e7 C |
511 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) |
512 | }) | |
513 | ||
bbe0f064 C |
514 | it('Should fail with a bad schedule update (miss updateAt)', async function () { |
515 | const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { privacy: VideoPrivacy.PUBLIC } }) | |
516 | ||
517 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
518 | }) | |
519 | ||
520 | it('Should fail with a bad schedule update (wrong updateAt)', async function () { | |
521 | const fields = immutableAssign(baseCorrectParams, { scheduleUpdate: { updateAt: 'toto', privacy: VideoPrivacy.PUBLIC } }) | |
522 | ||
523 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields }) | |
524 | }) | |
525 | ||
ac81d1a0 C |
526 | it('Should fail with an incorrect thumbnail file', async function () { |
527 | const fields = baseCorrectParams | |
528 | const attaches = { | |
99d10301 | 529 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
ac81d1a0 C |
530 | } |
531 | ||
532 | await makeUploadRequest({ | |
533 | url: server.url, | |
534 | method: 'PUT', | |
535 | path: path + videoId, | |
536 | token: server.accessToken, | |
537 | fields, | |
538 | attaches | |
539 | }) | |
540 | }) | |
541 | ||
542 | it('Should fail with a big thumbnail file', async function () { | |
543 | const fields = baseCorrectParams | |
544 | const attaches = { | |
99d10301 | 545 | 'thumbnailfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
ac81d1a0 C |
546 | } |
547 | ||
548 | await makeUploadRequest({ | |
549 | url: server.url, | |
550 | method: 'PUT', | |
551 | path: path + videoId, | |
552 | token: server.accessToken, | |
553 | fields, | |
554 | attaches | |
555 | }) | |
556 | }) | |
557 | ||
558 | it('Should fail with an incorrect preview file', async function () { | |
559 | const fields = baseCorrectParams | |
560 | const attaches = { | |
99d10301 | 561 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png') |
ac81d1a0 C |
562 | } |
563 | ||
564 | await makeUploadRequest({ | |
565 | url: server.url, | |
566 | method: 'PUT', | |
567 | path: path + videoId, | |
568 | token: server.accessToken, | |
569 | fields, | |
570 | attaches | |
571 | }) | |
572 | }) | |
573 | ||
574 | it('Should fail with a big preview file', async function () { | |
575 | const fields = baseCorrectParams | |
576 | const attaches = { | |
99d10301 | 577 | 'previewfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png') |
ac81d1a0 C |
578 | } |
579 | ||
580 | await makeUploadRequest({ | |
581 | url: server.url, | |
582 | method: 'PUT', | |
583 | path: path + videoId, | |
584 | token: server.accessToken, | |
585 | fields, | |
586 | attaches | |
587 | }) | |
588 | }) | |
589 | ||
6221f311 C |
590 | it('Should fail with a video of another user without the appropriate right', async function () { |
591 | const fields = baseCorrectParams | |
592 | ||
593 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: userAccessToken, fields, statusCodeExpected: 403 }) | |
594 | }) | |
0e1dc3e7 | 595 | |
9a27cdc2 | 596 | it('Should fail with a video of another server') |
11474c3c C |
597 | |
598 | it('Should succeed with the correct parameters', async function () { | |
11ba2ab3 | 599 | const fields = baseCorrectParams |
11474c3c C |
600 | |
601 | await makePutBodyRequest({ url: server.url, path: path + videoId, token: server.accessToken, fields, statusCodeExpected: 204 }) | |
602 | }) | |
0e1dc3e7 C |
603 | }) |
604 | ||
605 | describe('When getting a video', function () { | |
606 | it('Should return the list of the videos with nothing', async function () { | |
11ba2ab3 C |
607 | const res = await makeGetRequest({ |
608 | url: server.url, | |
609 | path, | |
610 | statusCodeExpected: 200 | |
611 | }) | |
0e1dc3e7 C |
612 | |
613 | expect(res.body.data).to.be.an('array') | |
614 | expect(res.body.data.length).to.equal(3) | |
615 | }) | |
616 | ||
617 | it('Should fail without a correct uuid', async function () { | |
11ba2ab3 | 618 | await getVideo(server.url, 'coucou', 400) |
0e1dc3e7 C |
619 | }) |
620 | ||
621 | it('Should return 404 with an incorrect video', async function () { | |
11ba2ab3 | 622 | await getVideo(server.url, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
623 | }) |
624 | ||
6221f311 C |
625 | it('Should succeed with the correct parameters', async function () { |
626 | await getVideo(server.url, videoId) | |
627 | }) | |
0e1dc3e7 C |
628 | }) |
629 | ||
630 | describe('When rating a video', function () { | |
631 | let videoId | |
632 | ||
633 | before(async function () { | |
634 | const res = await getVideosList(server.url) | |
635 | videoId = res.body.data[0].id | |
636 | }) | |
637 | ||
638 | it('Should fail without a valid uuid', async function () { | |
639 | const fields = { | |
640 | rating: 'like' | |
641 | } | |
642 | await makePutBodyRequest({ url: server.url, path: path + 'blabla/rate', token: server.accessToken, fields }) | |
643 | }) | |
644 | ||
645 | it('Should fail with an unknown id', async function () { | |
646 | const fields = { | |
647 | rating: 'like' | |
648 | } | |
649 | await makePutBodyRequest({ | |
650 | url: server.url, | |
651 | path: path + '4da6fde3-88f7-4d16-b119-108df5630b06/rate', | |
652 | token: server.accessToken, | |
653 | fields, | |
654 | statusCodeExpected: 404 | |
655 | }) | |
656 | }) | |
657 | ||
658 | it('Should fail with a wrong rating', async function () { | |
659 | const fields = { | |
660 | rating: 'likes' | |
661 | } | |
662 | await makePutBodyRequest({ url: server.url, path: path + videoId + '/rate', token: server.accessToken, fields }) | |
663 | }) | |
664 | ||
665 | it('Should succeed with the correct parameters', async function () { | |
666 | const fields = { | |
667 | rating: 'like' | |
668 | } | |
669 | await makePutBodyRequest({ | |
670 | url: server.url, | |
671 | path: path + videoId + '/rate', | |
672 | token: server.accessToken, | |
673 | fields, | |
674 | statusCodeExpected: 204 | |
675 | }) | |
676 | }) | |
677 | }) | |
678 | ||
679 | describe('When removing a video', function () { | |
680 | it('Should have 404 with nothing', async function () { | |
11ba2ab3 C |
681 | await makeDeleteRequest({ |
682 | url: server.url, | |
683 | path, | |
684 | statusCodeExpected: 400 | |
685 | }) | |
0e1dc3e7 C |
686 | }) |
687 | ||
688 | it('Should fail without a correct uuid', async function () { | |
11ba2ab3 | 689 | await removeVideo(server.url, server.accessToken, 'hello', 400) |
0e1dc3e7 C |
690 | }) |
691 | ||
692 | it('Should fail with a video which does not exist', async function () { | |
11ba2ab3 | 693 | await removeVideo(server.url, server.accessToken, '4da6fde3-88f7-4d16-b119-108df5630b06', 404) |
0e1dc3e7 C |
694 | }) |
695 | ||
6221f311 C |
696 | it('Should fail with a video of another user without the appropriate right', async function () { |
697 | await removeVideo(server.url, userAccessToken, videoId, 403) | |
698 | }) | |
0e1dc3e7 | 699 | |
9a27cdc2 | 700 | it('Should fail with a video of another server') |
0e1dc3e7 | 701 | |
6221f311 C |
702 | it('Should succeed with the correct parameters', async function () { |
703 | await removeVideo(server.url, server.accessToken, videoId) | |
704 | }) | |
0e1dc3e7 C |
705 | }) |
706 | ||
707 | after(async function () { | |
708 | killallServers([ server ]) | |
709 | ||
710 | // Keep the logs if the test failed | |
711 | if (this['ok']) { | |
712 | await flushTests() | |
713 | } | |
714 | }) | |
715 | }) |