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,
100 // ---------------------------------------------------------------
102 before(async function () {
105 server = await flushAndRunServer(1)
107 await setAccessTokensToServers([ server ])
113 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
114 userAccessToken = await userLogin(server, user)
117 describe('When getting the configuration', function () {
118 it('Should fail without token', async function () {
119 await makeGetRequest({
122 statusCodeExpected: 401
126 it('Should fail if the user is not an administrator', async function () {
127 await makeGetRequest({
130 token: userAccessToken,
131 statusCodeExpected: 403
136 describe('When updating the configuration', function () {
137 it('Should fail without token', async function () {
138 await makePutBodyRequest({
141 fields: updateParams,
142 statusCodeExpected: 401
146 it('Should fail if the user is not an administrator', async function () {
147 await makePutBodyRequest({
150 fields: updateParams,
151 token: userAccessToken,
152 statusCodeExpected: 403
156 it('Should fail if it misses a key', async function () {
157 const newUpdateParams = omit(updateParams, 'admin.email')
159 await makePutBodyRequest({
162 fields: newUpdateParams,
163 token: server.accessToken,
164 statusCodeExpected: 400
168 it('Should fail with a bad default NSFW policy', async function () {
169 const newUpdateParams = immutableAssign(updateParams, {
171 defaultNSFWPolicy: 'hello'
175 await makePutBodyRequest({
178 fields: newUpdateParams,
179 token: server.accessToken,
180 statusCodeExpected: 400
184 it('Should fail if email disabled and signup requires email verification', async function () {
185 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
186 const newUpdateParams = immutableAssign(updateParams, {
190 requiresEmailVerification: true
194 await makePutBodyRequest({
197 fields: newUpdateParams,
198 token: server.accessToken,
199 statusCodeExpected: 400
203 it('Should success with the correct parameters', async function () {
204 await makePutBodyRequest({
207 fields: updateParams,
208 token: server.accessToken,
209 statusCodeExpected: 200
214 describe('When deleting the configuration', function () {
215 it('Should fail without token', async function () {
216 await makeDeleteRequest({
219 statusCodeExpected: 401
223 it('Should fail if the user is not an administrator', async function () {
224 await makeDeleteRequest({
227 token: userAccessToken,
228 statusCodeExpected: 403
233 after(async function () {
234 await cleanupTests([ server ])