]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/video-channels.ts
Add pagination to account video channels endpoint
[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'
11ba2ab3
C
27
28const expect = chai.expect
5f04dd2f 29
08c1efbe 30describe('Test video channels API validator', function () {
48dce1c9 31 const videoChannelPath = '/api/v1/video-channels'
5f04dd2f 32 let server: ServerInfo
5f04dd2f
C
33 let accessTokenUser: string
34
35 // ---------------------------------------------------------------
36
37 before(async function () {
e212f887 38 this.timeout(30000)
5f04dd2f 39
210feb6c 40 server = await flushAndRunServer(1)
5f04dd2f
C
41
42 await setAccessTokensToServers([ server ])
43
5f04dd2f
C
44 const user = {
45 username: 'fake',
46 password: 'fake_password'
47 }
6b738c7a
C
48
49 {
1eddc9a7 50 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
6b738c7a
C
51 accessTokenUser = await userLogin(server, user)
52 }
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 () {
91b66319
C
85 await getAccountVideoChannelsList({ url: server.url, accountName: 'unknown', specialStatus: 404 })
86 })
87
88 it('Should succeed with the correct parameters', async function () {
89 await makeGetRequest({
90 url: server.url,
91 path: accountChannelPath,
92 statusCodeExpected: 200
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,
111 statusCodeExpected: 401
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 () {
126 const fields = immutableAssign(baseCorrectParams, { name: 'super name' })
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 () {
08c1efbe 136 const fields = immutableAssign(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 () {
d23e6a1c 141 const fields = immutableAssign(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 () {
d23e6a1c 146 const fields = immutableAssign(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,
2422c46b 156 statusCodeExpected: 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,
166 statusCodeExpected: 409
167 })
168 })
5f04dd2f
C
169 })
170
171 describe('When updating a video channel', function () {
11ba2ab3 172 const baseCorrectParams = {
08c1efbe 173 displayName: 'hello',
11ba2ab3
C
174 description: 'super description'
175 }
6b738c7a 176 let path: string
11ba2ab3 177
5f04dd2f 178 before(async function () {
8a19bee1 179 path = videoChannelPath + '/super_channel'
5f04dd2f
C
180 })
181
182 it('Should fail with a non authenticated user', async function () {
11ba2ab3
C
183 await makePutBodyRequest({
184 url: server.url,
48dce1c9 185 path,
11ba2ab3
C
186 token: 'hi',
187 fields: baseCorrectParams,
188 statusCodeExpected: 401
189 })
5f04dd2f
C
190 })
191
192 it('Should fail with another authenticated user', async function () {
5f04dd2f
C
193 await makePutBodyRequest({
194 url: server.url,
48dce1c9 195 path,
5f04dd2f 196 token: accessTokenUser,
11ba2ab3 197 fields: baseCorrectParams,
5f04dd2f
C
198 statusCodeExpected: 403
199 })
200 })
201
202 it('Should fail with a long name', async function () {
08c1efbe 203 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
48dce1c9 204 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
205 })
206
207 it('Should fail with a long description', async function () {
d23e6a1c 208 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(201) })
48dce1c9 209 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
5f04dd2f
C
210 })
211
2422c46b 212 it('Should fail with a long support text', async function () {
d23e6a1c 213 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(201) })
48dce1c9 214 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
2422c46b
C
215 })
216
5f04dd2f 217 it('Should succeed with the correct parameters', async function () {
5f04dd2f
C
218 await makePutBodyRequest({
219 url: server.url,
48dce1c9 220 path,
5f04dd2f 221 token: server.accessToken,
11ba2ab3 222 fields: baseCorrectParams,
5f04dd2f
C
223 statusCodeExpected: 204
224 })
225 })
226 })
227
4bbfc6c6
C
228 describe('When updating video channel avatar', function () {
229 let path: string
230
231 before(async function () {
8a19bee1 232 path = videoChannelPath + '/super_channel'
4bbfc6c6
C
233 })
234
235 it('Should fail with an incorrect input file', async function () {
236 const fields = {}
237 const attaches = {
238 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'video_short.mp4')
239 }
240 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
241 })
242
243 it('Should fail with a big file', async function () {
244 const fields = {}
245 const attaches = {
246 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar-big.png')
247 }
248 await makeUploadRequest({ url: server.url, path: path + '/avatar/pick', token: server.accessToken, fields, attaches })
249 })
250
251 it('Should fail with an unauthenticated user', async function () {
252 const fields = {}
253 const attaches = {
254 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
255 }
256 await makeUploadRequest({
257 url: server.url,
258 path: path + '/avatar/pick',
259 fields,
260 attaches,
261 statusCodeExpected: 401
262 })
263 })
264
265 it('Should succeed with the correct params', async function () {
266 const fields = {}
267 const attaches = {
268 'avatarfile': join(__dirname, '..', '..', 'fixtures', 'avatar.png')
269 }
270 await makeUploadRequest({
271 url: server.url,
272 path: path + '/avatar/pick',
273 token: server.accessToken,
274 fields,
275 attaches,
276 statusCodeExpected: 200
277 })
278 })
279 })
280
5f04dd2f 281 describe('When getting a video channel', function () {
5f04dd2f 282 it('Should return the list of the video channels with nothing', async function () {
11ba2ab3
C
283 const res = await makeGetRequest({
284 url: server.url,
cc918ac3 285 path: videoChannelPath,
11ba2ab3
C
286 statusCodeExpected: 200
287 })
5f04dd2f
C
288
289 expect(res.body.data).to.be.an('array')
290 })
291
5f04dd2f 292 it('Should return 404 with an incorrect video channel', async function () {
11ba2ab3
C
293 await makeGetRequest({
294 url: server.url,
8a19bee1 295 path: videoChannelPath + '/super_channel2',
11ba2ab3
C
296 statusCodeExpected: 404
297 })
5f04dd2f
C
298 })
299
300 it('Should succeed with the correct parameters', async function () {
11ba2ab3
C
301 await makeGetRequest({
302 url: server.url,
8a19bee1 303 path: videoChannelPath + '/super_channel',
11ba2ab3
C
304 statusCodeExpected: 200
305 })
5f04dd2f
C
306 })
307 })
308
309 describe('When deleting a video channel', function () {
5f04dd2f 310 it('Should fail with a non authenticated user', async function () {
8a19bee1 311 await deleteVideoChannel(server.url, 'coucou', 'super_channel', 401)
5f04dd2f
C
312 })
313
314 it('Should fail with another authenticated user', async function () {
8a19bee1 315 await deleteVideoChannel(server.url, accessTokenUser, 'super_channel', 403)
5f04dd2f
C
316 })
317
48dce1c9 318 it('Should fail with an unknown video channel id', async function () {
8a19bee1 319 await deleteVideoChannel(server.url, server.accessToken,'super_channel2', 404)
5f04dd2f
C
320 })
321
322 it('Should succeed with the correct parameters', async function () {
8a19bee1 323 await deleteVideoChannel(server.url, server.accessToken, 'super_channel')
5f04dd2f
C
324 })
325
326 it('Should fail to delete the last user video channel', async function () {
8a19bee1 327 await deleteVideoChannel(server.url, server.accessToken, 'root_channel', 409)
5f04dd2f
C
328 })
329 })
330
7c3b7976
C
331 after(async function () {
332 await cleanupTests([ server ])
5f04dd2f
C
333 })
334})