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,
86 // ---------------------------------------------------------------
88 before(async function () {
92 server = await runServer(1)
94 await setAccessTokensToServers([ server ])
100 await createUser(server.url, server.accessToken, user.username, user.password)
101 userAccessToken = await userLogin(server, user)
104 describe('When getting the configuration', function () {
105 it('Should fail without token', async function () {
106 await makeGetRequest({
109 statusCodeExpected: 401
113 it('Should fail if the user is not an administrator', async function () {
114 await makeGetRequest({
117 token: userAccessToken,
118 statusCodeExpected: 403
123 describe('When updating the configuration', function () {
124 it('Should fail without token', async function () {
125 await makePutBodyRequest({
128 fields: updateParams,
129 statusCodeExpected: 401
133 it('Should fail if the user is not an administrator', async function () {
134 await makePutBodyRequest({
137 fields: updateParams,
138 token: userAccessToken,
139 statusCodeExpected: 403
143 it('Should fail if it misses a key', async function () {
144 const newUpdateParams = omit(updateParams, 'admin.email')
146 await makePutBodyRequest({
149 fields: newUpdateParams,
150 token: server.accessToken,
151 statusCodeExpected: 400
155 it('Should fail with a bad default NSFW policy', async function () {
156 const newUpdateParams = immutableAssign(updateParams, {
158 defaultNSFWPolicy: 'hello'
162 await makePutBodyRequest({
165 fields: newUpdateParams,
166 token: server.accessToken,
167 statusCodeExpected: 400
171 it('Should fail if email disabled and signup requires email verification', async function () {
172 // opposite scenario - succcess when enable enabled - covered via tests/api/users/user-verification.ts
173 const newUpdateParams = immutableAssign(updateParams, {
177 requiresEmailVerification: true
181 await makePutBodyRequest({
184 fields: newUpdateParams,
185 token: server.accessToken,
186 statusCodeExpected: 400
190 it('Should success with the correct parameters', async function () {
191 await makePutBodyRequest({
194 fields: updateParams,
195 token: server.accessToken,
196 statusCodeExpected: 200
201 describe('When deleting the configuration', function () {
202 it('Should fail without token', async function () {
203 await makeDeleteRequest({
206 statusCodeExpected: 401
210 it('Should fail if the user is not an administrator', async function () {
211 await makeDeleteRequest({
214 token: userAccessToken,
215 statusCodeExpected: 403
220 after(async function () {
221 killallServers([ server ])
223 // Keep the logs if the test failed