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'
20 import { ServerConfig } from '../../../../shared/models'
22 const expect = chai.expect
24 function checkInitialConfig (data: CustomConfig) {
25 expect(data.instance.name).to.equal('PeerTube')
26 expect(data.instance.shortDescription).to.equal(
27 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
28 'with WebTorrent and Angular.'
30 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
31 expect(data.instance.terms).to.equal('No terms for now.')
32 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
33 expect(data.instance.isNSFW).to.be.false
34 expect(data.instance.defaultNSFWPolicy).to.equal('display')
35 expect(data.instance.customizations.css).to.be.empty
36 expect(data.instance.customizations.javascript).to.be.empty
38 expect(data.services.twitter.username).to.equal('@Chocobozzz')
39 expect(data.services.twitter.whitelisted).to.be.false
41 expect(data.cache.previews.size).to.equal(1)
42 expect(data.cache.captions.size).to.equal(1)
44 expect(data.signup.enabled).to.be.true
45 expect(data.signup.limit).to.equal(4)
46 expect(data.signup.requiresEmailVerification).to.be.false
48 expect(data.admin.email).to.equal('admin1@example.com')
49 expect(data.contactForm.enabled).to.be.true
51 expect(data.user.videoQuota).to.equal(5242880)
52 expect(data.user.videoQuotaDaily).to.equal(-1)
53 expect(data.transcoding.enabled).to.be.false
54 expect(data.transcoding.allowAdditionalExtensions).to.be.false
55 expect(data.transcoding.threads).to.equal(2)
56 expect(data.transcoding.resolutions['240p']).to.be.true
57 expect(data.transcoding.resolutions['360p']).to.be.true
58 expect(data.transcoding.resolutions['480p']).to.be.true
59 expect(data.transcoding.resolutions['720p']).to.be.true
60 expect(data.transcoding.resolutions['1080p']).to.be.true
61 expect(data.transcoding.hls.enabled).to.be.true
63 expect(data.import.videos.http.enabled).to.be.true
64 expect(data.import.videos.torrent.enabled).to.be.true
67 function checkUpdatedConfig (data: CustomConfig) {
68 expect(data.instance.name).to.equal('PeerTube updated')
69 expect(data.instance.shortDescription).to.equal('my short description')
70 expect(data.instance.description).to.equal('my super description')
71 expect(data.instance.terms).to.equal('my super terms')
72 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
73 expect(data.instance.isNSFW).to.be.true
74 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
75 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
76 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
78 expect(data.services.twitter.username).to.equal('@Kuja')
79 expect(data.services.twitter.whitelisted).to.be.true
81 expect(data.cache.previews.size).to.equal(2)
82 expect(data.cache.captions.size).to.equal(3)
84 expect(data.signup.enabled).to.be.false
85 expect(data.signup.limit).to.equal(5)
86 expect(data.signup.requiresEmailVerification).to.be.false
88 expect(data.admin.email).to.equal('superadmin1@example.com')
89 expect(data.contactForm.enabled).to.be.false
91 expect(data.user.videoQuota).to.equal(5242881)
92 expect(data.user.videoQuotaDaily).to.equal(318742)
94 expect(data.transcoding.enabled).to.be.true
95 expect(data.transcoding.threads).to.equal(1)
96 expect(data.transcoding.allowAdditionalExtensions).to.be.true
97 expect(data.transcoding.resolutions['240p']).to.be.false
98 expect(data.transcoding.resolutions['360p']).to.be.true
99 expect(data.transcoding.resolutions['480p']).to.be.true
100 expect(data.transcoding.resolutions['720p']).to.be.false
101 expect(data.transcoding.resolutions['1080p']).to.be.false
102 expect(data.transcoding.hls.enabled).to.be.false
104 expect(data.import.videos.http.enabled).to.be.false
105 expect(data.import.videos.torrent.enabled).to.be.false
108 describe('Test config', function () {
111 before(async function () {
115 server = await runServer(1)
116 await setAccessTokensToServers([ server ])
119 it('Should have a correct config on a server with registration enabled', async function () {
120 const res = await getConfig(server.url)
121 const data: ServerConfig = res.body
123 expect(data.signup.allowed).to.be.true
126 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
130 registerUser(server.url, 'user1', 'super password'),
131 registerUser(server.url, 'user2', 'super password'),
132 registerUser(server.url, 'user3', 'super password')
135 const res = await getConfig(server.url)
136 const data: ServerConfig = res.body
138 expect(data.signup.allowed).to.be.false
141 it('Should have the correct video allowed extensions', async function () {
142 const res = await getConfig(server.url)
143 const data: ServerConfig = res.body
145 expect(data.video.file.extensions).to.have.lengthOf(3)
146 expect(data.video.file.extensions).to.contain('.mp4')
147 expect(data.video.file.extensions).to.contain('.webm')
148 expect(data.video.file.extensions).to.contain('.ogv')
150 expect(data.contactForm.enabled).to.be.true
153 it('Should get the customized configuration', async function () {
154 const res = await getCustomConfig(server.url, server.accessToken)
155 const data = res.body as CustomConfig
157 checkInitialConfig(data)
160 it('Should update the customized configuration', async function () {
161 const newCustomConfig: CustomConfig = {
163 name: 'PeerTube updated',
164 shortDescription: 'my short description',
165 description: 'my super description',
166 terms: 'my super terms',
167 defaultClientRoute: '/videos/recently-added',
169 defaultNSFWPolicy: 'blur' as 'blur',
171 javascript: 'alert("coucou")',
172 css: 'body { background-color: red; }'
192 requiresEmailVerification: false
195 email: 'superadmin1@example.com'
202 videoQuotaDaily: 318742
206 allowAdditionalExtensions: true,
230 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
232 const res = await getCustomConfig(server.url, server.accessToken)
233 const data = res.body
235 checkUpdatedConfig(data)
238 it('Should have the correct updated video allowed extensions', async function () {
239 const res = await getConfig(server.url)
240 const data: ServerConfig = res.body
242 expect(data.video.file.extensions).to.have.length.above(3)
243 expect(data.video.file.extensions).to.contain('.mp4')
244 expect(data.video.file.extensions).to.contain('.webm')
245 expect(data.video.file.extensions).to.contain('.ogv')
246 expect(data.video.file.extensions).to.contain('.flv')
247 expect(data.video.file.extensions).to.contain('.mkv')
250 it('Should have the configuration updated after a restart', async function () {
253 killallServers([ server ])
255 await reRunServer(server)
257 const res = await getCustomConfig(server.url, server.accessToken)
258 const data = res.body
260 checkUpdatedConfig(data)
263 it('Should fetch the about information', async function () {
264 const res = await getAbout(server.url)
265 const data: About = res.body
267 expect(data.instance.name).to.equal('PeerTube updated')
268 expect(data.instance.shortDescription).to.equal('my short description')
269 expect(data.instance.description).to.equal('my super description')
270 expect(data.instance.terms).to.equal('my super terms')
273 it('Should remove the custom configuration', async function () {
276 await deleteCustomConfig(server.url, server.accessToken)
278 const res = await getCustomConfig(server.url, server.accessToken)
279 const data = res.body
281 checkInitialConfig(data)
284 after(async function () {
285 killallServers([ server ])