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'
14 setAccessTokensToServers,
16 } from '../../utils/index'
18 const expect = chai.expect
20 function checkInitialConfig (data: CustomConfig) {
21 expect(data.instance.name).to.equal('PeerTube')
22 expect(data.instance.shortDescription).to.equal(
23 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
24 'with WebTorrent and Angular.'
26 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
27 expect(data.instance.terms).to.equal('No terms for now.')
28 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
29 expect(data.instance.defaultNSFWPolicy).to.equal('display')
30 expect(data.instance.customizations.css).to.be.empty
31 expect(data.instance.customizations.javascript).to.be.empty
32 expect(data.services.twitter.username).to.equal('@Chocobozzz')
33 expect(data.services.twitter.whitelisted).to.be.false
34 expect(data.cache.previews.size).to.equal(1)
35 expect(data.cache.captions.size).to.equal(1)
36 expect(data.signup.enabled).to.be.true
37 expect(data.signup.limit).to.equal(4)
38 expect(data.admin.email).to.equal('admin1@example.com')
39 expect(data.user.videoQuota).to.equal(5242880)
40 expect(data.transcoding.enabled).to.be.false
41 expect(data.transcoding.threads).to.equal(2)
42 expect(data.transcoding.resolutions['240p']).to.be.true
43 expect(data.transcoding.resolutions['360p']).to.be.true
44 expect(data.transcoding.resolutions['480p']).to.be.true
45 expect(data.transcoding.resolutions['720p']).to.be.true
46 expect(data.transcoding.resolutions['1080p']).to.be.true
49 function checkUpdatedConfig (data: CustomConfig) {
50 expect(data.instance.name).to.equal('PeerTube updated')
51 expect(data.instance.shortDescription).to.equal('my short description')
52 expect(data.instance.description).to.equal('my super description')
53 expect(data.instance.terms).to.equal('my super terms')
54 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
55 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
56 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
57 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
58 expect(data.services.twitter.username).to.equal('@Kuja')
59 expect(data.services.twitter.whitelisted).to.be.true
60 expect(data.cache.previews.size).to.equal(2)
61 expect(data.cache.captions.size).to.equal(3)
62 expect(data.signup.enabled).to.be.false
63 expect(data.signup.limit).to.equal(5)
64 expect(data.admin.email).to.equal('superadmin1@example.com')
65 expect(data.user.videoQuota).to.equal(5242881)
66 expect(data.transcoding.enabled).to.be.true
67 expect(data.transcoding.threads).to.equal(1)
68 expect(data.transcoding.resolutions['240p']).to.be.false
69 expect(data.transcoding.resolutions['360p']).to.be.true
70 expect(data.transcoding.resolutions['480p']).to.be.true
71 expect(data.transcoding.resolutions['720p']).to.be.false
72 expect(data.transcoding.resolutions['1080p']).to.be.false
75 describe('Test config', function () {
78 before(async function () {
82 server = await runServer(1)
83 await setAccessTokensToServers([ server ])
86 it('Should have a correct config on a server with registration enabled', async function () {
87 const res = await getConfig(server.url)
90 expect(data.signup.allowed).to.be.true
93 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
97 registerUser(server.url, 'user1', 'super password'),
98 registerUser(server.url, 'user2', 'super password'),
99 registerUser(server.url, 'user3', 'super password')
102 const res = await getConfig(server.url)
103 const data = res.body
105 expect(data.signup.allowed).to.be.false
108 it('Should get the customized configuration', async function () {
109 const res = await getCustomConfig(server.url, server.accessToken)
110 const data = res.body as CustomConfig
112 checkInitialConfig(data)
115 it('Should update the customized configuration', async function () {
116 const newCustomConfig: CustomConfig = {
118 name: 'PeerTube updated',
119 shortDescription: 'my short description',
120 description: 'my super description',
121 terms: 'my super terms',
122 defaultClientRoute: '/videos/recently-added',
123 defaultNSFWPolicy: 'blur' as 'blur',
125 javascript: 'alert("coucou")',
126 css: 'body { background-color: red; }'
148 email: 'superadmin1@example.com'
165 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
167 const res = await getCustomConfig(server.url, server.accessToken)
168 const data = res.body
170 checkUpdatedConfig(data)
173 it('Should have the configuration updated after a restart', async function () {
176 killallServers([ server ])
178 await reRunServer(server)
180 const res = await getCustomConfig(server.url, server.accessToken)
181 const data = res.body
183 checkUpdatedConfig(data)
186 it('Should fetch the about information', async function () {
187 const res = await getAbout(server.url)
188 const data: About = res.body
190 expect(data.instance.name).to.equal('PeerTube updated')
191 expect(data.instance.shortDescription).to.equal('my short description')
192 expect(data.instance.description).to.equal('my super description')
193 expect(data.instance.terms).to.equal('my super terms')
196 it('Should remove the custom configuration', async function () {
199 await deleteCustomConfig(server.url, server.accessToken)
201 const res = await getCustomConfig(server.url, server.accessToken)
202 const data = res.body
204 checkInitialConfig(data)
207 after(async function () {
208 killallServers([ server ])