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',
21 defaultClientRoute: '/videos/recently-added',
23 javascript: 'alert("coucou")',
24 css: 'body { background-color: red; }'
37 email: 'superadmin1@example.com'
55 // ---------------------------------------------------------------
57 before(async function () {
61 server = await runServer(1)
63 await setAccessTokensToServers([ server ])
69 await createUser(server.url, server.accessToken, user.username, user.password)
70 userAccessToken = await userLogin(server, user)
73 describe('When getting the configuration', function () {
74 it('Should fail without token', async function () {
75 await makeGetRequest({
78 statusCodeExpected: 401
82 it('Should fail if the user is not an administrator', async function () {
83 await makeGetRequest({
86 token: userAccessToken,
87 statusCodeExpected: 403
92 describe('When updating the configuration', function () {
93 it('Should fail without token', async function () {
94 await makePutBodyRequest({
98 statusCodeExpected: 401
102 it('Should fail if the user is not an administrator', async function () {
103 await makePutBodyRequest({
106 fields: updateParams,
107 token: userAccessToken,
108 statusCodeExpected: 403
112 it('Should fail if it misses a key', async function () {
113 const newUpdateParams = omit(updateParams, 'admin.email')
115 await makePutBodyRequest({
118 fields: newUpdateParams,
119 token: server.accessToken,
120 statusCodeExpected: 400
124 it('Should success with the correct parameters', async function () {
125 await makePutBodyRequest({
128 fields: updateParams,
129 token: server.accessToken,
130 statusCodeExpected: 200
135 describe('When deleting the configuration', function () {
136 it('Should fail without token', async function () {
137 await makeDeleteRequest({
140 statusCodeExpected: 401
144 it('Should fail if the user is not an administrator', async function () {
145 await makeDeleteRequest({
148 token: userAccessToken,
149 statusCodeExpected: 403
154 after(async function () {
155 killallServers([ server ])
157 // Keep the logs if the test failed