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