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