1 /* tslint:disable:no-unused-expression */
3 import { omit } from 'lodash'
5 import { CustomConfig } from '../../../../shared/models/config/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'
32 email: 'superadmin1@example.com'
50 // ---------------------------------------------------------------
52 before(async function () {
56 server = await runServer(1)
58 await setAccessTokensToServers([ server ])
64 await createUser(server.url, server.accessToken, user.username, user.password)
65 userAccessToken = await userLogin(server, user)
68 describe('When getting the configuration', function () {
69 it('Should fail without token', async function () {
70 await makeGetRequest({
73 statusCodeExpected: 401
77 it('Should fail if the user is not an administrator', async function () {
78 await makeGetRequest({
81 token: userAccessToken,
82 statusCodeExpected: 403
87 describe('When updating the configuration', function () {
88 it('Should fail without token', async function () {
89 await makePutBodyRequest({
93 statusCodeExpected: 401
97 it('Should fail if the user is not an administrator', async function () {
98 await makePutBodyRequest({
101 fields: updateParams,
102 token: userAccessToken,
103 statusCodeExpected: 403
107 it('Should fail if it misses a key', async function () {
108 const newUpdateParams = omit(updateParams, 'admin.email')
110 await makePutBodyRequest({
113 fields: newUpdateParams,
114 token: server.accessToken,
115 statusCodeExpected: 400
119 it('Should success with the correct parameters', async function () {
120 await makePutBodyRequest({
123 fields: updateParams,
124 token: server.accessToken,
125 statusCodeExpected: 200
130 describe('When deleting the configuration', function () {
131 it('Should fail without token', async function () {
132 await makeDeleteRequest({
135 statusCodeExpected: 401
139 it('Should fail if the user is not an administrator', async function () {
140 await makeDeleteRequest({
143 token: userAccessToken,
144 statusCodeExpected: 403
149 after(async function () {
150 killallServers([ server ])
152 // Keep the logs if the test failed