]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
Add ability to change the homepage
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
4 import * as chai from 'chai'
5 import { About } from '../../../../shared/models/server/about.model'
6 import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7 import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils'
8 const expect = chai.expect
9
10 import {
11 getConfig,
12 flushTests,
13 runServer,
14 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
15 } from '../../utils/index'
16
17 describe('Test config', function () {
18 let server = null
19
20 before(async function () {
21 this.timeout(30000)
22
23 await flushTests()
24 server = await runServer(1)
25 await setAccessTokensToServers([ server ])
26 })
27
28 it('Should have a correct config on a server with registration enabled', async function () {
29 const res = await getConfig(server.url)
30 const data = res.body
31
32 expect(data.signup.allowed).to.be.true
33 })
34
35 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
36 this.timeout(5000)
37
38 await Promise.all([
39 registerUser(server.url, 'user1', 'super password'),
40 registerUser(server.url, 'user2', 'super password'),
41 registerUser(server.url, 'user3', 'super password')
42 ])
43
44 const res = await getConfig(server.url)
45 const data = res.body
46
47 expect(data.signup.allowed).to.be.false
48 })
49
50 it('Should get the customized configuration', async function () {
51 const res = await getCustomConfig(server.url, server.accessToken)
52 const data = res.body as CustomConfig
53
54 expect(data.instance.name).to.equal('PeerTube')
55 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
56 expect(data.instance.terms).to.equal('No terms for now.')
57 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
58 expect(data.instance.customizations.css).to.be.empty
59 expect(data.instance.customizations.javascript).to.be.empty
60 expect(data.cache.previews.size).to.equal(1)
61 expect(data.signup.enabled).to.be.true
62 expect(data.signup.limit).to.equal(4)
63 expect(data.admin.email).to.equal('admin1@example.com')
64 expect(data.user.videoQuota).to.equal(5242880)
65 expect(data.transcoding.enabled).to.be.false
66 expect(data.transcoding.threads).to.equal(2)
67 expect(data.transcoding.resolutions['240p']).to.be.true
68 expect(data.transcoding.resolutions['360p']).to.be.true
69 expect(data.transcoding.resolutions['480p']).to.be.true
70 expect(data.transcoding.resolutions['720p']).to.be.true
71 expect(data.transcoding.resolutions['1080p']).to.be.true
72 })
73
74 it('Should update the customized configuration', async function () {
75 const newCustomConfig = {
76 instance: {
77 name: 'PeerTube updated',
78 description: 'my super description',
79 terms: 'my super terms',
80 defaultClientRoute: '/videos/recently-added',
81 customizations: {
82 javascript: 'alert("coucou")',
83 css: 'body { background-color: red; }'
84 }
85 },
86 cache: {
87 previews: {
88 size: 2
89 }
90 },
91 signup: {
92 enabled: false,
93 limit: 5
94 },
95 admin: {
96 email: 'superadmin1@example.com'
97 },
98 user: {
99 videoQuota: 5242881
100 },
101 transcoding: {
102 enabled: true,
103 threads: 1,
104 resolutions: {
105 '240p': false,
106 '360p': true,
107 '480p': true,
108 '720p': false,
109 '1080p': false
110 }
111 }
112 }
113 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
114
115 const res = await getCustomConfig(server.url, server.accessToken)
116 const data = res.body
117
118 expect(data.instance.name).to.equal('PeerTube updated')
119 expect(data.instance.description).to.equal('my super description')
120 expect(data.instance.terms).to.equal('my super terms')
121 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
122 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
123 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
124 expect(data.cache.previews.size).to.equal(2)
125 expect(data.signup.enabled).to.be.false
126 expect(data.signup.limit).to.equal(5)
127 expect(data.admin.email).to.equal('superadmin1@example.com')
128 expect(data.user.videoQuota).to.equal(5242881)
129 expect(data.transcoding.enabled).to.be.true
130 expect(data.transcoding.threads).to.equal(1)
131 expect(data.transcoding.resolutions['240p']).to.be.false
132 expect(data.transcoding.resolutions['360p']).to.be.true
133 expect(data.transcoding.resolutions['480p']).to.be.true
134 expect(data.transcoding.resolutions['720p']).to.be.false
135 expect(data.transcoding.resolutions['1080p']).to.be.false
136 })
137
138 it('Should have the configuration updated after a restart', async function () {
139 this.timeout(10000)
140
141 killallServers([ server ])
142
143 await reRunServer(server)
144
145 const res = await getCustomConfig(server.url, server.accessToken)
146 const data = res.body
147
148 expect(data.instance.name).to.equal('PeerTube updated')
149 expect(data.instance.description).to.equal('my super description')
150 expect(data.instance.terms).to.equal('my super terms')
151 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
152 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
153 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
154 expect(data.cache.previews.size).to.equal(2)
155 expect(data.signup.enabled).to.be.false
156 expect(data.signup.limit).to.equal(5)
157 expect(data.admin.email).to.equal('superadmin1@example.com')
158 expect(data.user.videoQuota).to.equal(5242881)
159 expect(data.transcoding.enabled).to.be.true
160 expect(data.transcoding.threads).to.equal(1)
161 expect(data.transcoding.resolutions['240p']).to.be.false
162 expect(data.transcoding.resolutions['360p']).to.be.true
163 expect(data.transcoding.resolutions['480p']).to.be.true
164 expect(data.transcoding.resolutions['720p']).to.be.false
165 expect(data.transcoding.resolutions['1080p']).to.be.false
166 })
167
168 it('Should fetch the about information', async function () {
169 const res = await getAbout(server.url)
170 const data: About = res.body
171
172 expect(data.instance.name).to.equal('PeerTube updated')
173 expect(data.instance.description).to.equal('my super description')
174 expect(data.instance.terms).to.equal('my super terms')
175 })
176
177 it('Should remove the custom configuration', async function () {
178 this.timeout(10000)
179
180 await deleteCustomConfig(server.url, server.accessToken)
181
182 const res = await getCustomConfig(server.url, server.accessToken)
183 const data = res.body
184
185 expect(data.instance.name).to.equal('PeerTube')
186 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
187 expect(data.instance.terms).to.equal('No terms for now.')
188 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
189 expect(data.instance.customizations.css).to.be.empty
190 expect(data.instance.customizations.javascript).to.be.empty
191 expect(data.cache.previews.size).to.equal(1)
192 expect(data.signup.enabled).to.be.true
193 expect(data.signup.limit).to.equal(4)
194 expect(data.admin.email).to.equal('admin1@example.com')
195 expect(data.user.videoQuota).to.equal(5242880)
196 expect(data.transcoding.enabled).to.be.false
197 expect(data.transcoding.threads).to.equal(2)
198 expect(data.transcoding.resolutions['240p']).to.be.true
199 expect(data.transcoding.resolutions['360p']).to.be.true
200 expect(data.transcoding.resolutions['480p']).to.be.true
201 expect(data.transcoding.resolutions['720p']).to.be.true
202 expect(data.transcoding.resolutions['1080p']).to.be.true
203 })
204
205 after(async function () {
206 process.kill(-server.app.pid)
207
208 // Keep the logs if the test failed
209 if (this['ok']) {
210 await flushTests()
211 }
212 })
213 })