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; }'
32 username: '@MySuperUsername',
47 requiresEmailVerification: false
50 email: 'superadmin1@example.com'
57 videoQuotaDaily: 318742
61 allowAdditionalExtensions: true,
62 allowAudioFiles: true,
101 // ---------------------------------------------------------------
103 before(async function () {
106 server = await flushAndRunServer(1)
108 await setAccessTokensToServers([ server ])
114 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
115 userAccessToken = await userLogin(server, user)
118 describe('When getting the configuration', function () {
119 it('Should fail without token', async function () {
120 await makeGetRequest({
123 statusCodeExpected: 401
127 it('Should fail if the user is not an administrator', async function () {
128 await makeGetRequest({
131 token: userAccessToken,
132 statusCodeExpected: 403
137 describe('When updating the configuration', function () {
138 it('Should fail without token', async function () {
139 await makePutBodyRequest({
142 fields: updateParams,
143 statusCodeExpected: 401
147 it('Should fail if the user is not an administrator', async function () {
148 await makePutBodyRequest({
151 fields: updateParams,
152 token: userAccessToken,
153 statusCodeExpected: 403
157 it('Should fail if it misses a key', async function () {
158 const newUpdateParams = omit(updateParams, 'admin.email')
160 await makePutBodyRequest({
163 fields: newUpdateParams,
164 token: server.accessToken,
165 statusCodeExpected: 400
169 it('Should fail with a bad default NSFW policy', async function () {
170 const newUpdateParams = immutableAssign(updateParams, {
172 defaultNSFWPolicy: 'hello'
176 await makePutBodyRequest({
179 fields: newUpdateParams,
180 token: server.accessToken,
181 statusCodeExpected: 400
185 it('Should fail if email disabled and signup requires email verification', async function () {
186 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
187 const newUpdateParams = immutableAssign(updateParams, {
191 requiresEmailVerification: true
195 await makePutBodyRequest({
198 fields: newUpdateParams,
199 token: server.accessToken,
200 statusCodeExpected: 400
204 it('Should success with the correct parameters', async function () {
205 await makePutBodyRequest({
208 fields: updateParams,
209 token: server.accessToken,
210 statusCodeExpected: 200
215 describe('When deleting the configuration', function () {
216 it('Should fail without token', async function () {
217 await makeDeleteRequest({
220 statusCodeExpected: 401
224 it('Should fail if the user is not an administrator', async function () {
225 await makeDeleteRequest({
228 token: userAccessToken,
229 statusCodeExpected: 403
234 after(async function () {
235 await cleanupTests([ server ])