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