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',
31 defaultClientRoute: '/videos/recently-added',
32 defaultNSFWPolicy: 'blur',
34 javascript: 'alert("coucou")',
35 css: 'body { background-color: red; }'
43 username: '@MySuperUsername',
58 requiresEmailVerification: false
61 email: 'superadmin1@example.com'
68 videoQuotaDaily: 318742
72 allowAdditionalExtensions: true,
73 allowAudioFiles: true,
117 indexUrl: 'https://index.example.com'
123 // ---------------------------------------------------------------
125 before(async function () {
128 server = await flushAndRunServer(1)
130 await setAccessTokensToServers([ server ])
136 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
137 userAccessToken = await userLogin(server, user)
140 describe('When getting the configuration', function () {
141 it('Should fail without token', async function () {
142 await makeGetRequest({
145 statusCodeExpected: 401
149 it('Should fail if the user is not an administrator', async function () {
150 await makeGetRequest({
153 token: userAccessToken,
154 statusCodeExpected: 403
159 describe('When updating the configuration', function () {
160 it('Should fail without token', async function () {
161 await makePutBodyRequest({
164 fields: updateParams,
165 statusCodeExpected: 401
169 it('Should fail if the user is not an administrator', async function () {
170 await makePutBodyRequest({
173 fields: updateParams,
174 token: userAccessToken,
175 statusCodeExpected: 403
179 it('Should fail if it misses a key', async function () {
180 const newUpdateParams = omit(updateParams, 'admin.email')
182 await makePutBodyRequest({
185 fields: newUpdateParams,
186 token: server.accessToken,
187 statusCodeExpected: 400
191 it('Should fail with a bad default NSFW policy', async function () {
192 const newUpdateParams = immutableAssign(updateParams, {
194 defaultNSFWPolicy: 'hello'
198 await makePutBodyRequest({
201 fields: newUpdateParams,
202 token: server.accessToken,
203 statusCodeExpected: 400
207 it('Should fail if email disabled and signup requires email verification', async function () {
208 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
209 const newUpdateParams = immutableAssign(updateParams, {
213 requiresEmailVerification: true
217 await makePutBodyRequest({
220 fields: newUpdateParams,
221 token: server.accessToken,
222 statusCodeExpected: 400
226 it('Should success with the correct parameters', async function () {
227 await makePutBodyRequest({
230 fields: updateParams,
231 token: server.accessToken,
232 statusCodeExpected: 200
237 describe('When deleting the configuration', function () {
238 it('Should fail without token', async function () {
239 await makeDeleteRequest({
242 statusCodeExpected: 401
246 it('Should fail if the user is not an administrator', async function () {
247 await makeDeleteRequest({
250 token: userAccessToken,
251 statusCodeExpected: 403
256 after(async function () {
257 await cleanupTests([ server ])