]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
5f04dd2f | 2 | |
3d470a53 | 3 | import 'mocha' |
5f04dd2f | 4 | import * as chai from 'chai' |
11ba2ab3 | 5 | import { omit } from 'lodash' |
2a491182 F |
6 | import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination, FIXTURE_URLS } from '@server/tests/shared' |
7 | import { areHttpImportTestsDisabled, buildAbsoluteFixturePath } from '@shared/core-utils' | |
c55e3d72 | 8 | import { HttpStatusCode, VideoChannelUpdate } from '@shared/models' |
5f04dd2f | 9 | import { |
a5461888 | 10 | ChannelsCommand, |
7c3b7976 | 11 | cleanupTests, |
254d3579 | 12 | createSingleServer, |
48dce1c9 C |
13 | makeGetRequest, |
14 | makePostBodyRequest, | |
52d9f792 C |
15 | makePutBodyRequest, |
16 | makeUploadRequest, | |
254d3579 | 17 | PeerTubeServer, |
41d1d075 | 18 | setAccessTokensToServers |
bf54587a | 19 | } from '@shared/server-commands' |
11ba2ab3 C |
20 | |
21 | const expect = chai.expect | |
5f04dd2f | 22 | |
08c1efbe | 23 | describe('Test video channels API validator', function () { |
48dce1c9 | 24 | const videoChannelPath = '/api/v1/video-channels' |
254d3579 | 25 | let server: PeerTubeServer |
2a491182 F |
26 | const userInfo = { |
27 | accessToken: '', | |
28 | channelName: 'fake_channel', | |
29 | id: -1, | |
30 | videoQuota: -1, | |
31 | videoQuotaDaily: -1 | |
32 | } | |
a5461888 | 33 | let command: ChannelsCommand |
5f04dd2f C |
34 | |
35 | // --------------------------------------------------------------- | |
36 | ||
37 | before(async function () { | |
e212f887 | 38 | this.timeout(30000) |
5f04dd2f | 39 | |
254d3579 | 40 | server = await createSingleServer(1) |
5f04dd2f C |
41 | |
42 | await setAccessTokensToServers([ server ]) | |
43 | ||
2a491182 | 44 | const userCreds = { |
5f04dd2f C |
45 | username: 'fake', |
46 | password: 'fake_password' | |
47 | } | |
6b738c7a C |
48 | |
49 | { | |
2a491182 F |
50 | const user = await server.users.create({ username: userCreds.username, password: userCreds.password }) |
51 | userInfo.id = user.id | |
52 | userInfo.accessToken = await server.login.getAccessToken(userCreds) | |
6b738c7a | 53 | } |
a5461888 | 54 | |
89d241a7 | 55 | command = server.channels |
5f04dd2f C |
56 | }) |
57 | ||
58 | describe('When listing a video channels', function () { | |
59 | it('Should fail with a bad start pagination', async function () { | |
48dce1c9 | 60 | await checkBadStartPagination(server.url, videoChannelPath, server.accessToken) |
5f04dd2f C |
61 | }) |
62 | ||
63 | it('Should fail with a bad count pagination', async function () { | |
48dce1c9 | 64 | await checkBadCountPagination(server.url, videoChannelPath, server.accessToken) |
5f04dd2f C |
65 | }) |
66 | ||
67 | it('Should fail with an incorrect sort', async function () { | |
48dce1c9 | 68 | await checkBadSortPagination(server.url, videoChannelPath, server.accessToken) |
5f04dd2f C |
69 | }) |
70 | }) | |
71 | ||
d50acfab | 72 | describe('When listing account video channels', function () { |
91b66319 C |
73 | const accountChannelPath = '/api/v1/accounts/fake/video-channels' |
74 | ||
75 | it('Should fail with a bad start pagination', async function () { | |
76 | await checkBadStartPagination(server.url, accountChannelPath, server.accessToken) | |
77 | }) | |
78 | ||
79 | it('Should fail with a bad count pagination', async function () { | |
80 | await checkBadCountPagination(server.url, accountChannelPath, server.accessToken) | |
81 | }) | |
82 | ||
83 | it('Should fail with an incorrect sort', async function () { | |
84 | await checkBadSortPagination(server.url, accountChannelPath, server.accessToken) | |
85 | }) | |
86 | ||
d50acfab | 87 | it('Should fail with a unknown account', async function () { |
89d241a7 | 88 | await server.channels.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
91b66319 C |
89 | }) |
90 | ||
91 | it('Should succeed with the correct parameters', async function () { | |
92 | await makeGetRequest({ | |
93 | url: server.url, | |
94 | path: accountChannelPath, | |
c0e8b12e | 95 | expectedStatus: HttpStatusCode.OK_200 |
91b66319 | 96 | }) |
5f04dd2f C |
97 | }) |
98 | }) | |
99 | ||
100 | describe('When adding a video channel', function () { | |
11ba2ab3 | 101 | const baseCorrectParams = { |
8a19bee1 | 102 | name: 'super_channel', |
08c1efbe | 103 | displayName: 'hello', |
2422c46b C |
104 | description: 'super description', |
105 | support: 'super support text' | |
11ba2ab3 | 106 | } |
48dce1c9 | 107 | |
5f04dd2f | 108 | it('Should fail with a non authenticated user', async function () { |
cc918ac3 C |
109 | await makePostBodyRequest({ |
110 | url: server.url, | |
111 | path: videoChannelPath, | |
112 | token: 'none', | |
113 | fields: baseCorrectParams, | |
c0e8b12e | 114 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
cc918ac3 | 115 | }) |
5f04dd2f C |
116 | }) |
117 | ||
118 | it('Should fail with nothing', async function () { | |
119 | const fields = {} | |
cc918ac3 | 120 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
121 | }) |
122 | ||
8a19bee1 C |
123 | it('Should fail without a name', async function () { |
124 | const fields = omit(baseCorrectParams, 'name') | |
125 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) | |
126 | }) | |
127 | ||
128 | it('Should fail with a bad name', async function () { | |
6c5065a0 | 129 | const fields = { ...baseCorrectParams, name: 'super name' } |
8a19bee1 C |
130 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
131 | }) | |
132 | ||
08c1efbe C |
133 | it('Should fail without a name', async function () { |
134 | const fields = omit(baseCorrectParams, 'displayName') | |
cc918ac3 | 135 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
136 | }) |
137 | ||
138 | it('Should fail with a long name', async function () { | |
6c5065a0 | 139 | const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } |
cc918ac3 | 140 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
141 | }) |
142 | ||
143 | it('Should fail with a long description', async function () { | |
6c5065a0 | 144 | const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } |
cc918ac3 | 145 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
5f04dd2f C |
146 | }) |
147 | ||
2422c46b | 148 | it('Should fail with a long support text', async function () { |
6c5065a0 | 149 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } |
cc918ac3 | 150 | await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields }) |
2422c46b C |
151 | }) |
152 | ||
5f04dd2f | 153 | it('Should succeed with the correct parameters', async function () { |
11ba2ab3 C |
154 | await makePostBodyRequest({ |
155 | url: server.url, | |
cc918ac3 | 156 | path: videoChannelPath, |
11ba2ab3 C |
157 | token: server.accessToken, |
158 | fields: baseCorrectParams, | |
c0e8b12e | 159 | expectedStatus: HttpStatusCode.OK_200 |
11ba2ab3 | 160 | }) |
5f04dd2f | 161 | }) |
601527d7 C |
162 | |
163 | it('Should fail when adding a channel with the same username', async function () { | |
164 | await makePostBodyRequest({ | |
165 | url: server.url, | |
166 | path: videoChannelPath, | |
167 | token: server.accessToken, | |
168 | fields: baseCorrectParams, | |
c0e8b12e | 169 | expectedStatus: HttpStatusCode.CONFLICT_409 |
601527d7 C |
170 | }) |
171 | }) | |
5f04dd2f C |
172 | }) |
173 | ||
174 | describe('When updating a video channel', function () { | |
7d14d4d2 | 175 | const baseCorrectParams: VideoChannelUpdate = { |
08c1efbe | 176 | displayName: 'hello', |
7d14d4d2 C |
177 | description: 'super description', |
178 | support: 'toto', | |
179 | bulkVideosSupportUpdate: false | |
11ba2ab3 | 180 | } |
6b738c7a | 181 | let path: string |
11ba2ab3 | 182 | |
5f04dd2f | 183 | before(async function () { |
8a19bee1 | 184 | path = videoChannelPath + '/super_channel' |
5f04dd2f C |
185 | }) |
186 | ||
187 | it('Should fail with a non authenticated user', async function () { | |
11ba2ab3 C |
188 | await makePutBodyRequest({ |
189 | url: server.url, | |
48dce1c9 | 190 | path, |
11ba2ab3 C |
191 | token: 'hi', |
192 | fields: baseCorrectParams, | |
c0e8b12e | 193 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
11ba2ab3 | 194 | }) |
5f04dd2f C |
195 | }) |
196 | ||
197 | it('Should fail with another authenticated user', async function () { | |
5f04dd2f C |
198 | await makePutBodyRequest({ |
199 | url: server.url, | |
48dce1c9 | 200 | path, |
2a491182 | 201 | token: userInfo.accessToken, |
11ba2ab3 | 202 | fields: baseCorrectParams, |
c0e8b12e | 203 | expectedStatus: HttpStatusCode.FORBIDDEN_403 |
5f04dd2f C |
204 | }) |
205 | }) | |
206 | ||
207 | it('Should fail with a long name', async function () { | |
6c5065a0 | 208 | const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) } |
48dce1c9 | 209 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
5f04dd2f C |
210 | }) |
211 | ||
212 | it('Should fail with a long description', async function () { | |
6c5065a0 | 213 | const fields = { ...baseCorrectParams, description: 'super'.repeat(201) } |
48dce1c9 | 214 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
5f04dd2f C |
215 | }) |
216 | ||
2422c46b | 217 | it('Should fail with a long support text', async function () { |
6c5065a0 | 218 | const fields = { ...baseCorrectParams, support: 'super'.repeat(201) } |
48dce1c9 | 219 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
2422c46b C |
220 | }) |
221 | ||
7d14d4d2 | 222 | it('Should fail with a bad bulkVideosSupportUpdate field', async function () { |
6c5065a0 | 223 | const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' } |
7d14d4d2 C |
224 | await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields }) |
225 | }) | |
226 | ||
5f04dd2f | 227 | it('Should succeed with the correct parameters', async function () { |
5f04dd2f C |
228 | await makePutBodyRequest({ |
229 | url: server.url, | |
48dce1c9 | 230 | path, |
5f04dd2f | 231 | token: server.accessToken, |
11ba2ab3 | 232 | fields: baseCorrectParams, |
c0e8b12e | 233 | expectedStatus: HttpStatusCode.NO_CONTENT_204 |
5f04dd2f C |
234 | }) |
235 | }) | |
236 | }) | |
237 | ||
d0800f76 | 238 | describe('When updating video channel avatars/banners', function () { |
213e30ef | 239 | const types = [ 'avatar', 'banner' ] |
4bbfc6c6 C |
240 | let path: string |
241 | ||
242 | before(async function () { | |
8a19bee1 | 243 | path = videoChannelPath + '/super_channel' |
4bbfc6c6 C |
244 | }) |
245 | ||
246 | it('Should fail with an incorrect input file', async function () { | |
213e30ef C |
247 | for (const type of types) { |
248 | const fields = {} | |
249 | const attaches = { | |
3d470a53 | 250 | [type + 'file']: buildAbsoluteFixturePath('video_short.mp4') |
213e30ef C |
251 | } |
252 | ||
253 | await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) | |
4bbfc6c6 | 254 | } |
4bbfc6c6 C |
255 | }) |
256 | ||
257 | it('Should fail with a big file', async function () { | |
213e30ef C |
258 | for (const type of types) { |
259 | const fields = {} | |
260 | const attaches = { | |
3d470a53 | 261 | [type + 'file']: buildAbsoluteFixturePath('avatar-big.png') |
213e30ef C |
262 | } |
263 | await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches }) | |
4bbfc6c6 | 264 | } |
4bbfc6c6 C |
265 | }) |
266 | ||
267 | it('Should fail with an unauthenticated user', async function () { | |
213e30ef C |
268 | for (const type of types) { |
269 | const fields = {} | |
270 | const attaches = { | |
3d470a53 | 271 | [type + 'file']: buildAbsoluteFixturePath('avatar.png') |
213e30ef C |
272 | } |
273 | await makeUploadRequest({ | |
274 | url: server.url, | |
275 | path: `${path}/${type}/pick`, | |
276 | fields, | |
277 | attaches, | |
c0e8b12e | 278 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 |
213e30ef | 279 | }) |
4bbfc6c6 | 280 | } |
4bbfc6c6 C |
281 | }) |
282 | ||
283 | it('Should succeed with the correct params', async function () { | |
213e30ef C |
284 | for (const type of types) { |
285 | const fields = {} | |
286 | const attaches = { | |
3d470a53 | 287 | [type + 'file']: buildAbsoluteFixturePath('avatar.png') |
213e30ef C |
288 | } |
289 | await makeUploadRequest({ | |
290 | url: server.url, | |
291 | path: `${path}/${type}/pick`, | |
292 | token: server.accessToken, | |
293 | fields, | |
294 | attaches, | |
c0e8b12e | 295 | expectedStatus: HttpStatusCode.OK_200 |
213e30ef | 296 | }) |
4bbfc6c6 | 297 | } |
4bbfc6c6 C |
298 | }) |
299 | }) | |
300 | ||
5f04dd2f | 301 | describe('When getting a video channel', function () { |
5f04dd2f | 302 | it('Should return the list of the video channels with nothing', async function () { |
11ba2ab3 C |
303 | const res = await makeGetRequest({ |
304 | url: server.url, | |
cc918ac3 | 305 | path: videoChannelPath, |
c0e8b12e | 306 | expectedStatus: HttpStatusCode.OK_200 |
11ba2ab3 | 307 | }) |
5f04dd2f C |
308 | |
309 | expect(res.body.data).to.be.an('array') | |
310 | }) | |
311 | ||
5f04dd2f | 312 | it('Should return 404 with an incorrect video channel', async function () { |
11ba2ab3 C |
313 | await makeGetRequest({ |
314 | url: server.url, | |
8a19bee1 | 315 | path: videoChannelPath + '/super_channel2', |
c0e8b12e | 316 | expectedStatus: HttpStatusCode.NOT_FOUND_404 |
11ba2ab3 | 317 | }) |
5f04dd2f C |
318 | }) |
319 | ||
320 | it('Should succeed with the correct parameters', async function () { | |
11ba2ab3 C |
321 | await makeGetRequest({ |
322 | url: server.url, | |
8a19bee1 | 323 | path: videoChannelPath + '/super_channel', |
c0e8b12e | 324 | expectedStatus: HttpStatusCode.OK_200 |
11ba2ab3 | 325 | }) |
5f04dd2f C |
326 | }) |
327 | }) | |
328 | ||
4beda9e1 C |
329 | describe('When getting channel followers', function () { |
330 | const path = '/api/v1/video-channels/super_channel/followers' | |
331 | ||
332 | it('Should fail with a bad start pagination', async function () { | |
333 | await checkBadStartPagination(server.url, path, server.accessToken) | |
334 | }) | |
335 | ||
336 | it('Should fail with a bad count pagination', async function () { | |
337 | await checkBadCountPagination(server.url, path, server.accessToken) | |
338 | }) | |
339 | ||
340 | it('Should fail with an incorrect sort', async function () { | |
341 | await checkBadSortPagination(server.url, path, server.accessToken) | |
342 | }) | |
343 | ||
344 | it('Should fail with a unauthenticated user', async function () { | |
345 | await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) | |
346 | }) | |
347 | ||
348 | it('Should fail with a another user', async function () { | |
2a491182 | 349 | await makeGetRequest({ url: server.url, path, token: userInfo.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
4beda9e1 C |
350 | }) |
351 | ||
352 | it('Should succeed with the correct params', async function () { | |
353 | await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 }) | |
354 | }) | |
355 | }) | |
356 | ||
2a491182 F |
357 | describe('When triggering full synchronization', function () { |
358 | ||
359 | it('Should fail when HTTP upload is disabled', async function () { | |
360 | await server.config.disableImports() | |
361 | ||
362 | await command.importVideos({ | |
363 | channelName: 'super_channel', | |
364 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | |
365 | token: server.accessToken, | |
366 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
367 | }) | |
368 | ||
369 | await server.config.enableImports() | |
370 | }) | |
371 | ||
372 | it('Should fail when externalChannelUrl is not provided', async function () { | |
373 | await command.importVideos({ | |
374 | channelName: 'super_channel', | |
375 | externalChannelUrl: null, | |
376 | token: server.accessToken, | |
377 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
378 | }) | |
379 | }) | |
380 | ||
381 | it('Should fail when externalChannelUrl is malformed', async function () { | |
382 | await command.importVideos({ | |
383 | channelName: 'super_channel', | |
384 | externalChannelUrl: 'not-a-url', | |
385 | token: server.accessToken, | |
386 | expectedStatus: HttpStatusCode.BAD_REQUEST_400 | |
387 | }) | |
388 | }) | |
389 | ||
390 | it('Should fail with no authentication', async function () { | |
391 | await command.importVideos({ | |
392 | channelName: 'super_channel', | |
393 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | |
394 | token: null, | |
395 | expectedStatus: HttpStatusCode.UNAUTHORIZED_401 | |
396 | }) | |
397 | }) | |
398 | ||
399 | it('Should fail when sync is not owned by the user', async function () { | |
400 | await command.importVideos({ | |
401 | channelName: 'super_channel', | |
402 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | |
403 | token: userInfo.accessToken, | |
404 | expectedStatus: HttpStatusCode.FORBIDDEN_403 | |
405 | }) | |
406 | }) | |
407 | ||
408 | it('Should fail when the user has no quota', async function () { | |
409 | await server.users.update({ | |
410 | userId: userInfo.id, | |
411 | videoQuota: 0 | |
412 | }) | |
413 | ||
414 | await command.importVideos({ | |
415 | channelName: 'fake_channel', | |
416 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | |
417 | token: userInfo.accessToken, | |
418 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | |
419 | }) | |
420 | ||
421 | await server.users.update({ | |
422 | userId: userInfo.id, | |
423 | videoQuota: userInfo.videoQuota | |
424 | }) | |
425 | }) | |
426 | ||
427 | it('Should fail when the user has no daily quota', async function () { | |
428 | await server.users.update({ | |
429 | userId: userInfo.id, | |
430 | videoQuotaDaily: 0 | |
431 | }) | |
432 | ||
433 | await command.importVideos({ | |
434 | channelName: 'fake_channel', | |
435 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | |
436 | token: userInfo.accessToken, | |
437 | expectedStatus: HttpStatusCode.PAYLOAD_TOO_LARGE_413 | |
438 | }) | |
439 | ||
440 | await server.users.update({ | |
441 | userId: userInfo.id, | |
442 | videoQuotaDaily: userInfo.videoQuotaDaily | |
443 | }) | |
444 | }) | |
445 | ||
446 | it('Should succeed when sync is run by its owner', async function () { | |
447 | if (!areHttpImportTestsDisabled()) return | |
448 | ||
449 | await command.importVideos({ | |
450 | channelName: 'fake_channel', | |
451 | externalChannelUrl: FIXTURE_URLS.youtubeChannel, | |
452 | token: userInfo.accessToken | |
453 | }) | |
454 | }) | |
455 | ||
456 | it('Should succeed when sync is run with root and for another user\'s channel', async function () { | |
457 | if (!areHttpImportTestsDisabled()) return | |
458 | ||
459 | await command.importVideos({ | |
460 | channelName: 'fake_channel', | |
461 | externalChannelUrl: FIXTURE_URLS.youtubeChannel | |
462 | }) | |
463 | }) | |
464 | }) | |
465 | ||
5f04dd2f | 466 | describe('When deleting a video channel', function () { |
5f04dd2f | 467 | it('Should fail with a non authenticated user', async function () { |
a5461888 | 468 | await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 }) |
5f04dd2f C |
469 | }) |
470 | ||
471 | it('Should fail with another authenticated user', async function () { | |
2a491182 | 472 | await command.delete({ token: userInfo.accessToken, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 }) |
5f04dd2f C |
473 | }) |
474 | ||
48dce1c9 | 475 | it('Should fail with an unknown video channel id', async function () { |
a5461888 | 476 | await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 }) |
5f04dd2f C |
477 | }) |
478 | ||
479 | it('Should succeed with the correct parameters', async function () { | |
a5461888 | 480 | await command.delete({ channelName: 'super_channel' }) |
5f04dd2f C |
481 | }) |
482 | ||
483 | it('Should fail to delete the last user video channel', async function () { | |
a5461888 | 484 | await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 }) |
5f04dd2f C |
485 | }) |
486 | }) | |
487 | ||
7c3b7976 C |
488 | after(async function () { |
489 | await cleanupTests([ server ]) | |
5f04dd2f C |
490 | }) |
491 | }) |