1 /* tslint:disable:no-unused-expression */
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
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.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
74 it('Should update the customized configuration', async function () {
75 const newCustomConfig = {
77 name: 'PeerTube updated',
78 description: 'my super description',
79 terms: 'my super terms',
80 defaultClientRoute: '/videos/recently-added',
82 javascript: 'alert("coucou")',
83 css: 'body { background-color: red; }'
96 email: 'superadmin1@example.com'
113 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
115 const res = await getCustomConfig(server.url, server.accessToken)
116 const data = res.body
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
138 it('Should have the configuration updated after a restart', async function () {
141 killallServers([ server ])
143 await reRunServer(server)
145 const res = await getCustomConfig(server.url, server.accessToken)
146 const data = res.body
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
168 it('Should fetch the about information', async function () {
169 const res = await getAbout(server.url)
170 const data: About = res.body
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')
177 it('Should remove the custom configuration', async function () {
180 await deleteCustomConfig(server.url, server.accessToken)
182 const res = await getCustomConfig(server.url, server.accessToken)
183 const data = res.body
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
205 after(async function () {
206 process.kill(-server.app.pid)
208 // Keep the logs if the test failed