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'
17 setAccessTokensToServers,
19 } from '../../../../shared/utils'
21 const expect = chai.expect
23 function checkInitialConfig (data: CustomConfig) {
24 expect(data.instance.name).to.equal('PeerTube')
25 expect(data.instance.shortDescription).to.equal(
26 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
27 'with WebTorrent and Angular.'
29 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
30 expect(data.instance.terms).to.equal('No terms for now.')
31 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
32 expect(data.instance.defaultNSFWPolicy).to.equal('display')
33 expect(data.instance.customizations.css).to.be.empty
34 expect(data.instance.customizations.javascript).to.be.empty
35 expect(data.services.twitter.username).to.equal('@Chocobozzz')
36 expect(data.services.twitter.whitelisted).to.be.false
37 expect(data.cache.previews.size).to.equal(1)
38 expect(data.cache.captions.size).to.equal(1)
39 expect(data.signup.enabled).to.be.true
40 expect(data.signup.limit).to.equal(4)
41 expect(data.signup.requiresEmailVerification).to.be.false
42 expect(data.admin.email).to.equal('admin1@example.com')
43 expect(data.user.videoQuota).to.equal(5242880)
44 expect(data.user.videoQuotaDaily).to.equal(-1)
45 expect(data.transcoding.enabled).to.be.false
46 expect(data.transcoding.threads).to.equal(2)
47 expect(data.transcoding.resolutions['240p']).to.be.true
48 expect(data.transcoding.resolutions['360p']).to.be.true
49 expect(data.transcoding.resolutions['480p']).to.be.true
50 expect(data.transcoding.resolutions['720p']).to.be.true
51 expect(data.transcoding.resolutions['1080p']).to.be.true
52 expect(data.import.videos.http.enabled).to.be.true
53 expect(data.import.videos.torrent.enabled).to.be.true
56 function checkUpdatedConfig (data: CustomConfig) {
57 expect(data.instance.name).to.equal('PeerTube updated')
58 expect(data.instance.shortDescription).to.equal('my short description')
59 expect(data.instance.description).to.equal('my super description')
60 expect(data.instance.terms).to.equal('my super terms')
61 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
62 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
63 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
64 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
65 expect(data.services.twitter.username).to.equal('@Kuja')
66 expect(data.services.twitter.whitelisted).to.be.true
67 expect(data.cache.previews.size).to.equal(2)
68 expect(data.cache.captions.size).to.equal(3)
69 expect(data.signup.enabled).to.be.false
70 expect(data.signup.limit).to.equal(5)
71 expect(data.signup.requiresEmailVerification).to.be.true
72 expect(data.admin.email).to.equal('superadmin1@example.com')
73 expect(data.user.videoQuota).to.equal(5242881)
74 expect(data.user.videoQuotaDaily).to.equal(318742)
75 expect(data.transcoding.enabled).to.be.true
76 expect(data.transcoding.threads).to.equal(1)
77 expect(data.transcoding.resolutions['240p']).to.be.false
78 expect(data.transcoding.resolutions['360p']).to.be.true
79 expect(data.transcoding.resolutions['480p']).to.be.true
80 expect(data.transcoding.resolutions['720p']).to.be.false
81 expect(data.transcoding.resolutions['1080p']).to.be.false
82 expect(data.import.videos.http.enabled).to.be.false
83 expect(data.import.videos.torrent.enabled).to.be.false
86 describe('Test config', function () {
89 before(async function () {
93 server = await runServer(1)
94 await setAccessTokensToServers([ server ])
97 it('Should have a correct config on a server with registration enabled', async function () {
98 const res = await getConfig(server.url)
101 expect(data.signup.allowed).to.be.true
104 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
108 registerUser(server.url, 'user1', 'super password'),
109 registerUser(server.url, 'user2', 'super password'),
110 registerUser(server.url, 'user3', 'super password')
113 const res = await getConfig(server.url)
114 const data = res.body
116 expect(data.signup.allowed).to.be.false
119 it('Should get the customized configuration', async function () {
120 const res = await getCustomConfig(server.url, server.accessToken)
121 const data = res.body as CustomConfig
123 checkInitialConfig(data)
126 it('Should update the customized configuration', async function () {
127 const newCustomConfig: CustomConfig = {
129 name: 'PeerTube updated',
130 shortDescription: 'my short description',
131 description: 'my super description',
132 terms: 'my super terms',
133 defaultClientRoute: '/videos/recently-added',
134 defaultNSFWPolicy: 'blur' as 'blur',
136 javascript: 'alert("coucou")',
137 css: 'body { background-color: red; }'
157 requiresEmailVerification: true
160 email: 'superadmin1@example.com'
164 videoQuotaDaily: 318742
188 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
190 const res = await getCustomConfig(server.url, server.accessToken)
191 const data = res.body
193 checkUpdatedConfig(data)
196 it('Should have the configuration updated after a restart', async function () {
199 killallServers([ server ])
201 await reRunServer(server)
203 const res = await getCustomConfig(server.url, server.accessToken)
204 const data = res.body
206 checkUpdatedConfig(data)
209 it('Should fetch the about information', async function () {
210 const res = await getAbout(server.url)
211 const data: About = res.body
213 expect(data.instance.name).to.equal('PeerTube updated')
214 expect(data.instance.shortDescription).to.equal('my short description')
215 expect(data.instance.description).to.equal('my super description')
216 expect(data.instance.terms).to.equal('my super terms')
219 it('Should remove the custom configuration', async function () {
222 await deleteCustomConfig(server.url, server.accessToken)
224 const res = await getCustomConfig(server.url, server.accessToken)
225 const data = res.body
227 checkInitialConfig(data)
230 after(async function () {
231 killallServers([ server ])