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