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,
108 maxInstanceLives: -1,
154 indexUrl: 'https://index.example.com'
161 message: 'super message',
171 url: 'https://search.joinpeertube.org',
172 disableLocalSearch: true,
173 isDefaultSearch: true
178 // ---------------------------------------------------------------
180 before(async function () {
183 server = await flushAndRunServer(1)
185 await setAccessTokensToServers([ server ])
191 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
192 userAccessToken = await userLogin(server, user)
195 describe('When getting the configuration', function () {
196 it('Should fail without token', async function () {
197 await makeGetRequest({
200 statusCodeExpected: 401
204 it('Should fail if the user is not an administrator', async function () {
205 await makeGetRequest({
208 token: userAccessToken,
209 statusCodeExpected: 403
214 describe('When updating the configuration', function () {
215 it('Should fail without token', async function () {
216 await makePutBodyRequest({
219 fields: updateParams,
220 statusCodeExpected: 401
224 it('Should fail if the user is not an administrator', async function () {
225 await makePutBodyRequest({
228 fields: updateParams,
229 token: userAccessToken,
230 statusCodeExpected: 403
234 it('Should fail if it misses a key', async function () {
235 const newUpdateParams = omit(updateParams, 'admin.email')
237 await makePutBodyRequest({
240 fields: newUpdateParams,
241 token: server.accessToken,
242 statusCodeExpected: 400
246 it('Should fail with a bad default NSFW policy', async function () {
247 const newUpdateParams = immutableAssign(updateParams, {
249 defaultNSFWPolicy: 'hello'
253 await makePutBodyRequest({
256 fields: newUpdateParams,
257 token: server.accessToken,
258 statusCodeExpected: 400
262 it('Should fail if email disabled and signup requires email verification', async function () {
263 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
264 const newUpdateParams = immutableAssign(updateParams, {
268 requiresEmailVerification: true
272 await makePutBodyRequest({
275 fields: newUpdateParams,
276 token: server.accessToken,
277 statusCodeExpected: 400
281 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
282 const newUpdateParams = immutableAssign(updateParams, {
293 await makePutBodyRequest({
296 fields: newUpdateParams,
297 token: server.accessToken,
298 statusCodeExpected: 400
302 it('Should success with the correct parameters', async function () {
303 await makePutBodyRequest({
306 fields: updateParams,
307 token: server.accessToken,
308 statusCodeExpected: 200
313 describe('When deleting the configuration', function () {
314 it('Should fail without token', async function () {
315 await makeDeleteRequest({
318 statusCodeExpected: 401
322 it('Should fail if the user is not an administrator', async function () {
323 await makeDeleteRequest({
326 token: userAccessToken,
327 statusCodeExpected: 403
332 after(async function () {
333 await cleanupTests([ server ])