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
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',
48 email: 'superadmin1@example.com'
76 // ---------------------------------------------------------------
78 before(async function () {
82 server = await runServer(1)
84 await setAccessTokensToServers([ server ])
90 await createUser(server.url, server.accessToken, user.username, user.password)
91 userAccessToken = await userLogin(server, user)
94 describe('When getting the configuration', function () {
95 it('Should fail without token', async function () {
96 await makeGetRequest({
99 statusCodeExpected: 401
103 it('Should fail if the user is not an administrator', async function () {
104 await makeGetRequest({
107 token: userAccessToken,
108 statusCodeExpected: 403
113 describe('When updating the configuration', function () {
114 it('Should fail without token', async function () {
115 await makePutBodyRequest({
118 fields: updateParams,
119 statusCodeExpected: 401
123 it('Should fail if the user is not an administrator', async function () {
124 await makePutBodyRequest({
127 fields: updateParams,
128 token: userAccessToken,
129 statusCodeExpected: 403
133 it('Should fail if it misses a key', async function () {
134 const newUpdateParams = omit(updateParams, 'admin.email')
136 await makePutBodyRequest({
139 fields: newUpdateParams,
140 token: server.accessToken,
141 statusCodeExpected: 400
145 it('Should fail with a bad default NSFW policy', async function () {
146 const newUpdateParams = immutableAssign(updateParams, {
148 defaultNSFWPolicy: 'hello'
152 await makePutBodyRequest({
155 fields: newUpdateParams,
156 token: server.accessToken,
157 statusCodeExpected: 400
161 it('Should success with the correct parameters', async function () {
162 await makePutBodyRequest({
165 fields: updateParams,
166 token: server.accessToken,
167 statusCodeExpected: 200
172 describe('When deleting the configuration', function () {
173 it('Should fail without token', async function () {
174 await makeDeleteRequest({
177 statusCodeExpected: 401
181 it('Should fail if the user is not an administrator', async function () {
182 await makeDeleteRequest({
185 token: userAccessToken,
186 statusCodeExpected: 403
191 after(async function () {
192 killallServers([ server ])
194 // Keep the logs if the test failed