1 /* tslint:disable:no-unused-expression */
4 import * as chai from 'chai'
5 import { About } from '../../../../shared/models/config/about.model'
6 import { CustomConfig } from '../../../../shared/models/config/custom-config.model'
7 import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils'
8 const expect = chai.expect
14 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
15 } from '../../utils/index'
17 describe('Test config', function () {
20 before(async function () {
24 server = await runServer(1)
25 await setAccessTokensToServers([ server ])
28 it('Should have a correct config on a server with registration enabled', async function () {
29 const res = await getConfig(server.url)
32 expect(data.signup.allowed).to.be.true
35 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
39 registerUser(server.url, 'user1', 'super password'),
40 registerUser(server.url, 'user2', 'super password'),
41 registerUser(server.url, 'user3', 'super password')
44 const res = await getConfig(server.url)
47 expect(data.signup.allowed).to.be.false
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
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.customizations.css).to.be.empty
58 expect(data.instance.customizations.javascript).to.be.empty
59 expect(data.cache.previews.size).to.equal(1)
60 expect(data.signup.enabled).to.be.true
61 expect(data.signup.limit).to.equal(4)
62 expect(data.admin.email).to.equal('admin1@example.com')
63 expect(data.user.videoQuota).to.equal(5242880)
64 expect(data.transcoding.enabled).to.be.false
65 expect(data.transcoding.threads).to.equal(2)
66 expect(data.transcoding.resolutions['240p']).to.be.true
67 expect(data.transcoding.resolutions['360p']).to.be.true
68 expect(data.transcoding.resolutions['480p']).to.be.true
69 expect(data.transcoding.resolutions['720p']).to.be.true
70 expect(data.transcoding.resolutions['1080p']).to.be.true
73 it('Should update the customized configuration', async function () {
74 const newCustomConfig = {
76 name: 'PeerTube updated',
77 description: 'my super description',
78 terms: 'my super terms',
80 javascript: 'alert("coucou")',
81 css: 'body { background-color: red; }'
94 email: 'superadmin1@example.com'
111 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
113 const res = await getCustomConfig(server.url, server.accessToken)
114 const data = res.body
116 expect(data.instance.name).to.equal('PeerTube updated')
117 expect(data.instance.description).to.equal('my super description')
118 expect(data.instance.terms).to.equal('my super terms')
119 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
120 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
121 expect(data.cache.previews.size).to.equal(2)
122 expect(data.signup.enabled).to.be.false
123 expect(data.signup.limit).to.equal(5)
124 expect(data.admin.email).to.equal('superadmin1@example.com')
125 expect(data.user.videoQuota).to.equal(5242881)
126 expect(data.transcoding.enabled).to.be.true
127 expect(data.transcoding.threads).to.equal(1)
128 expect(data.transcoding.resolutions['240p']).to.be.false
129 expect(data.transcoding.resolutions['360p']).to.be.true
130 expect(data.transcoding.resolutions['480p']).to.be.true
131 expect(data.transcoding.resolutions['720p']).to.be.false
132 expect(data.transcoding.resolutions['1080p']).to.be.false
135 it('Should have the configuration updated after a restart', async function () {
138 killallServers([ server ])
140 await reRunServer(server)
142 const res = await getCustomConfig(server.url, server.accessToken)
143 const data = res.body
145 expect(data.instance.name).to.equal('PeerTube updated')
146 expect(data.instance.description).to.equal('my super description')
147 expect(data.instance.terms).to.equal('my super terms')
148 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
149 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
150 expect(data.cache.previews.size).to.equal(2)
151 expect(data.signup.enabled).to.be.false
152 expect(data.signup.limit).to.equal(5)
153 expect(data.admin.email).to.equal('superadmin1@example.com')
154 expect(data.user.videoQuota).to.equal(5242881)
155 expect(data.transcoding.enabled).to.be.true
156 expect(data.transcoding.threads).to.equal(1)
157 expect(data.transcoding.resolutions['240p']).to.be.false
158 expect(data.transcoding.resolutions['360p']).to.be.true
159 expect(data.transcoding.resolutions['480p']).to.be.true
160 expect(data.transcoding.resolutions['720p']).to.be.false
161 expect(data.transcoding.resolutions['1080p']).to.be.false
164 it('Should fetch the about information', async function () {
165 const res = await getAbout(server.url)
166 const data: About = res.body
168 expect(data.instance.name).to.equal('PeerTube updated')
169 expect(data.instance.description).to.equal('my super description')
170 expect(data.instance.terms).to.equal('my super terms')
173 it('Should remove the custom configuration', async function () {
176 await deleteCustomConfig(server.url, server.accessToken)
178 const res = await getCustomConfig(server.url, server.accessToken)
179 const data = res.body
181 expect(data.instance.name).to.equal('PeerTube')
182 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
183 expect(data.instance.terms).to.equal('No terms for now.')
184 expect(data.instance.customizations.css).to.be.empty
185 expect(data.instance.customizations.javascript).to.be.empty
186 expect(data.cache.previews.size).to.equal(1)
187 expect(data.signup.enabled).to.be.true
188 expect(data.signup.limit).to.equal(4)
189 expect(data.admin.email).to.equal('admin1@example.com')
190 expect(data.user.videoQuota).to.equal(5242880)
191 expect(data.transcoding.enabled).to.be.false
192 expect(data.transcoding.threads).to.equal(2)
193 expect(data.transcoding.resolutions['240p']).to.be.true
194 expect(data.transcoding.resolutions['360p']).to.be.true
195 expect(data.transcoding.resolutions['480p']).to.be.true
196 expect(data.transcoding.resolutions['720p']).to.be.true
197 expect(data.transcoding.resolutions['1080p']).to.be.true
200 after(async function () {
201 process.kill(-server.app.pid)
203 // Keep the logs if the test failed