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