]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/video-channels.ts
Add videos list filters
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / video-channels.ts
1 /* tslint:disable:no-unused-expression */
2
3 import * as chai from 'chai'
4 import { omit } from 'lodash'
5 import 'mocha'
6 import {
7 createUser,
8 deleteVideoChannel,
9 flushTests,
10 getAccountVideoChannelsList,
11 getMyUserInformation,
12 getVideoChannelsList,
13 immutableAssign,
14 killallServers,
15 makeGetRequest,
16 makePostBodyRequest,
17 makePutBodyRequest,
18 makeUploadRequest,
19 runServer,
20 ServerInfo,
21 setAccessTokensToServers,
22 userLogin
23 } from '../../utils'
24 import { checkBadCountPagination, checkBadSortPagination, checkBadStartPagination } from '../../utils/requests/check-api-params'
25 import { User } from '../../../../shared/models/users'
26 import { join } from 'path'
27
28 const expect = chai.expect
29
30 describe('Test video channels API validator', function () {
31 const videoChannelPath = '/api/v1/video-channels'
32 let server: ServerInfo
33 let accessTokenUser: string
34 let videoChannelUUID: string
35
36 // ---------------------------------------------------------------
37
38 before(async function () {
39 this.timeout(30000)
40
41 await flushTests()
42
43 server = await runServer(1)
44
45 await setAccessTokensToServers([ server ])
46
47 const user = {
48 username: 'fake',
49 password: 'fake_password'
50 }
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
60 videoChannelUUID = user.videoChannels[0].uuid
61 }
62 })
63
64 describe('When listing a video channels', function () {
65 it('Should fail with a bad start pagination', async function () {
66 await checkBadStartPagination(server.url, videoChannelPath, server.accessToken)
67 })
68
69 it('Should fail with a bad count pagination', async function () {
70 await checkBadCountPagination(server.url, videoChannelPath, server.accessToken)
71 })
72
73 it('Should fail with an incorrect sort', async function () {
74 await checkBadSortPagination(server.url, videoChannelPath, server.accessToken)
75 })
76 })
77
78 describe('When listing account video channels', function () {
79 it('Should fail with a unknown account', async function () {
80 await getAccountVideoChannelsList(server.url, 'unknown', 404)
81 })
82 })
83
84 describe('When adding a video channel', function () {
85 const baseCorrectParams = {
86 displayName: 'hello',
87 description: 'super description',
88 support: 'super support text'
89 }
90
91 it('Should fail with a non authenticated user', async function () {
92 await makePostBodyRequest({
93 url: server.url,
94 path: videoChannelPath,
95 token: 'none',
96 fields: baseCorrectParams,
97 statusCodeExpected: 401
98 })
99 })
100
101 it('Should fail with nothing', async function () {
102 const fields = {}
103 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
104 })
105
106 it('Should fail without a name', async function () {
107 const fields = omit(baseCorrectParams, 'displayName')
108 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
109 })
110
111 it('Should fail with a long name', async function () {
112 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
113 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
114 })
115
116 it('Should fail with a long description', async function () {
117 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
118 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
119 })
120
121 it('Should fail with a long support text', async function () {
122 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
123 await makePostBodyRequest({ url: server.url, path: videoChannelPath, token: server.accessToken, fields })
124 })
125
126 it('Should succeed with the correct parameters', async function () {
127 await makePostBodyRequest({
128 url: server.url,
129 path: videoChannelPath,
130 token: server.accessToken,
131 fields: baseCorrectParams,
132 statusCodeExpected: 200
133 })
134 })
135 })
136
137 describe('When updating a video channel', function () {
138 const baseCorrectParams = {
139 displayName: 'hello',
140 description: 'super description'
141 }
142 let path: string
143
144 before(async function () {
145 path = videoChannelPath + '/' + videoChannelUUID
146 })
147
148 it('Should fail with a non authenticated user', async function () {
149 await makePutBodyRequest({
150 url: server.url,
151 path,
152 token: 'hi',
153 fields: baseCorrectParams,
154 statusCodeExpected: 401
155 })
156 })
157
158 it('Should fail with another authenticated user', async function () {
159 await makePutBodyRequest({
160 url: server.url,
161 path,
162 token: accessTokenUser,
163 fields: baseCorrectParams,
164 statusCodeExpected: 403
165 })
166 })
167
168 it('Should fail with a long name', async function () {
169 const fields = immutableAssign(baseCorrectParams, { displayName: 'super'.repeat(25) })
170 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
171 })
172
173 it('Should fail with a long description', async function () {
174 const fields = immutableAssign(baseCorrectParams, { description: 'super'.repeat(150) })
175 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
176 })
177
178 it('Should fail with a long support text', async function () {
179 const fields = immutableAssign(baseCorrectParams, { support: 'super'.repeat(150) })
180 await makePutBodyRequest({ url: server.url, path, token: server.accessToken, fields })
181 })
182
183 it('Should succeed with the correct parameters', async function () {
184 await makePutBodyRequest({
185 url: server.url,
186 path,
187 token: server.accessToken,
188 fields: baseCorrectParams,
189 statusCodeExpected: 204
190 })
191 })
192 })
193
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
247 describe('When getting a video channel', function () {
248 it('Should return the list of the video channels with nothing', async function () {
249 const res = await makeGetRequest({
250 url: server.url,
251 path: videoChannelPath,
252 statusCodeExpected: 200
253 })
254
255 expect(res.body.data).to.be.an('array')
256 })
257
258 it('Should fail without a correct uuid', async function () {
259 await makeGetRequest({
260 url: server.url,
261 path: videoChannelPath + '/coucou',
262 statusCodeExpected: 400
263 })
264 })
265
266 it('Should return 404 with an incorrect video channel', async function () {
267 await makeGetRequest({
268 url: server.url,
269 path: videoChannelPath + '/4da6fde3-88f7-4d16-b119-108df5630b06',
270 statusCodeExpected: 404
271 })
272 })
273
274 it('Should succeed with the correct parameters', async function () {
275 await makeGetRequest({
276 url: server.url,
277 path: videoChannelPath + '/' + videoChannelUUID,
278 statusCodeExpected: 200
279 })
280 })
281 })
282
283 describe('When deleting a video channel', function () {
284 it('Should fail with a non authenticated user', async function () {
285 await deleteVideoChannel(server.url, 'coucou', videoChannelUUID, 401)
286 })
287
288 it('Should fail with another authenticated user', async function () {
289 await deleteVideoChannel(server.url, accessTokenUser, videoChannelUUID, 403)
290 })
291
292 it('Should fail with an unknown video channel id', async function () {
293 await deleteVideoChannel(server.url, server.accessToken,454554, 404)
294 })
295
296 it('Should succeed with the correct parameters', async function () {
297 await deleteVideoChannel(server.url, server.accessToken, videoChannelUUID)
298 })
299
300 it('Should fail to delete the last user video channel', async function () {
301 const res = await getVideoChannelsList(server.url, 0, 1)
302 const lastVideoChannelUUID = res.body.data[0].uuid
303
304 await deleteVideoChannel(server.url, server.accessToken, lastVideoChannelUUID, 409)
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 })