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