1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { omit } from 'lodash'
5 import { HttpStatusCode } from '@shared/core-utils'
14 setAccessTokensToServers,
16 } from '@shared/extra-utils'
17 import { CustomConfig } from '@shared/models'
19 describe('Test config API validators', function () {
20 const path = '/api/v1/config/custom'
21 let server: ServerInfo
22 let userAccessToken: string
23 const updateParams: CustomConfig = {
25 name: 'PeerTube updated',
26 shortDescription: 'my short description',
27 description: 'my super description',
28 terms: 'my super terms',
29 codeOfConduct: 'my super coc',
31 creationReason: 'my super reason',
32 moderationInformation: 'my super moderation information',
33 administrator: 'Kuja',
34 maintenanceLifetime: 'forever',
35 businessModel: 'my super business model',
36 hardwareInformation: '2vCore 3GB RAM',
38 languages: [ 'en', 'es' ],
42 defaultNSFWPolicy: 'blur',
44 defaultClientRoute: '/videos/recently-added',
47 javascript: 'alert("coucou")',
48 css: 'body { background-color: red; }'
56 username: '@MySuperUsername',
74 requiresEmailVerification: false,
78 email: 'superadmin1@example.com'
85 videoQuotaDaily: 318742
89 allowAdditionalExtensions: true,
90 allowAudioFiles: true,
93 profile: 'vod_profile',
116 maxInstanceLives: -1,
122 profile: 'live_profile',
148 enabled: [ 'best', 'hot', 'most-viewed', 'most-liked' ],
149 default: 'most-viewed'
173 indexUrl: 'https://index.example.com'
180 message: 'super message',
190 url: 'https://search.joinpeertube.org',
191 disableLocalSearch: true,
192 isDefaultSearch: true
197 // ---------------------------------------------------------------
199 before(async function () {
202 server = await flushAndRunServer(1)
204 await setAccessTokensToServers([ server ])
210 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
211 userAccessToken = await userLogin(server, user)
214 describe('When getting the configuration', function () {
215 it('Should fail without token', async function () {
216 await makeGetRequest({
219 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
223 it('Should fail if the user is not an administrator', async function () {
224 await makeGetRequest({
227 token: userAccessToken,
228 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
233 describe('When updating the configuration', function () {
234 it('Should fail without token', async function () {
235 await makePutBodyRequest({
238 fields: updateParams,
239 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
243 it('Should fail if the user is not an administrator', async function () {
244 await makePutBodyRequest({
247 fields: updateParams,
248 token: userAccessToken,
249 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
253 it('Should fail if it misses a key', async function () {
254 const newUpdateParams = omit(updateParams, 'admin.email')
256 await makePutBodyRequest({
259 fields: newUpdateParams,
260 token: server.accessToken,
261 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
265 it('Should fail with a bad default NSFW policy', async function () {
266 const newUpdateParams = {
270 defaultNSFWPolicy: 'hello'
274 await makePutBodyRequest({
277 fields: newUpdateParams,
278 token: server.accessToken,
279 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
283 it('Should fail if email disabled and signup requires email verification', async function () {
284 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
285 const newUpdateParams = {
291 requiresEmailVerification: true
295 await makePutBodyRequest({
298 fields: newUpdateParams,
299 token: server.accessToken,
300 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
304 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
305 const newUpdateParams = {
318 await makePutBodyRequest({
321 fields: newUpdateParams,
322 token: server.accessToken,
323 statusCodeExpected: HttpStatusCode.BAD_REQUEST_400
327 it('Should success with the correct parameters', async function () {
328 await makePutBodyRequest({
331 fields: updateParams,
332 token: server.accessToken,
333 statusCodeExpected: HttpStatusCode.OK_200
338 describe('When deleting the configuration', function () {
339 it('Should fail without token', async function () {
340 await makeDeleteRequest({
343 statusCodeExpected: HttpStatusCode.UNAUTHORIZED_401
347 it('Should fail if the user is not an administrator', async function () {
348 await makeDeleteRequest({
351 token: userAccessToken,
352 statusCodeExpected: HttpStatusCode.FORBIDDEN_403
357 after(async function () {
358 await cleanupTests([ server ])