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 = {
27 email: 'superadmin1@example.com'
45 // ---------------------------------------------------------------
47 before(async function () {
51 server = await runServer(1)
53 await setAccessTokensToServers([ server ])
59 await createUser(server.url, server.accessToken, user.username, user.password)
60 userAccessToken = await userLogin(server, user)
63 describe('When getting the configuration', function () {
64 it('Should fail without token', async function () {
65 await makeGetRequest({
68 statusCodeExpected: 401
72 it('Should fail if the user is not an administrator', async function () {
73 await makeGetRequest({
76 token: userAccessToken,
77 statusCodeExpected: 403
82 describe('When updating the configuration', function () {
83 it('Should fail without token', async function () {
84 await makePutBodyRequest({
88 statusCodeExpected: 401
92 it('Should fail if the user is not an administrator', async function () {
93 await makePutBodyRequest({
97 token: userAccessToken,
98 statusCodeExpected: 403
102 it('Should fail if it misses a key', async function () {
103 const newUpdateParams = omit(updateParams, 'admin.email')
105 await makePutBodyRequest({
108 fields: newUpdateParams,
109 token: server.accessToken,
110 statusCodeExpected: 400
114 it('Should success with the correct parameters', async function () {
115 await makePutBodyRequest({
118 fields: updateParams,
119 token: server.accessToken,
120 statusCodeExpected: 200
125 describe('When deleting the configuration', function () {
126 it('Should fail without token', async function () {
127 await makeDeleteRequest({
130 statusCodeExpected: 401
134 it('Should fail if the user is not an administrator', async function () {
135 await makeDeleteRequest({
138 token: userAccessToken,
139 statusCodeExpected: 403
144 after(async function () {
145 killallServers([ server ])
147 // Keep the logs if the test failed