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'
52 videoQuotaDaily: 318742
77 // ---------------------------------------------------------------
79 before(async function () {
83 server = await runServer(1)
85 await setAccessTokensToServers([ server ])
91 await createUser(server.url, server.accessToken, user.username, user.password)
92 userAccessToken = await userLogin(server, user)
95 describe('When getting the configuration', function () {
96 it('Should fail without token', async function () {
97 await makeGetRequest({
100 statusCodeExpected: 401
104 it('Should fail if the user is not an administrator', async function () {
105 await makeGetRequest({
108 token: userAccessToken,
109 statusCodeExpected: 403
114 describe('When updating the configuration', function () {
115 it('Should fail without token', async function () {
116 await makePutBodyRequest({
119 fields: updateParams,
120 statusCodeExpected: 401
124 it('Should fail if the user is not an administrator', async function () {
125 await makePutBodyRequest({
128 fields: updateParams,
129 token: userAccessToken,
130 statusCodeExpected: 403
134 it('Should fail if it misses a key', async function () {
135 const newUpdateParams = omit(updateParams, 'admin.email')
137 await makePutBodyRequest({
140 fields: newUpdateParams,
141 token: server.accessToken,
142 statusCodeExpected: 400
146 it('Should fail with a bad default NSFW policy', async function () {
147 const newUpdateParams = immutableAssign(updateParams, {
149 defaultNSFWPolicy: 'hello'
153 await makePutBodyRequest({
156 fields: newUpdateParams,
157 token: server.accessToken,
158 statusCodeExpected: 400
162 it('Should success with the correct parameters', async function () {
163 await makePutBodyRequest({
166 fields: updateParams,
167 token: server.accessToken,
168 statusCodeExpected: 200
173 describe('When deleting the configuration', function () {
174 it('Should fail without token', async function () {
175 await makeDeleteRequest({
178 statusCodeExpected: 401
182 it('Should fail if the user is not an administrator', async function () {
183 await makeDeleteRequest({
186 token: userAccessToken,
187 statusCodeExpected: 403
192 after(async function () {
193 killallServers([ server ])
195 // Keep the logs if the test failed