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',
22 defaultClientRoute: '/videos/recently-added',
23 defaultNSFWPolicy: 'blur',
25 javascript: 'alert("coucou")',
26 css: 'body { background-color: red; }'
31 username: '@MySuperUsername',
46 requiresEmailVerification: false
49 email: 'superadmin1@example.com'
56 videoQuotaDaily: 318742
60 allowAdditionalExtensions: true,
82 // ---------------------------------------------------------------
84 before(async function () {
88 server = await runServer(1)
90 await setAccessTokensToServers([ server ])
96 await createUser(server.url, server.accessToken, user.username, user.password)
97 userAccessToken = await userLogin(server, user)
100 describe('When getting the configuration', function () {
101 it('Should fail without token', async function () {
102 await makeGetRequest({
105 statusCodeExpected: 401
109 it('Should fail if the user is not an administrator', async function () {
110 await makeGetRequest({
113 token: userAccessToken,
114 statusCodeExpected: 403
119 describe('When updating the configuration', function () {
120 it('Should fail without token', async function () {
121 await makePutBodyRequest({
124 fields: updateParams,
125 statusCodeExpected: 401
129 it('Should fail if the user is not an administrator', async function () {
130 await makePutBodyRequest({
133 fields: updateParams,
134 token: userAccessToken,
135 statusCodeExpected: 403
139 it('Should fail if it misses a key', async function () {
140 const newUpdateParams = omit(updateParams, 'admin.email')
142 await makePutBodyRequest({
145 fields: newUpdateParams,
146 token: server.accessToken,
147 statusCodeExpected: 400
151 it('Should fail with a bad default NSFW policy', async function () {
152 const newUpdateParams = immutableAssign(updateParams, {
154 defaultNSFWPolicy: 'hello'
158 await makePutBodyRequest({
161 fields: newUpdateParams,
162 token: server.accessToken,
163 statusCodeExpected: 400
167 it('Should success with the correct parameters', async function () {
168 await makePutBodyRequest({
171 fields: updateParams,
172 token: server.accessToken,
173 statusCodeExpected: 200
178 describe('When deleting the configuration', function () {
179 it('Should fail without token', async function () {
180 await makeDeleteRequest({
183 statusCodeExpected: 401
187 it('Should fail if the user is not an administrator', async function () {
188 await makeDeleteRequest({
191 token: userAccessToken,
192 statusCodeExpected: 403
197 after(async function () {
198 killallServers([ server ])
200 // Keep the logs if the test failed