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; }'
39 email: 'superadmin1@example.com'
57 // ---------------------------------------------------------------
59 before(async function () {
63 server = await runServer(1)
65 await setAccessTokensToServers([ server ])
71 await createUser(server.url, server.accessToken, user.username, user.password)
72 userAccessToken = await userLogin(server, user)
75 describe('When getting the configuration', function () {
76 it('Should fail without token', async function () {
77 await makeGetRequest({
80 statusCodeExpected: 401
84 it('Should fail if the user is not an administrator', async function () {
85 await makeGetRequest({
88 token: userAccessToken,
89 statusCodeExpected: 403
94 describe('When updating the configuration', function () {
95 it('Should fail without token', async function () {
96 await makePutBodyRequest({
100 statusCodeExpected: 401
104 it('Should fail if the user is not an administrator', async function () {
105 await makePutBodyRequest({
108 fields: updateParams,
109 token: userAccessToken,
110 statusCodeExpected: 403
114 it('Should fail if it misses a key', async function () {
115 const newUpdateParams = omit(updateParams, 'admin.email')
117 await makePutBodyRequest({
120 fields: newUpdateParams,
121 token: server.accessToken,
122 statusCodeExpected: 400
126 it('Should fail with a bad default NSFW policy', async function () {
127 const newUpdateParams = immutableAssign(updateParams, {
129 defaultNSFWPolicy: 'hello'
133 await makePutBodyRequest({
136 fields: newUpdateParams,
137 token: server.accessToken,
138 statusCodeExpected: 400
142 it('Should success with the correct parameters', async function () {
143 await makePutBodyRequest({
146 fields: updateParams,
147 token: server.accessToken,
148 statusCodeExpected: 200
153 describe('When deleting the configuration', function () {
154 it('Should fail without token', async function () {
155 await makeDeleteRequest({
158 statusCodeExpected: 401
162 it('Should fail if the user is not an administrator', async function () {
163 await makeDeleteRequest({
166 token: userAccessToken,
167 statusCodeExpected: 403
172 after(async function () {
173 killallServers([ server ])
175 // Keep the logs if the test failed