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