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