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