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, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin, immutableAssign
10 } from '../../../../shared/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,
93 // ---------------------------------------------------------------
95 before(async function () {
99 server = await runServer(1)
101 await setAccessTokensToServers([ server ])
107 await createUser(server.url, server.accessToken, user.username, user.password)
108 userAccessToken = await userLogin(server, user)
111 describe('When getting the configuration', function () {
112 it('Should fail without token', async function () {
113 await makeGetRequest({
116 statusCodeExpected: 401
120 it('Should fail if the user is not an administrator', async function () {
121 await makeGetRequest({
124 token: userAccessToken,
125 statusCodeExpected: 403
130 describe('When updating the configuration', function () {
131 it('Should fail without token', async function () {
132 await makePutBodyRequest({
135 fields: updateParams,
136 statusCodeExpected: 401
140 it('Should fail if the user is not an administrator', async function () {
141 await makePutBodyRequest({
144 fields: updateParams,
145 token: userAccessToken,
146 statusCodeExpected: 403
150 it('Should fail if it misses a key', async function () {
151 const newUpdateParams = omit(updateParams, 'admin.email')
153 await makePutBodyRequest({
156 fields: newUpdateParams,
157 token: server.accessToken,
158 statusCodeExpected: 400
162 it('Should fail with a bad default NSFW policy', async function () {
163 const newUpdateParams = immutableAssign(updateParams, {
165 defaultNSFWPolicy: 'hello'
169 await makePutBodyRequest({
172 fields: newUpdateParams,
173 token: server.accessToken,
174 statusCodeExpected: 400
178 it('Should fail if email disabled and signup requires email verification', async function () {
179 // opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts
180 const newUpdateParams = immutableAssign(updateParams, {
184 requiresEmailVerification: true
188 await makePutBodyRequest({
191 fields: newUpdateParams,
192 token: server.accessToken,
193 statusCodeExpected: 400
197 it('Should success with the correct parameters', async function () {
198 await makePutBodyRequest({
201 fields: updateParams,
202 token: server.accessToken,
203 statusCodeExpected: 200
208 describe('When deleting the configuration', function () {
209 it('Should fail without token', async function () {
210 await makeDeleteRequest({
213 statusCodeExpected: 401
217 it('Should fail if the user is not an administrator', async function () {
218 await makeDeleteRequest({
221 token: userAccessToken,
222 statusCodeExpected: 403
227 after(async function () {
228 killallServers([ server ])
230 // Keep the logs if the test failed