1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { omit } from 'lodash'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
16 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
20 describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom'
22 let server: ServerInfo
23 let userAccessToken: string
24 const updateParams: CustomConfig = {
26 name: 'PeerTube updated',
27 shortDescription: 'my short description',
28 description: 'my super description',
29 terms: 'my super terms',
30 codeOfConduct: 'my super coc',
32 creationReason: 'my super reason',
33 moderationInformation: 'my super moderation information',
34 administrator: 'Kuja',
35 maintenanceLifetime: 'forever',
36 businessModel: 'my super business model',
37 hardwareInformation: '2vCore 3GB RAM',
39 languages: [ 'en', 'es' ],
43 defaultClientRoute: '/videos/recently-added',
44 defaultNSFWPolicy: 'blur',
46 javascript: 'alert("coucou")',
47 css: 'body { background-color: red; }'
55 username: '@MySuperUsername',
70 requiresEmailVerification: false
73 email: 'superadmin1@example.com'
80 videoQuotaDaily: 318742
84 allowAdditionalExtensions: true,
85 allowAudioFiles: true,
152 indexUrl: 'https://index.example.com'
159 message: 'super message',
169 url: 'https://search.joinpeertube.org',
170 disableLocalSearch: true,
171 isDefaultSearch: true
176 // ---------------------------------------------------------------
178 before(async function () {
181 server = await flushAndRunServer(1)
183 await setAccessTokensToServers([ server ])
189 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
190 userAccessToken = await userLogin(server, user)
193 describe('When getting the configuration', function () {
194 it('Should fail without token', async function () {
195 await makeGetRequest({
198 statusCodeExpected: 401
202 it('Should fail if the user is not an administrator', async function () {
203 await makeGetRequest({
206 token: userAccessToken,
207 statusCodeExpected: 403
212 describe('When updating the configuration', function () {
213 it('Should fail without token', async function () {
214 await makePutBodyRequest({
217 fields: updateParams,
218 statusCodeExpected: 401
222 it('Should fail if the user is not an administrator', async function () {
223 await makePutBodyRequest({
226 fields: updateParams,
227 token: userAccessToken,
228 statusCodeExpected: 403
232 it('Should fail if it misses a key', async function () {
233 const newUpdateParams = omit(updateParams, 'admin.email')
235 await makePutBodyRequest({
238 fields: newUpdateParams,
239 token: server.accessToken,
240 statusCodeExpected: 400
244 it('Should fail with a bad default NSFW policy', async function () {
245 const newUpdateParams = immutableAssign(updateParams, {
247 defaultNSFWPolicy: 'hello'
251 await makePutBodyRequest({
254 fields: newUpdateParams,
255 token: server.accessToken,
256 statusCodeExpected: 400
260 it('Should fail if email disabled and signup requires email verification', async function () {
261 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
262 const newUpdateParams = immutableAssign(updateParams, {
266 requiresEmailVerification: true
270 await makePutBodyRequest({
273 fields: newUpdateParams,
274 token: server.accessToken,
275 statusCodeExpected: 400
279 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
280 const newUpdateParams = immutableAssign(updateParams, {
291 await makePutBodyRequest({
294 fields: newUpdateParams,
295 token: server.accessToken,
296 statusCodeExpected: 400
300 it('Should success with the correct parameters', async function () {
301 await makePutBodyRequest({
304 fields: updateParams,
305 token: server.accessToken,
306 statusCodeExpected: 200
311 describe('When deleting the configuration', function () {
312 it('Should fail without token', async function () {
313 await makeDeleteRequest({
316 statusCodeExpected: 401
320 it('Should fail if the user is not an administrator', async function () {
321 await makeDeleteRequest({
324 token: userAccessToken,
325 statusCodeExpected: 403
330 after(async function () {
331 await cleanupTests([ server ])