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
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',
24 javascript: 'alert("coucou")',
25 css: 'body { background-color: red; }'
38 email: 'superadmin1@example.com'
56 // ---------------------------------------------------------------
58 before(async function () {
62 server = await runServer(1)
64 await setAccessTokensToServers([ server ])
70 await createUser(server.url, server.accessToken, user.username, user.password)
71 userAccessToken = await userLogin(server, user)
74 describe('When getting the configuration', function () {
75 it('Should fail without token', async function () {
76 await makeGetRequest({
79 statusCodeExpected: 401
83 it('Should fail if the user is not an administrator', async function () {
84 await makeGetRequest({
87 token: userAccessToken,
88 statusCodeExpected: 403
93 describe('When updating the configuration', function () {
94 it('Should fail without token', async function () {
95 await makePutBodyRequest({
99 statusCodeExpected: 401
103 it('Should fail if the user is not an administrator', async function () {
104 await makePutBodyRequest({
107 fields: updateParams,
108 token: userAccessToken,
109 statusCodeExpected: 403
113 it('Should fail if it misses a key', async function () {
114 const newUpdateParams = omit(updateParams, 'admin.email')
116 await makePutBodyRequest({
119 fields: newUpdateParams,
120 token: server.accessToken,
121 statusCodeExpected: 400
125 it('Should success with the correct parameters', async function () {
126 await makePutBodyRequest({
129 fields: updateParams,
130 token: server.accessToken,
131 statusCodeExpected: 200
136 describe('When deleting the configuration', function () {
137 it('Should fail without token', async function () {
138 await makeDeleteRequest({
141 statusCodeExpected: 401
145 it('Should fail if the user is not an administrator', async function () {
146 await makeDeleteRequest({
149 token: userAccessToken,
150 statusCodeExpected: 403
155 after(async function () {
156 killallServers([ server ])
158 // Keep the logs if the test failed