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,
85 // ---------------------------------------------------------------
87 before(async function () {
91 server = await runServer(1)
93 await setAccessTokensToServers([ server ])
99 await createUser(server.url, server.accessToken, user.username, user.password)
100 userAccessToken = await userLogin(server, user)
103 describe('When getting the configuration', function () {
104 it('Should fail without token', async function () {
105 await makeGetRequest({
108 statusCodeExpected: 401
112 it('Should fail if the user is not an administrator', async function () {
113 await makeGetRequest({
116 token: userAccessToken,
117 statusCodeExpected: 403
122 describe('When updating the configuration', function () {
123 it('Should fail without token', async function () {
124 await makePutBodyRequest({
127 fields: updateParams,
128 statusCodeExpected: 401
132 it('Should fail if the user is not an administrator', async function () {
133 await makePutBodyRequest({
136 fields: updateParams,
137 token: userAccessToken,
138 statusCodeExpected: 403
142 it('Should fail if it misses a key', async function () {
143 const newUpdateParams = omit(updateParams, 'admin.email')
145 await makePutBodyRequest({
148 fields: newUpdateParams,
149 token: server.accessToken,
150 statusCodeExpected: 400
154 it('Should fail with a bad default NSFW policy', async function () {
155 const newUpdateParams = immutableAssign(updateParams, {
157 defaultNSFWPolicy: 'hello'
161 await makePutBodyRequest({
164 fields: newUpdateParams,
165 token: server.accessToken,
166 statusCodeExpected: 400
170 it('Should success with the correct parameters', async function () {
171 await makePutBodyRequest({
174 fields: updateParams,
175 token: server.accessToken,
176 statusCodeExpected: 200
181 describe('When deleting the configuration', function () {
182 it('Should fail without token', async function () {
183 await makeDeleteRequest({
186 statusCodeExpected: 401
190 it('Should fail if the user is not an administrator', async function () {
191 await makeDeleteRequest({
194 token: userAccessToken,
195 statusCodeExpected: 403
200 after(async function () {
201 killallServers([ server ])
203 // Keep the logs if the test failed