]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/check-params/config.ts
Optimize videos list API endpoint
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
CommitLineData
a1587156 1/* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
fd206f0b
C
2
3import { omit } from 'lodash'
4import 'mocha'
09cababd 5import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
fd206f0b
C
6
7import {
8424c402
C
8 cleanupTests,
9 createUser,
10 flushAndRunServer,
11 immutableAssign,
12 makeDeleteRequest,
13 makeGetRequest,
14 makePutBodyRequest,
15 ServerInfo,
16 setAccessTokensToServers,
17 userLogin
94565d52 18} from '../../../../shared/extra-utils'
2d53be02 19import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
fd206f0b
C
20
21describe('Test config API validators', function () {
22 const path = '/api/v1/config/custom'
23 let server: ServerInfo
24 let userAccessToken: string
25 const updateParams: CustomConfig = {
66b16caf
C
26 instance: {
27 name: 'PeerTube updated',
2e3a0215 28 shortDescription: 'my short description',
66b16caf 29 description: 'my super description',
00b5556c 30 terms: 'my super terms',
ccc00cb2
C
31 codeOfConduct: 'my super coc',
32
8ae03c37 33 creationReason: 'my super reason',
ccc00cb2
C
34 moderationInformation: 'my super moderation information',
35 administrator: 'Kuja',
36 maintenanceLifetime: 'forever',
37 businessModel: 'my super business model',
be04c6fd 38 hardwareInformation: '2vCore 3GB RAM',
ccc00cb2
C
39
40 languages: [ 'en', 'es' ],
41 categories: [ 1, 2 ],
42
f8802489 43 isNSFW: true,
0883b324 44 defaultNSFWPolicy: 'blur',
3da68f0a
RK
45
46 defaultClientRoute: '/videos/recently-added',
3da68f0a 47
00b5556c
C
48 customizations: {
49 javascript: 'alert("coucou")',
50 css: 'body { background-color: red; }'
51 }
66b16caf 52 },
7cd4d2ba
C
53 theme: {
54 default: 'default'
55 },
8be1afa1
C
56 services: {
57 twitter: {
58 username: '@MySuperUsername',
59 whitelisted: true
60 }
61 },
fd206f0b
C
62 cache: {
63 previews: {
64 size: 2
40e87e9e
C
65 },
66 captions: {
67 size: 3
fd206f0b
C
68 }
69 },
70 signup: {
71 enabled: false,
d9eaee39
JM
72 limit: 5,
73 requiresEmailVerification: false
fd206f0b
C
74 },
75 admin: {
76 email: 'superadmin1@example.com'
77 },
a4101923
C
78 contactForm: {
79 enabled: false
80 },
fd206f0b 81 user: {
bee0abff
FA
82 videoQuota: 5242881,
83 videoQuotaDaily: 318742
fd206f0b
C
84 },
85 transcoding: {
86 enabled: true,
14e2014a 87 allowAdditionalExtensions: true,
536598cf 88 allowAudioFiles: true,
fd206f0b 89 threads: 1,
1896bca0 90 profile: 'vod_profile',
fd206f0b 91 resolutions: {
5c7d6508 92 '0p': false,
fd206f0b
C
93 '240p': false,
94 '360p': true,
95 '480p': true,
96 '720p': false,
db714ab4 97 '1080p': false,
b7085c71 98 '1440p': false,
db714ab4 99 '2160p': false
09209296 100 },
d7a25329
C
101 webtorrent: {
102 enabled: true
103 },
09209296
C
104 hls: {
105 enabled: false
fd206f0b 106 }
5d08a6a7 107 },
c6c0fa6c
C
108 live: {
109 enabled: true,
110
fb719404 111 allowReplay: false,
c9bc850e 112 maxDuration: 30,
a056ca48
C
113 maxInstanceLives: -1,
114 maxUserLives: 50,
fb719404 115
c6c0fa6c
C
116 transcoding: {
117 enabled: true,
118 threads: 4,
1896bca0 119 profile: 'live_profile',
c6c0fa6c
C
120 resolutions: {
121 '240p': true,
122 '360p': true,
123 '480p': true,
124 '720p': true,
125 '1080p': true,
b7085c71 126 '1440p': true,
c6c0fa6c
C
127 '2160p': true
128 }
129 }
130 },
5d08a6a7
C
131 import: {
132 videos: {
133 http: {
134 enabled: false
a84b8fa5
C
135 },
136 torrent: {
137 enabled: false
5d08a6a7
C
138 }
139 }
7ccddd7b 140 },
ba5d4a84
RK
141 trending: {
142 videos: {
143 algorithms: {
3d4e112d 144 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
ba5d4a84
RK
145 default: 'most-viewed'
146 }
147 }
148 },
7ccddd7b
JM
149 autoBlacklist: {
150 videos: {
151 ofUsers: {
152 enabled: false
153 }
154 }
5b9c965d
C
155 },
156 followers: {
157 instance: {
14893eb7
C
158 enabled: false,
159 manualApproval: true
5b9c965d 160 }
8424c402
C
161 },
162 followings: {
163 instance: {
164 autoFollowBack: {
165 enabled: true
166 },
167 autoFollowIndex: {
168 enabled: true,
169 indexUrl: 'https://index.example.com'
170 }
171 }
72c33e71
C
172 },
173 broadcastMessage: {
174 enabled: true,
175 dismissable: true,
176 message: 'super message',
177 level: 'warning'
5fb2e288
C
178 },
179 search: {
180 remoteUri: {
181 users: true,
182 anonymous: true
183 },
184 searchIndex: {
185 enabled: true,
186 url: 'https://search.joinpeertube.org',
187 disableLocalSearch: true,
188 isDefaultSearch: true
189 }
fd206f0b
C
190 }
191 }
192
193 // ---------------------------------------------------------------
194
195 before(async function () {
e212f887 196 this.timeout(30000)
fd206f0b 197
210feb6c 198 server = await flushAndRunServer(1)
fd206f0b
C
199
200 await setAccessTokensToServers([ server ])
201
202 const user = {
203 username: 'user1',
204 password: 'password'
205 }
1eddc9a7 206 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
fd206f0b
C
207 userAccessToken = await userLogin(server, user)
208 })
209
210 describe('When getting the configuration', function () {
211 it('Should fail without token', async function () {
212 await makeGetRequest({
213 url: server.url,
214 path,
2d53be02 215 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
216 })
217 })
218
219 it('Should fail if the user is not an administrator', async function () {
220 await makeGetRequest({
221 url: server.url,
222 path,
223 token: userAccessToken,
2d53be02 224 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
225 })
226 })
227 })
228
229 describe('When updating the configuration', function () {
230 it('Should fail without token', async function () {
231 await makePutBodyRequest({
232 url: server.url,
233 path,
234 fields: updateParams,
2d53be02 235 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
236 })
237 })
238
239 it('Should fail if the user is not an administrator', async function () {
240 await makePutBodyRequest({
241 url: server.url,
242 path,
243 fields: updateParams,
244 token: userAccessToken,
2d53be02 245 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
246 })
247 })
248
249 it('Should fail if it misses a key', async function () {
250 const newUpdateParams = omit(updateParams, 'admin.email')
251
252 await makePutBodyRequest({
253 url: server.url,
254 path,
0883b324
C
255 fields: newUpdateParams,
256 token: server.accessToken,
2d53be02 257 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
0883b324
C
258 })
259 })
260
261 it('Should fail with a bad default NSFW policy', async function () {
262 const newUpdateParams = immutableAssign(updateParams, {
263 instance: {
264 defaultNSFWPolicy: 'hello'
265 }
266 })
267
268 await makePutBodyRequest({
269 url: server.url,
270 path,
576ad67a
JM
271 fields: newUpdateParams,
272 token: server.accessToken,
2d53be02 273 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
576ad67a
JM
274 })
275 })
276
277 it('Should fail if email disabled and signup requires email verification', async function () {
7c3b7976 278 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
576ad67a
JM
279 const newUpdateParams = immutableAssign(updateParams, {
280 signup: {
281 enabled: true,
282 limit: 5,
283 requiresEmailVerification: true
284 }
285 })
286
287 await makePutBodyRequest({
288 url: server.url,
289 path,
fd206f0b
C
290 fields: newUpdateParams,
291 token: server.accessToken,
2d53be02 292 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
fd206f0b
C
293 })
294 })
295
d7a25329
C
296 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
297 const newUpdateParams = immutableAssign(updateParams, {
298 transcoding: {
299 hls: {
300 enabled: false
301 },
302 webtorrent: {
303 enabled: false
304 }
305 }
306 })
307
308 await makePutBodyRequest({
309 url: server.url,
310 path,
311 fields: newUpdateParams,
312 token: server.accessToken,
2d53be02 313 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
d7a25329
C
314 })
315 })
316
fd206f0b
C
317 it('Should success with the correct parameters', async function () {
318 await makePutBodyRequest({
319 url: server.url,
320 path,
321 fields: updateParams,
322 token: server.accessToken,
2d53be02 323 statusCodeExpected: HttpStatusCode.OK_200
fd206f0b
C
324 })
325 })
326 })
327
328 describe('When deleting the configuration', function () {
329 it('Should fail without token', async function () {
330 await makeDeleteRequest({
331 url: server.url,
332 path,
2d53be02 333 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
fd206f0b
C
334 })
335 })
336
337 it('Should fail if the user is not an administrator', async function () {
338 await makeDeleteRequest({
339 url: server.url,
340 path,
341 token: userAccessToken,
2d53be02 342 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
fd206f0b
C
343 })
344 })
345 })
346
7c3b7976
C
347 after(async function () {
348 await cleanupTests([ server ])
fd206f0b
C
349 })
350})