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,
133 indexUrl: 'https://index.example.com'
140 message: 'super message',
150 url: 'https://search.joinpeertube.org',
151 disableLocalSearch: true,
152 isDefaultSearch: true
157 // ---------------------------------------------------------------
159 before(async function () {
162 server = await flushAndRunServer(1)
164 await setAccessTokensToServers([ server ])
170 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
171 userAccessToken = await userLogin(server, user)
174 describe('When getting the configuration', function () {
175 it('Should fail without token', async function () {
176 await makeGetRequest({
179 statusCodeExpected: 401
183 it('Should fail if the user is not an administrator', async function () {
184 await makeGetRequest({
187 token: userAccessToken,
188 statusCodeExpected: 403
193 describe('When updating the configuration', function () {
194 it('Should fail without token', async function () {
195 await makePutBodyRequest({
198 fields: updateParams,
199 statusCodeExpected: 401
203 it('Should fail if the user is not an administrator', async function () {
204 await makePutBodyRequest({
207 fields: updateParams,
208 token: userAccessToken,
209 statusCodeExpected: 403
213 it('Should fail if it misses a key', async function () {
214 const newUpdateParams = omit(updateParams, 'admin.email')
216 await makePutBodyRequest({
219 fields: newUpdateParams,
220 token: server.accessToken,
221 statusCodeExpected: 400
225 it('Should fail with a bad default NSFW policy', async function () {
226 const newUpdateParams = immutableAssign(updateParams, {
228 defaultNSFWPolicy: 'hello'
232 await makePutBodyRequest({
235 fields: newUpdateParams,
236 token: server.accessToken,
237 statusCodeExpected: 400
241 it('Should fail if email disabled and signup requires email verification', async function () {
242 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
243 const newUpdateParams = immutableAssign(updateParams, {
247 requiresEmailVerification: true
251 await makePutBodyRequest({
254 fields: newUpdateParams,
255 token: server.accessToken,
256 statusCodeExpected: 400
260 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
261 const newUpdateParams = immutableAssign(updateParams, {
272 await makePutBodyRequest({
275 fields: newUpdateParams,
276 token: server.accessToken,
277 statusCodeExpected: 400
281 it('Should success with the correct parameters', async function () {
282 await makePutBodyRequest({
285 fields: updateParams,
286 token: server.accessToken,
287 statusCodeExpected: 200
292 describe('When deleting the configuration', function () {
293 it('Should fail without token', async function () {
294 await makeDeleteRequest({
297 statusCodeExpected: 401
301 it('Should fail if the user is not an administrator', async function () {
302 await makeDeleteRequest({
305 token: userAccessToken,
306 statusCodeExpected: 403
311 after(async function () {
312 await cleanupTests([ server ])