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,
149 indexUrl: 'https://index.example.com'
156 message: 'super message',
166 url: 'https://search.joinpeertube.org',
167 disableLocalSearch: true,
168 isDefaultSearch: true
173 // ---------------------------------------------------------------
175 before(async function () {
178 server = await flushAndRunServer(1)
180 await setAccessTokensToServers([ server ])
186 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
187 userAccessToken = await userLogin(server, user)
190 describe('When getting the configuration', function () {
191 it('Should fail without token', async function () {
192 await makeGetRequest({
195 statusCodeExpected: 401
199 it('Should fail if the user is not an administrator', async function () {
200 await makeGetRequest({
203 token: userAccessToken,
204 statusCodeExpected: 403
209 describe('When updating the configuration', function () {
210 it('Should fail without token', async function () {
211 await makePutBodyRequest({
214 fields: updateParams,
215 statusCodeExpected: 401
219 it('Should fail if the user is not an administrator', async function () {
220 await makePutBodyRequest({
223 fields: updateParams,
224 token: userAccessToken,
225 statusCodeExpected: 403
229 it('Should fail if it misses a key', async function () {
230 const newUpdateParams = omit(updateParams, 'admin.email')
232 await makePutBodyRequest({
235 fields: newUpdateParams,
236 token: server.accessToken,
237 statusCodeExpected: 400
241 it('Should fail with a bad default NSFW policy', async function () {
242 const newUpdateParams = immutableAssign(updateParams, {
244 defaultNSFWPolicy: 'hello'
248 await makePutBodyRequest({
251 fields: newUpdateParams,
252 token: server.accessToken,
253 statusCodeExpected: 400
257 it('Should fail if email disabled and signup requires email verification', async function () {
258 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
259 const newUpdateParams = immutableAssign(updateParams, {
263 requiresEmailVerification: true
267 await makePutBodyRequest({
270 fields: newUpdateParams,
271 token: server.accessToken,
272 statusCodeExpected: 400
276 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
277 const newUpdateParams = immutableAssign(updateParams, {
288 await makePutBodyRequest({
291 fields: newUpdateParams,
292 token: server.accessToken,
293 statusCodeExpected: 400
297 it('Should success with the correct parameters', async function () {
298 await makePutBodyRequest({
301 fields: updateParams,
302 token: server.accessToken,
303 statusCodeExpected: 200
308 describe('When deleting the configuration', function () {
309 it('Should fail without token', async function () {
310 await makeDeleteRequest({
313 statusCodeExpected: 401
317 it('Should fail if the user is not an administrator', async function () {
318 await makeDeleteRequest({
321 token: userAccessToken,
322 statusCodeExpected: 403
327 after(async function () {
328 await cleanupTests([ server ])