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'
66 // ---------------------------------------------------------------
68 before(async function () {
72 server = await runServer(1)
74 await setAccessTokensToServers([ server ])
80 await createUser(server.url, server.accessToken, user.username, user.password)
81 userAccessToken = await userLogin(server, user)
84 describe('When getting the configuration', function () {
85 it('Should fail without token', async function () {
86 await makeGetRequest({
89 statusCodeExpected: 401
93 it('Should fail if the user is not an administrator', async function () {
94 await makeGetRequest({
97 token: userAccessToken,
98 statusCodeExpected: 403
103 describe('When updating the configuration', function () {
104 it('Should fail without token', async function () {
105 await makePutBodyRequest({
108 fields: updateParams,
109 statusCodeExpected: 401
113 it('Should fail if the user is not an administrator', async function () {
114 await makePutBodyRequest({
117 fields: updateParams,
118 token: userAccessToken,
119 statusCodeExpected: 403
123 it('Should fail if it misses a key', async function () {
124 const newUpdateParams = omit(updateParams, 'admin.email')
126 await makePutBodyRequest({
129 fields: newUpdateParams,
130 token: server.accessToken,
131 statusCodeExpected: 400
135 it('Should fail with a bad default NSFW policy', async function () {
136 const newUpdateParams = immutableAssign(updateParams, {
138 defaultNSFWPolicy: 'hello'
142 await makePutBodyRequest({
145 fields: newUpdateParams,
146 token: server.accessToken,
147 statusCodeExpected: 400
151 it('Should success with the correct parameters', async function () {
152 await makePutBodyRequest({
155 fields: updateParams,
156 token: server.accessToken,
157 statusCodeExpected: 200
162 describe('When deleting the configuration', function () {
163 it('Should fail without token', async function () {
164 await makeDeleteRequest({
167 statusCodeExpected: 401
171 it('Should fail if the user is not an administrator', async function () {
172 await makeDeleteRequest({
175 token: userAccessToken,
176 statusCodeExpected: 403
181 after(async function () {
182 killallServers([ server ])
184 // Keep the logs if the test failed