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 description: 'my super description',
20 terms: 'my super terms',
22 javascript: 'alert("coucou")',
23 css: 'body { background-color: red; }'
36 email: 'superadmin1@example.com'
54 // ---------------------------------------------------------------
56 before(async function () {
60 server = await runServer(1)
62 await setAccessTokensToServers([ server ])
68 await createUser(server.url, server.accessToken, user.username, user.password)
69 userAccessToken = await userLogin(server, user)
72 describe('When getting the configuration', function () {
73 it('Should fail without token', async function () {
74 await makeGetRequest({
77 statusCodeExpected: 401
81 it('Should fail if the user is not an administrator', async function () {
82 await makeGetRequest({
85 token: userAccessToken,
86 statusCodeExpected: 403
91 describe('When updating the configuration', function () {
92 it('Should fail without token', async function () {
93 await makePutBodyRequest({
97 statusCodeExpected: 401
101 it('Should fail if the user is not an administrator', async function () {
102 await makePutBodyRequest({
105 fields: updateParams,
106 token: userAccessToken,
107 statusCodeExpected: 403
111 it('Should fail if it misses a key', async function () {
112 const newUpdateParams = omit(updateParams, 'admin.email')
114 await makePutBodyRequest({
117 fields: newUpdateParams,
118 token: server.accessToken,
119 statusCodeExpected: 400
123 it('Should success with the correct parameters', async function () {
124 await makePutBodyRequest({
127 fields: updateParams,
128 token: server.accessToken,
129 statusCodeExpected: 200
134 describe('When deleting the configuration', function () {
135 it('Should fail without token', async function () {
136 await makeDeleteRequest({
139 statusCodeExpected: 401
143 it('Should fail if the user is not an administrator', async function () {
144 await makeDeleteRequest({
147 token: userAccessToken,
148 statusCodeExpected: 403
153 after(async function () {
154 killallServers([ server ])
156 // Keep the logs if the test failed