1 /* tslint:disable:no-unused-expression */
3 import { omit } from 'lodash'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
16 setAccessTokensToServers,
18 } from '../../../../shared/extra-utils'
20 describe('Test config API validators', function () {
21 const path = '/api/v1/config/custom'
22 let server: ServerInfo
23 let userAccessToken: string
24 const updateParams: CustomConfig = {
26 name: 'PeerTube updated',
27 shortDescription: 'my short description',
28 description: 'my super description',
29 terms: 'my super terms',
30 codeOfConduct: 'my super coc',
32 creationReason: 'my super reason',
33 moderationInformation: 'my super moderation information',
34 administrator: 'Kuja',
35 maintenanceLifetime: 'forever',
36 businessModel: 'my super business model',
37 hardwareInformation: '2vCore 3GB RAM',
39 languages: [ 'en', 'es' ],
43 defaultClientRoute: '/videos/recently-added',
44 defaultNSFWPolicy: 'blur',
46 javascript: 'alert("coucou")',
47 css: 'body { background-color: red; }'
55 username: '@MySuperUsername',
70 requiresEmailVerification: false
73 email: 'superadmin1@example.com'
80 videoQuotaDaily: 318742
84 allowAdditionalExtensions: true,
85 allowAudioFiles: true,
133 indexUrl: 'https://index.example.com'
139 // ---------------------------------------------------------------
141 before(async function () {
144 server = await flushAndRunServer(1)
146 await setAccessTokensToServers([ server ])
152 await createUser({ url: server.url, accessToken: server.accessToken, username: user.username, password: user.password })
153 userAccessToken = await userLogin(server, user)
156 describe('When getting the configuration', function () {
157 it('Should fail without token', async function () {
158 await makeGetRequest({
161 statusCodeExpected: 401
165 it('Should fail if the user is not an administrator', async function () {
166 await makeGetRequest({
169 token: userAccessToken,
170 statusCodeExpected: 403
175 describe('When updating the configuration', function () {
176 it('Should fail without token', async function () {
177 await makePutBodyRequest({
180 fields: updateParams,
181 statusCodeExpected: 401
185 it('Should fail if the user is not an administrator', async function () {
186 await makePutBodyRequest({
189 fields: updateParams,
190 token: userAccessToken,
191 statusCodeExpected: 403
195 it('Should fail if it misses a key', async function () {
196 const newUpdateParams = omit(updateParams, 'admin.email')
198 await makePutBodyRequest({
201 fields: newUpdateParams,
202 token: server.accessToken,
203 statusCodeExpected: 400
207 it('Should fail with a bad default NSFW policy', async function () {
208 const newUpdateParams = immutableAssign(updateParams, {
210 defaultNSFWPolicy: 'hello'
214 await makePutBodyRequest({
217 fields: newUpdateParams,
218 token: server.accessToken,
219 statusCodeExpected: 400
223 it('Should fail if email disabled and signup requires email verification', async function () {
224 // opposite scenario - success when enable enabled - covered via tests/api/users/user-verification.ts
225 const newUpdateParams = immutableAssign(updateParams, {
229 requiresEmailVerification: true
233 await makePutBodyRequest({
236 fields: newUpdateParams,
237 token: server.accessToken,
238 statusCodeExpected: 400
242 it('Should fail with a disabled webtorrent & hls transcoding', async function () {
243 const newUpdateParams = immutableAssign(updateParams, {
254 await makePutBodyRequest({
257 fields: newUpdateParams,
258 token: server.accessToken,
259 statusCodeExpected: 400
263 it('Should success with the correct parameters', async function () {
264 await makePutBodyRequest({
267 fields: updateParams,
268 token: server.accessToken,
269 statusCodeExpected: 200
274 describe('When deleting the configuration', function () {
275 it('Should fail without token', async function () {
276 await makeDeleteRequest({
279 statusCodeExpected: 401
283 it('Should fail if the user is not an administrator', async function () {
284 await makeDeleteRequest({
287 token: userAccessToken,
288 statusCodeExpected: 403
293 after(async function () {
294 await cleanupTests([ server ])