]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/check-params/config.ts
Add ability to change the homepage
[github/Chocobozzz/PeerTube.git] / server / tests / api / check-params / config.ts
1 /* tslint:disable:no-unused-expression */
2
3 import { omit } from 'lodash'
4 import 'mocha'
5 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
6
7 import {
8 createUser, flushTests, killallServers, makeDeleteRequest, makeGetRequest, makePutBodyRequest, runServer, ServerInfo,
9 setAccessTokensToServers, userLogin
10 } from '../../utils'
11
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 = {
17 instance: {
18 name: 'PeerTube updated',
19 description: 'my super description',
20 terms: 'my super terms',
21 defaultClientRoute: '/videos/recently-added',
22 customizations: {
23 javascript: 'alert("coucou")',
24 css: 'body { background-color: red; }'
25 }
26 },
27 cache: {
28 previews: {
29 size: 2
30 }
31 },
32 signup: {
33 enabled: false,
34 limit: 5
35 },
36 admin: {
37 email: 'superadmin1@example.com'
38 },
39 user: {
40 videoQuota: 5242881
41 },
42 transcoding: {
43 enabled: true,
44 threads: 1,
45 resolutions: {
46 '240p': false,
47 '360p': true,
48 '480p': true,
49 '720p': false,
50 '1080p': false
51 }
52 }
53 }
54
55 // ---------------------------------------------------------------
56
57 before(async function () {
58 this.timeout(30000)
59
60 await flushTests()
61 server = await runServer(1)
62
63 await setAccessTokensToServers([ server ])
64
65 const user = {
66 username: 'user1',
67 password: 'password'
68 }
69 await createUser(server.url, server.accessToken, user.username, user.password)
70 userAccessToken = await userLogin(server, user)
71 })
72
73 describe('When getting the configuration', function () {
74 it('Should fail without token', async function () {
75 await makeGetRequest({
76 url: server.url,
77 path,
78 statusCodeExpected: 401
79 })
80 })
81
82 it('Should fail if the user is not an administrator', async function () {
83 await makeGetRequest({
84 url: server.url,
85 path,
86 token: userAccessToken,
87 statusCodeExpected: 403
88 })
89 })
90 })
91
92 describe('When updating the configuration', function () {
93 it('Should fail without token', async function () {
94 await makePutBodyRequest({
95 url: server.url,
96 path,
97 fields: updateParams,
98 statusCodeExpected: 401
99 })
100 })
101
102 it('Should fail if the user is not an administrator', async function () {
103 await makePutBodyRequest({
104 url: server.url,
105 path,
106 fields: updateParams,
107 token: userAccessToken,
108 statusCodeExpected: 403
109 })
110 })
111
112 it('Should fail if it misses a key', async function () {
113 const newUpdateParams = omit(updateParams, 'admin.email')
114
115 await makePutBodyRequest({
116 url: server.url,
117 path,
118 fields: newUpdateParams,
119 token: server.accessToken,
120 statusCodeExpected: 400
121 })
122 })
123
124 it('Should success with the correct parameters', async function () {
125 await makePutBodyRequest({
126 url: server.url,
127 path,
128 fields: updateParams,
129 token: server.accessToken,
130 statusCodeExpected: 200
131 })
132 })
133 })
134
135 describe('When deleting the configuration', function () {
136 it('Should fail without token', async function () {
137 await makeDeleteRequest({
138 url: server.url,
139 path,
140 statusCodeExpected: 401
141 })
142 })
143
144 it('Should fail if the user is not an administrator', async function () {
145 await makeDeleteRequest({
146 url: server.url,
147 path,
148 token: userAccessToken,
149 statusCodeExpected: 403
150 })
151 })
152 })
153
154 after(async function () {
155 killallServers([ server ])
156
157 // Keep the logs if the test failed
158 if (this['ok']) {
159 await flushTests()
160 }
161 })
162 })