1 /* tslint:disable:no-unused-expression */
3 import { omit } from 'lodash'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, flushAndRunServer, ServerInfo,
9 setAccessTokensToServers, userLogin, immutableAssign, cleanupTests
10 } from '../../../../shared/extra-utils'
12 describe('Test config API validators', function () {
13 const path = '/api/v1/config/custom'
14 let server: ServerInfo
15 let userAccessToken: string
16 const updateParams: CustomConfig = {
18 name: 'PeerTube updated',
19 shortDescription: 'my short description',
20 description: 'my super description',
21 terms: 'my super terms',
23 defaultClientRoute: '/videos/recently-added',
24 defaultNSFWPolicy: 'blur',
26 javascript: 'alert("coucou")',
27 css: 'body { background-color: red; }'
35 username: '@MySuperUsername',
50 requiresEmailVerification: false
53 email: 'superadmin1@example.com'
60 videoQuotaDaily: 318742
64 allowAdditionalExtensions: true,
65 allowAudioFiles: true,
104 // ---------------------------------------------------------------
106 before(async function () {
109 server = await flushAndRunServer(1)
111 await setAccessTokensToServers([ server ])
117 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
118 userAccessToken = await userLogin(server, user)
121 describe('When getting the configuration', function () {
122 it('Should fail without token', async function () {
123 await makeGetRequest({
126 statusCodeExpected: 401
130 it('Should fail if the user is not an administrator', async function () {
131 await makeGetRequest({
134 token: userAccessToken,
135 statusCodeExpected: 403
140 describe('When updating the configuration', function () {
141 it('Should fail without token', async function () {
142 await makePutBodyRequest({
145 fields: updateParams,
146 statusCodeExpected: 401
150 it('Should fail if the user is not an administrator', async function () {
151 await makePutBodyRequest({
154 fields: updateParams,
155 token: userAccessToken,
156 statusCodeExpected: 403
160 it('Should fail if it misses a key', async function () {
161 const newUpdateParams = omit(updateParams, 'admin.email')
163 await makePutBodyRequest({
166 fields: newUpdateParams,
167 token: server.accessToken,
168 statusCodeExpected: 400
172 it('Should fail with a bad default NSFW policy', async function () {
173 const newUpdateParams = immutableAssign(updateParams, {
175 defaultNSFWPolicy: 'hello'
179 await makePutBodyRequest({
182 fields: newUpdateParams,
183 token: server.accessToken,
184 statusCodeExpected: 400
188 it('Should fail if email disabled and signup requires email verification', async function () {
189 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
190 const newUpdateParams = immutableAssign(updateParams, {
194 requiresEmailVerification: true
198 await makePutBodyRequest({
201 fields: newUpdateParams,
202 token: server.accessToken,
203 statusCodeExpected: 400
207 it('Should success with the correct parameters', async function () {
208 await makePutBodyRequest({
211 fields: updateParams,
212 token: server.accessToken,
213 statusCodeExpected: 200
218 describe('When deleting the configuration', function () {
219 it('Should fail without token', async function () {
220 await makeDeleteRequest({
223 statusCodeExpected: 401
227 it('Should fail if the user is not an administrator', async function () {
228 await makeDeleteRequest({
231 token: userAccessToken,
232 statusCodeExpected: 403
237 after(async function () {
238 await cleanupTests([ server ])