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