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.defaultNSFWPolicy).to.equal('display')
34 expect(data.instance.customizations.css).to.be.empty
35 expect(data.instance.customizations.javascript).to.be.empty
37 expect(data.services.twitter.username).to.equal('@Chocobozzz')
38 expect(data.services.twitter.whitelisted).to.be.false
40 expect(data.cache.previews.size).to.equal(1)
41 expect(data.cache.captions.size).to.equal(1)
43 expect(data.signup.enabled).to.be.true
44 expect(data.signup.limit).to.equal(4)
45 expect(data.signup.requiresEmailVerification).to.be.false
47 expect(data.admin.email).to.equal('admin1@example.com')
48 expect(data.contactForm.enabled).to.be.true
50 expect(data.user.videoQuota).to.equal(5242880)
51 expect(data.user.videoQuotaDaily).to.equal(-1)
52 expect(data.transcoding.enabled).to.be.false
53 expect(data.transcoding.allowAdditionalExtensions).to.be.false
54 expect(data.transcoding.threads).to.equal(2)
55 expect(data.transcoding.resolutions['240p']).to.be.true
56 expect(data.transcoding.resolutions['360p']).to.be.true
57 expect(data.transcoding.resolutions['480p']).to.be.true
58 expect(data.transcoding.resolutions['720p']).to.be.true
59 expect(data.transcoding.resolutions['1080p']).to.be.true
60 expect(data.import.videos.http.enabled).to.be.true
61 expect(data.import.videos.torrent.enabled).to.be.true
64 function checkUpdatedConfig (data: CustomConfig) {
65 expect(data.instance.name).to.equal('PeerTube updated')
66 expect(data.instance.shortDescription).to.equal('my short description')
67 expect(data.instance.description).to.equal('my super description')
68 expect(data.instance.terms).to.equal('my super terms')
69 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
70 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
71 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
72 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
74 expect(data.services.twitter.username).to.equal('@Kuja')
75 expect(data.services.twitter.whitelisted).to.be.true
77 expect(data.cache.previews.size).to.equal(2)
78 expect(data.cache.captions.size).to.equal(3)
80 expect(data.signup.enabled).to.be.false
81 expect(data.signup.limit).to.equal(5)
82 expect(data.signup.requiresEmailVerification).to.be.true
84 expect(data.admin.email).to.equal('superadmin1@example.com')
85 expect(data.contactForm.enabled).to.be.false
87 expect(data.user.videoQuota).to.equal(5242881)
88 expect(data.user.videoQuotaDaily).to.equal(318742)
90 expect(data.transcoding.enabled).to.be.true
91 expect(data.transcoding.threads).to.equal(1)
92 expect(data.transcoding.allowAdditionalExtensions).to.be.true
93 expect(data.transcoding.resolutions['240p']).to.be.false
94 expect(data.transcoding.resolutions['360p']).to.be.true
95 expect(data.transcoding.resolutions['480p']).to.be.true
96 expect(data.transcoding.resolutions['720p']).to.be.false
97 expect(data.transcoding.resolutions['1080p']).to.be.false
99 expect(data.import.videos.http.enabled).to.be.false
100 expect(data.import.videos.torrent.enabled).to.be.false
103 describe('Test config', function () {
106 before(async function () {
110 server = await runServer(1)
111 await setAccessTokensToServers([ server ])
114 it('Should have a correct config on a server with registration enabled', async function () {
115 const res = await getConfig(server.url)
116 const data: ServerConfig = res.body
118 expect(data.signup.allowed).to.be.true
121 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
125 registerUser(server.url, 'user1', 'super password'),
126 registerUser(server.url, 'user2', 'super password'),
127 registerUser(server.url, 'user3', 'super password')
130 const res = await getConfig(server.url)
131 const data: ServerConfig = res.body
133 expect(data.signup.allowed).to.be.false
136 it('Should have the correct video allowed extensions', async function () {
137 const res = await getConfig(server.url)
138 const data: ServerConfig = res.body
140 expect(data.video.file.extensions).to.have.lengthOf(3)
141 expect(data.video.file.extensions).to.contain('.mp4')
142 expect(data.video.file.extensions).to.contain('.webm')
143 expect(data.video.file.extensions).to.contain('.ogv')
145 expect(data.contactForm.enabled).to.be.true
148 it('Should get the customized configuration', async function () {
149 const res = await getCustomConfig(server.url, server.accessToken)
150 const data = res.body as CustomConfig
152 checkInitialConfig(data)
155 it('Should update the customized configuration', async function () {
156 const newCustomConfig: CustomConfig = {
158 name: 'PeerTube updated',
159 shortDescription: 'my short description',
160 description: 'my super description',
161 terms: 'my super terms',
162 defaultClientRoute: '/videos/recently-added',
163 defaultNSFWPolicy: 'blur' as 'blur',
165 javascript: 'alert("coucou")',
166 css: 'body { background-color: red; }'
186 requiresEmailVerification: true
189 email: 'superadmin1@example.com'
196 videoQuotaDaily: 318742
200 allowAdditionalExtensions: true,
221 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
223 const res = await getCustomConfig(server.url, server.accessToken)
224 const data = res.body
226 checkUpdatedConfig(data)
229 it('Should have the correct updated video allowed extensions', async function () {
230 const res = await getConfig(server.url)
231 const data: ServerConfig = res.body
233 expect(data.video.file.extensions).to.have.length.above(3)
234 expect(data.video.file.extensions).to.contain('.mp4')
235 expect(data.video.file.extensions).to.contain('.webm')
236 expect(data.video.file.extensions).to.contain('.ogv')
237 expect(data.video.file.extensions).to.contain('.flv')
238 expect(data.video.file.extensions).to.contain('.mkv')
241 it('Should have the configuration updated after a restart', async function () {
244 killallServers([ server ])
246 await reRunServer(server)
248 const res = await getCustomConfig(server.url, server.accessToken)
249 const data = res.body
251 checkUpdatedConfig(data)
254 it('Should fetch the about information', async function () {
255 const res = await getAbout(server.url)
256 const data: About = res.body
258 expect(data.instance.name).to.equal('PeerTube updated')
259 expect(data.instance.shortDescription).to.equal('my short description')
260 expect(data.instance.description).to.equal('my super description')
261 expect(data.instance.terms).to.equal('my super terms')
264 it('Should remove the custom configuration', async function () {
267 await deleteCustomConfig(server.url, server.accessToken)
269 const res = await getCustomConfig(server.url, server.accessToken)
270 const data = res.body
272 checkInitialConfig(data)
275 after(async function () {
276 killallServers([ server ])