1 /* tslint:disable:no-unused-expression */
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',
38 languages: [ 'en', 'es' ],
42 defaultClientRoute: '/videos/recently-added',
43 defaultNSFWPolicy: 'blur',
45 javascript: 'alert("coucou")',
46 css: 'body { background-color: red; }'
54 username: '@MySuperUsername',
69 requiresEmailVerification: false
72 email: 'superadmin1@example.com'
79 videoQuotaDaily: 318742
83 allowAdditionalExtensions: true,
84 allowAudioFiles: true,
128 indexUrl: 'https://index.example.com'
134 // ---------------------------------------------------------------
136 before(async function () {
139 server = await flushAndRunServer(1)
141 await setAccessTokensToServers([ server ])
147 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
148 userAccessToken = await userLogin(server, user)
151 describe('When getting the configuration', function () {
152 it('Should fail without token', async function () {
153 await makeGetRequest({
156 statusCodeExpected: 401
160 it('Should fail if the user is not an administrator', async function () {
161 await makeGetRequest({
164 token: userAccessToken,
165 statusCodeExpected: 403
170 describe('When updating the configuration', function () {
171 it('Should fail without token', async function () {
172 await makePutBodyRequest({
175 fields: updateParams,
176 statusCodeExpected: 401
180 it('Should fail if the user is not an administrator', async function () {
181 await makePutBodyRequest({
184 fields: updateParams,
185 token: userAccessToken,
186 statusCodeExpected: 403
190 it('Should fail if it misses a key', async function () {
191 const newUpdateParams = omit(updateParams, 'admin.email')
193 await makePutBodyRequest({
196 fields: newUpdateParams,
197 token: server.accessToken,
198 statusCodeExpected: 400
202 it('Should fail with a bad default NSFW policy', async function () {
203 const newUpdateParams = immutableAssign(updateParams, {
205 defaultNSFWPolicy: 'hello'
209 await makePutBodyRequest({
212 fields: newUpdateParams,
213 token: server.accessToken,
214 statusCodeExpected: 400
218 it('Should fail if email disabled and signup requires email verification', async function () {
219 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
220 const newUpdateParams = immutableAssign(updateParams, {
224 requiresEmailVerification: true
228 await makePutBodyRequest({
231 fields: newUpdateParams,
232 token: server.accessToken,
233 statusCodeExpected: 400
237 it('Should success with the correct parameters', async function () {
238 await makePutBodyRequest({
241 fields: updateParams,
242 token: server.accessToken,
243 statusCodeExpected: 200
248 describe('When deleting the configuration', function () {
249 it('Should fail without token', async function () {
250 await makeDeleteRequest({
253 statusCodeExpected: 401
257 it('Should fail if the user is not an administrator', async function () {
258 await makeDeleteRequest({
261 token: userAccessToken,
262 statusCodeExpected: 403
267 after(async function () {
268 await cleanupTests([ server ])