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