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