1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
12 setAccessTokensToServers
13 } from '@shared/server-commands'
14 import { CustomConfig, HttpStatusCode } from '@shared/models'
16 describe('Test config API validators', function () {
17 const path = '/api/v1/config/custom'
18 let server: PeerTubeServer
19 let userAccessToken: string
20 const updateParams: CustomConfig = {
22 name: 'PeerTube updated',
23 shortDescription: 'my short description',
24 description: 'my super description',
25 terms: 'my super terms',
26 codeOfConduct: 'my super coc',
28 creationReason: 'my super reason',
29 moderationInformation: 'my super moderation information',
30 administrator: 'Kuja',
31 maintenanceLifetime: 'forever',
32 businessModel: 'my super business model',
33 hardwareInformation: '2vCore 3GB RAM',
35 languages: [ 'en', 'es' ],
39 defaultNSFWPolicy: 'blur',
41 defaultClientRoute: '/videos/recently-added',
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
53 username: '@MySuperUsername',
60 preferAuthorDisplayName: false
65 redirectOnSingleExternalAuth: false
83 requiresEmailVerification: false,
87 email: 'superadmin1@example.com'
94 videoQuotaDaily: 318742
101 allowAdditionalExtensions: true,
102 allowAudioFiles: true,
105 profile: 'vod_profile',
117 alwaysTranscodeOriginalResolution: false,
133 maxInstanceLives: -1,
139 profile: 'live_profile',
150 alwaysTranscodeOriginalResolution: false
170 enabled: [ 'hot', 'most-viewed', 'most-liked' ],
171 default: 'most-viewed'
195 indexUrl: 'https://index.example.com'
202 message: 'super message',
212 url: 'https://search.joinpeertube.org',
213 disableLocalSearch: true,
214 isDefaultSearch: true
219 // ---------------------------------------------------------------
221 before(async function () {
224 server = await createSingleServer(1)
226 await setAccessTokensToServers([ server ])
232 await server.users.create({ username: user.username, password: user.password })
233 userAccessToken = await server.login.getAccessToken(user)
236 describe('When getting the configuration', function () {
237 it('Should fail without token', async function () {
238 await makeGetRequest({
241 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
245 it('Should fail if the user is not an administrator', async function () {
246 await makeGetRequest({
249 token: userAccessToken,
250 expectedStatus: HttpStatusCode.FORBIDDEN_403
255 describe('When updating the configuration', function () {
256 it('Should fail without token', async function () {
257 await makePutBodyRequest({
260 fields: updateParams,
261 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
265 it('Should fail if the user is not an administrator', async function () {
266 await makePutBodyRequest({
269 fields: updateParams,
270 token: userAccessToken,
271 expectedStatus: HttpStatusCode.FORBIDDEN_403
275 it('Should fail if it misses a key', async function () {
276 const newUpdateParams = omit(updateParams, 'admin.email')
278 await makePutBodyRequest({
281 fields: newUpdateParams,
282 token: server.accessToken,
283 expectedStatus: HttpStatusCode.BAD_REQUEST_400
287 it('Should fail with a bad default NSFW policy', async function () {
288 const newUpdateParams = {
292 defaultNSFWPolicy: 'hello'
296 await makePutBodyRequest({
299 fields: newUpdateParams,
300 token: server.accessToken,
301 expectedStatus: HttpStatusCode.BAD_REQUEST_400
305 it('Should fail if email disabled and signup requires email verification', async function () {
306 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
307 const newUpdateParams = {
313 requiresEmailVerification: true
317 await makePutBodyRequest({
320 fields: newUpdateParams,
321 token: server.accessToken,
322 expectedStatus: HttpStatusCode.BAD_REQUEST_400
326 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
327 const newUpdateParams = {
340 await makePutBodyRequest({
343 fields: newUpdateParams,
344 token: server.accessToken,
345 expectedStatus: HttpStatusCode.BAD_REQUEST_400
349 it('Should success with the correct parameters', async function () {
350 await makePutBodyRequest({
353 fields: updateParams,
354 token: server.accessToken,
355 expectedStatus: HttpStatusCode.OK_200
360 describe('When deleting the configuration', function () {
361 it('Should fail without token', async function () {
362 await makeDeleteRequest({
365 expectedStatus: HttpStatusCode.UNAUTHORIZED_401
369 it('Should fail if the user is not an administrator', async function () {
370 await makeDeleteRequest({
373 token: userAccessToken,
374 expectedStatus: HttpStatusCode.FORBIDDEN_403
379 after(async function () {
380 await cleanupTests([ server ])