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',
45 email: 'superadmin1@example.com'
63 // ---------------------------------------------------------------
65 before(async function () {
69 server = await runServer(1)
71 await setAccessTokensToServers([ server ])
77 await createUser(server.url, server.accessToken, user.username, user.password)
78 userAccessToken = await userLogin(server, user)
81 describe('When getting the configuration', function () {
82 it('Should fail without token', async function () {
83 await makeGetRequest({
86 statusCodeExpected: 401
90 it('Should fail if the user is not an administrator', async function () {
91 await makeGetRequest({
94 token: userAccessToken,
95 statusCodeExpected: 403
100 describe('When updating the configuration', function () {
101 it('Should fail without token', async function () {
102 await makePutBodyRequest({
105 fields: updateParams,
106 statusCodeExpected: 401
110 it('Should fail if the user is not an administrator', async function () {
111 await makePutBodyRequest({
114 fields: updateParams,
115 token: userAccessToken,
116 statusCodeExpected: 403
120 it('Should fail if it misses a key', async function () {
121 const newUpdateParams = omit(updateParams, 'admin.email')
123 await makePutBodyRequest({
126 fields: newUpdateParams,
127 token: server.accessToken,
128 statusCodeExpected: 400
132 it('Should fail with a bad default NSFW policy', async function () {
133 const newUpdateParams = immutableAssign(updateParams, {
135 defaultNSFWPolicy: 'hello'
139 await makePutBodyRequest({
142 fields: newUpdateParams,
143 token: server.accessToken,
144 statusCodeExpected: 400
148 it('Should success with the correct parameters', async function () {
149 await makePutBodyRequest({
152 fields: updateParams,
153 token: server.accessToken,
154 statusCodeExpected: 200
159 describe('When deleting the configuration', function () {
160 it('Should fail without token', async function () {
161 await makeDeleteRequest({
164 statusCodeExpected: 401
168 it('Should fail if the user is not an administrator', async function () {
169 await makeDeleteRequest({
172 token: userAccessToken,
173 statusCodeExpected: 403
178 after(async function () {
179 killallServers([ server ])
181 // Keep the logs if the test failed