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',
46 requiresEmailVerification: false
49 email: 'superadmin1@example.com'
53 videoQuotaDaily: 318742
78 // ---------------------------------------------------------------
80 before(async function () {
84 server = await runServer(1)
86 await setAccessTokensToServers([ server ])
92 await createUser(server.url, server.accessToken, user.username, user.password)
93 userAccessToken = await userLogin(server, user)
96 describe('When getting the configuration', function () {
97 it('Should fail without token', async function () {
98 await makeGetRequest({
101 statusCodeExpected: 401
105 it('Should fail if the user is not an administrator', async function () {
106 await makeGetRequest({
109 token: userAccessToken,
110 statusCodeExpected: 403
115 describe('When updating the configuration', function () {
116 it('Should fail without token', async function () {
117 await makePutBodyRequest({
120 fields: updateParams,
121 statusCodeExpected: 401
125 it('Should fail if the user is not an administrator', async function () {
126 await makePutBodyRequest({
129 fields: updateParams,
130 token: userAccessToken,
131 statusCodeExpected: 403
135 it('Should fail if it misses a key', async function () {
136 const newUpdateParams = omit(updateParams, 'admin.email')
138 await makePutBodyRequest({
141 fields: newUpdateParams,
142 token: server.accessToken,
143 statusCodeExpected: 400
147 it('Should fail with a bad default NSFW policy', async function () {
148 const newUpdateParams = immutableAssign(updateParams, {
150 defaultNSFWPolicy: 'hello'
154 await makePutBodyRequest({
157 fields: newUpdateParams,
158 token: server.accessToken,
159 statusCodeExpected: 400
163 it('Should success with the correct parameters', async function () {
164 await makePutBodyRequest({
167 fields: updateParams,
168 token: server.accessToken,
169 statusCodeExpected: 200
174 describe('When deleting the configuration', function () {
175 it('Should fail without token', async function () {
176 await makeDeleteRequest({
179 statusCodeExpected: 401
183 it('Should fail if the user is not an administrator', async function () {
184 await makeDeleteRequest({
187 token: userAccessToken,
188 statusCodeExpected: 403
193 after(async function () {
194 killallServers([ server ])
196 // Keep the logs if the test failed