]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-channels.ts
Improve remote runner config UX
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-channels.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
5f04dd2f 2
bbd5aa7e 3import { expect } from 'chai'
a3b472a1 4import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '@server/tests/shared'
bbd5aa7e 5import { buildAbsoluteFixturePath, omit } from '@shared/core-utils'
c55e3d72 6import { HttpStatusCode, VideoChannelUpdate } from '@shared/models'
5f04dd2f 7import {
a5461888 8 ChannelsCommand,
7c3b7976 9 cleanupTests,
254d3579 10 createSingleServer,
48dce1c9
C
11 makeGetRequest,
12 makePostBodyRequest,
52d9f792
C
13 makePutBodyRequest,
14 makeUploadRequest,
254d3579 15 PeerTubeServer,
41d1d075 16 setAccessTokensToServers
bf54587a 17} from '@shared/server-commands'
11ba2ab3 18
08c1efbe 19describe('Test video channels API validator', function () {
48dce1c9 20 const videoChannelPath = '/api/v1/video-channels'
254d3579 21 let server: PeerTubeServer
2a491182
F
22 const userInfo = {
23 accessToken: '',
24 channelName: 'fake_channel',
25 id: -1,
26 videoQuota: -1,
27 videoQuotaDaily: -1
28 }
a5461888 29 let command: ChannelsCommand
5f04dd2f
C
30
31 // ---------------------------------------------------------------
32
33 before(async function () {
e212f887 34 this.timeout(30000)
5f04dd2f 35
254d3579 36 server = await createSingleServer(1)
5f04dd2f
C
37
38 await setAccessTokensToServers([ server ])
39
2a491182 40 const userCreds = {
5f04dd2f
C
41 username: 'fake',
42 password: 'fake_password'
43 }
6b738c7a
C
44
45 {
2a491182
F
46 const user = await server.users.create({ username: userCreds.username, password: userCreds.password })
47 userInfo.id = user.id
48 userInfo.accessToken = await server.login.getAccessToken(userCreds)
6b738c7a 49 }
a5461888 50
89d241a7 51 command = server.channels
5f04dd2f
C
52 })
53
54 describe('When listing a video channels', function () {
55 it('Should fail with a bad start pagination', async function () {
48dce1c9 56 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
5f04dd2f
C
57 })
58
59 it('Should fail with a bad count pagination', async function () {
48dce1c9 60 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
5f04dd2f
C
61 })
62
63 it('Should fail with an incorrect sort', async function () {
48dce1c9 64 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
5f04dd2f
C
65 })
66 })
67
d50acfab 68 describe('When listing account video channels', function () {
91b66319
C
69 const accountChannelPath = '/api/v1/accounts/fake/video-channels'
70
71 it('Should fail with a bad start pagination', async function () {
72 await checkBadStartPagination(server.url, accountChannelPath, server.accessToken)
73 })
74
75 it('Should fail with a bad count pagination', async function () {
76 await checkBadCountPagination(server.url, accountChannelPath, server.accessToken)
77 })
78
79 it('Should fail with an incorrect sort', async function () {
80 await checkBadSortPagination(server.url, accountChannelPath, server.accessToken)
81 })
82
d50acfab 83 it('Should fail with a unknown account', async function () {
89d241a7 84 await server.channels.listByAccount({ accountName: 'unknown', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
91b66319
C
85 })
86
87 it('Should succeed with the correct parameters', async function () {
88 await makeGetRequest({
89 url: server.url,
90 path: accountChannelPath,
c0e8b12e 91 expectedStatus: HttpStatusCode.OK_200
91b66319 92 })
5f04dd2f
C
93 })
94 })
95
96 describe('When adding a video channel', function () {
11ba2ab3 97 const baseCorrectParams = {
8a19bee1 98 name: 'super_channel',
08c1efbe 99 displayName: 'hello',
2422c46b
C
100 description: 'super description',
101 support: 'super support text'
11ba2ab3 102 }
48dce1c9 103
5f04dd2f 104 it('Should fail with a non authenticated user', async function () {
cc918ac3
C
105 await makePostBodyRequest({
106 url: server.url,
107 path: videoChannelPath,
108 token: 'none',
109 fields: baseCorrectParams,
c0e8b12e 110 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
cc918ac3 111 })
5f04dd2f
C
112 })
113
114 it('Should fail with nothing', async function () {
115 const fields = {}
cc918ac3 116 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
117 })
118
8a19bee1 119 it('Should fail without a name', async function () {
bbd5aa7e 120 const fields = omit(baseCorrectParams, [ 'name' ])
8a19bee1
C
121 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
122 })
123
124 it('Should fail with a bad name', async function () {
6c5065a0 125 const fields = { ...baseCorrectParams, name: 'super name' }
8a19bee1
C
126 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
127 })
128
08c1efbe 129 it('Should fail without a name', async function () {
bbd5aa7e 130 const fields = omit(baseCorrectParams, [ 'displayName' ])
cc918ac3 131 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
132 })
133
134 it('Should fail with a long name', async function () {
6c5065a0 135 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
cc918ac3 136 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
137 })
138
139 it('Should fail with a long description', async function () {
6c5065a0 140 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
cc918ac3 141 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
5f04dd2f
C
142 })
143
2422c46b 144 it('Should fail with a long support text', async function () {
6c5065a0 145 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
cc918ac3 146 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
2422c46b
C
147 })
148
5f04dd2f 149 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
150 await makePostBodyRequest({
151 url: server.url,
cc918ac3 152 path: videoChannelPath,
11ba2ab3
C
153 token: server.accessToken,
154 fields: baseCorrectParams,
c0e8b12e 155 expectedStatus: HttpStatusCode.OK_200
11ba2ab3 156 })
5f04dd2f 157 })
601527d7
C
158
159 it('Should fail when adding a channel with the same username', async function () {
160 await makePostBodyRequest({
161 url: server.url,
162 path: videoChannelPath,
163 token: server.accessToken,
164 fields: baseCorrectParams,
c0e8b12e 165 expectedStatus: HttpStatusCode.CONFLICT_409
601527d7
C
166 })
167 })
5f04dd2f
C
168 })
169
170 describe('When updating a video channel', function () {
7d14d4d2 171 const baseCorrectParams: VideoChannelUpdate = {
08c1efbe 172 displayName: 'hello',
7d14d4d2
C
173 description: 'super description',
174 support: 'toto',
175 bulkVideosSupportUpdate: false
11ba2ab3 176 }
6b738c7a 177 let path: string
11ba2ab3 178
5f04dd2f 179 before(async function () {
8a19bee1 180 path = videoChannelPath + '/super_channel'
5f04dd2f
C
181 })
182
183 it('Should fail with a non authenticated user', async function () {
11ba2ab3
C
184 await makePutBodyRequest({
185 url: server.url,
48dce1c9 186 path,
11ba2ab3
C
187 token: 'hi',
188 fields: baseCorrectParams,
c0e8b12e 189 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
11ba2ab3 190 })
5f04dd2f
C
191 })
192
193 it('Should fail with another authenticated user', async function () {
5f04dd2f
C
194 await makePutBodyRequest({
195 url: server.url,
48dce1c9 196 path,
2a491182 197 token: userInfo.accessToken,
11ba2ab3 198 fields: baseCorrectParams,
c0e8b12e 199 expectedStatus: HttpStatusCode.FORBIDDEN_403
5f04dd2f
C
200 })
201 })
202
203 it('Should fail with a long name', async function () {
6c5065a0 204 const fields = { ...baseCorrectParams, displayName: 'super'.repeat(25) }
48dce1c9 205 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
206 })
207
208 it('Should fail with a long description', async function () {
6c5065a0 209 const fields = { ...baseCorrectParams, description: 'super'.repeat(201) }
48dce1c9 210 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
211 })
212
2422c46b 213 it('Should fail with a long support text', async function () {
6c5065a0 214 const fields = { ...baseCorrectParams, support: 'super'.repeat(201) }
48dce1c9 215 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
2422c46b
C
216 })
217
7d14d4d2 218 it('Should fail with a bad bulkVideosSupportUpdate field', async function () {
6c5065a0 219 const fields = { ...baseCorrectParams, bulkVideosSupportUpdate: 'super' }
7d14d4d2
C
220 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
221 })
222
5f04dd2f 223 it('Should succeed with the correct parameters', async function () {
5f04dd2f
C
224 await makePutBodyRequest({
225 url: server.url,
48dce1c9 226 path,
5f04dd2f 227 token: server.accessToken,
11ba2ab3 228 fields: baseCorrectParams,
c0e8b12e 229 expectedStatus: HttpStatusCode.NO_CONTENT_204
5f04dd2f
C
230 })
231 })
232 })
233
d0800f76 234 describe('When updating video channel avatars/banners', function () {
213e30ef 235 const types = [ 'avatar', 'banner' ]
4bbfc6c6
C
236 let path: string
237
238 before(async function () {
8a19bee1 239 path = videoChannelPath + '/super_channel'
4bbfc6c6
C
240 })
241
242 it('Should fail with an incorrect input file', async function () {
213e30ef
C
243 for (const type of types) {
244 const fields = {}
245 const attaches = {
3d470a53 246 [type + 'file']: buildAbsoluteFixturePath('video_short.mp4')
213e30ef
C
247 }
248
249 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
4bbfc6c6 250 }
4bbfc6c6
C
251 })
252
253 it('Should fail with a big file', async function () {
213e30ef
C
254 for (const type of types) {
255 const fields = {}
256 const attaches = {
3d470a53 257 [type + 'file']: buildAbsoluteFixturePath('avatar-big.png')
213e30ef
C
258 }
259 await makeUploadRequest({ url: server.url, path: `${path}/${type}/pick`, token: server.accessToken, fields, attaches })
4bbfc6c6 260 }
4bbfc6c6
C
261 })
262
263 it('Should fail with an unauthenticated user', async function () {
213e30ef
C
264 for (const type of types) {
265 const fields = {}
266 const attaches = {
3d470a53 267 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
213e30ef
C
268 }
269 await makeUploadRequest({
270 url: server.url,
271 path: `${path}/${type}/pick`,
272 fields,
273 attaches,
c0e8b12e 274 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
213e30ef 275 })
4bbfc6c6 276 }
4bbfc6c6
C
277 })
278
279 it('Should succeed with the correct params', async function () {
213e30ef
C
280 for (const type of types) {
281 const fields = {}
282 const attaches = {
3d470a53 283 [type + 'file']: buildAbsoluteFixturePath('avatar.png')
213e30ef
C
284 }
285 await makeUploadRequest({
286 url: server.url,
287 path: `${path}/${type}/pick`,
288 token: server.accessToken,
289 fields,
290 attaches,
c0e8b12e 291 expectedStatus: HttpStatusCode.OK_200
213e30ef 292 })
4bbfc6c6 293 }
4bbfc6c6
C
294 })
295 })
296
5f04dd2f 297 describe('When getting a video channel', function () {
5f04dd2f 298 it('Should return the list of the video channels with nothing', async function () {
11ba2ab3
C
299 const res = await makeGetRequest({
300 url: server.url,
cc918ac3 301 path: videoChannelPath,
c0e8b12e 302 expectedStatus: HttpStatusCode.OK_200
11ba2ab3 303 })
5f04dd2f
C
304
305 expect(res.body.data).to.be.an('array')
306 })
307
5f04dd2f 308 it('Should return 404 with an incorrect video channel', async function () {
11ba2ab3
C
309 await makeGetRequest({
310 url: server.url,
8a19bee1 311 path: videoChannelPath + '/super_channel2',
c0e8b12e 312 expectedStatus: HttpStatusCode.NOT_FOUND_404
11ba2ab3 313 })
5f04dd2f
C
314 })
315
316 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
317 await makeGetRequest({
318 url: server.url,
8a19bee1 319 path: videoChannelPath + '/super_channel',
c0e8b12e 320 expectedStatus: HttpStatusCode.OK_200
11ba2ab3 321 })
5f04dd2f
C
322 })
323 })
324
4beda9e1
C
325 describe('When getting channel followers', function () {
326 const path = '/api/v1/video-channels/super_channel/followers'
327
328 it('Should fail with a bad start pagination', async function () {
329 await checkBadStartPagination(server.url, path, server.accessToken)
330 })
331
332 it('Should fail with a bad count pagination', async function () {
333 await checkBadCountPagination(server.url, path, server.accessToken)
334 })
335
336 it('Should fail with an incorrect sort', async function () {
337 await checkBadSortPagination(server.url, path, server.accessToken)
338 })
339
340 it('Should fail with a unauthenticated user', async function () {
341 await makeGetRequest({ url: server.url, path, expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
342 })
343
344 it('Should fail with a another user', async function () {
2a491182 345 await makeGetRequest({ url: server.url, path, token: userInfo.accessToken, expectedStatus: HttpStatusCode.FORBIDDEN_403 })
4beda9e1
C
346 })
347
348 it('Should succeed with the correct params', async function () {
349 await makeGetRequest({ url: server.url, path, token: server.accessToken, expectedStatus: HttpStatusCode.OK_200 })
350 })
351 })
352
5f04dd2f 353 describe('When deleting a video channel', function () {
5f04dd2f 354 it('Should fail with a non authenticated user', async function () {
a5461888 355 await command.delete({ token: 'coucou', channelName: 'super_channel', expectedStatus: HttpStatusCode.UNAUTHORIZED_401 })
5f04dd2f
C
356 })
357
358 it('Should fail with another authenticated user', async function () {
2a491182 359 await command.delete({ token: userInfo.accessToken, channelName: 'super_channel', expectedStatus: HttpStatusCode.FORBIDDEN_403 })
5f04dd2f
C
360 })
361
48dce1c9 362 it('Should fail with an unknown video channel id', async function () {
a5461888 363 await command.delete({ channelName: 'super_channel2', expectedStatus: HttpStatusCode.NOT_FOUND_404 })
5f04dd2f
C
364 })
365
366 it('Should succeed with the correct parameters', async function () {
a5461888 367 await command.delete({ channelName: 'super_channel' })
5f04dd2f
C
368 })
369
370 it('Should fail to delete the last user video channel', async function () {
a5461888 371 await command.delete({ channelName: 'root_channel', expectedStatus: HttpStatusCode.CONFLICT_409 })
5f04dd2f
C
372 })
373 })
374
7c3b7976
C
375 after(async function () {
376 await cleanupTests([ server ])
5f04dd2f
C
377 })
378})