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 moderationInformation: 'my super moderation information',
33 administrator: 'Kuja',
34 maintenanceLifetime: 'forever',
35 businessModel: 'my super business model',
37 languages: [ 'en', 'es' ],
41 defaultClientRoute: '/videos/recently-added',
42 defaultNSFWPolicy: 'blur',
44 javascript: 'alert("coucou")',
45 css: 'body { background-color: red; }'
53 username: '@MySuperUsername',
68 requiresEmailVerification: false
71 email: 'superadmin1@example.com'
78 videoQuotaDaily: 318742
82 allowAdditionalExtensions: true,
83 allowAudioFiles: true,
127 indexUrl: 'https://index.example.com'
133 // ---------------------------------------------------------------
135 before(async function () {
138 server = await flushAndRunServer(1)
140 await setAccessTokensToServers([ server ])
146 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
147 userAccessToken = await userLogin(server, user)
150 describe('When getting the configuration', function () {
151 it('Should fail without token', async function () {
152 await makeGetRequest({
155 statusCodeExpected: 401
159 it('Should fail if the user is not an administrator', async function () {
160 await makeGetRequest({
163 token: userAccessToken,
164 statusCodeExpected: 403
169 describe('When updating the configuration', function () {
170 it('Should fail without token', async function () {
171 await makePutBodyRequest({
174 fields: updateParams,
175 statusCodeExpected: 401
179 it('Should fail if the user is not an administrator', async function () {
180 await makePutBodyRequest({
183 fields: updateParams,
184 token: userAccessToken,
185 statusCodeExpected: 403
189 it('Should fail if it misses a key', async function () {
190 const newUpdateParams = omit(updateParams, 'admin.email')
192 await makePutBodyRequest({
195 fields: newUpdateParams,
196 token: server.accessToken,
197 statusCodeExpected: 400
201 it('Should fail with a bad default NSFW policy', async function () {
202 const newUpdateParams = immutableAssign(updateParams, {
204 defaultNSFWPolicy: 'hello'
208 await makePutBodyRequest({
211 fields: newUpdateParams,
212 token: server.accessToken,
213 statusCodeExpected: 400
217 it('Should fail if email disabled and signup requires email verification', async function () {
218 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
219 const newUpdateParams = immutableAssign(updateParams, {
223 requiresEmailVerification: true
227 await makePutBodyRequest({
230 fields: newUpdateParams,
231 token: server.accessToken,
232 statusCodeExpected: 400
236 it('Should success with the correct parameters', async function () {
237 await makePutBodyRequest({
240 fields: updateParams,
241 token: server.accessToken,
242 statusCodeExpected: 200
247 describe('When deleting the configuration', function () {
248 it('Should fail without token', async function () {
249 await makeDeleteRequest({
252 statusCodeExpected: 401
256 it('Should fail if the user is not an administrator', async function () {
257 await makeDeleteRequest({
260 token: userAccessToken,
261 statusCodeExpected: 403
266 after(async function () {
267 await cleanupTests([ server ])