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'
73 // ---------------------------------------------------------------
75 before(async function () {
79 server = await runServer(1)
81 await setAccessTokensToServers([ server ])
87 await createUser(server.url, server.accessToken, user.username, user.password)
88 userAccessToken = await userLogin(server, user)
91 describe('When getting the configuration', function () {
92 it('Should fail without token', async function () {
93 await makeGetRequest({
96 statusCodeExpected: 401
100 it('Should fail if the user is not an administrator', async function () {
101 await makeGetRequest({
104 token: userAccessToken,
105 statusCodeExpected: 403
110 describe('When updating the configuration', function () {
111 it('Should fail without token', async function () {
112 await makePutBodyRequest({
115 fields: updateParams,
116 statusCodeExpected: 401
120 it('Should fail if the user is not an administrator', async function () {
121 await makePutBodyRequest({
124 fields: updateParams,
125 token: userAccessToken,
126 statusCodeExpected: 403
130 it('Should fail if it misses a key', async function () {
131 const newUpdateParams = omit(updateParams, 'admin.email')
133 await makePutBodyRequest({
136 fields: newUpdateParams,
137 token: server.accessToken,
138 statusCodeExpected: 400
142 it('Should fail with a bad default NSFW policy', async function () {
143 const newUpdateParams = immutableAssign(updateParams, {
145 defaultNSFWPolicy: 'hello'
149 await makePutBodyRequest({
152 fields: newUpdateParams,
153 token: server.accessToken,
154 statusCodeExpected: 400
158 it('Should success with the correct parameters', async function () {
159 await makePutBodyRequest({
162 fields: updateParams,
163 token: server.accessToken,
164 statusCodeExpected: 200
169 describe('When deleting the configuration', function () {
170 it('Should fail without token', async function () {
171 await makeDeleteRequest({
174 statusCodeExpected: 401
178 it('Should fail if the user is not an administrator', async function () {
179 await makeDeleteRequest({
182 token: userAccessToken,
183 statusCodeExpected: 403
188 after(async function () {
189 killallServers([ server ])
191 // Keep the logs if the test failed