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