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