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