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, makeHTMLRequest, 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 function checkIndexTags (html: string, title: string, description: string, css: string) {
73 expect(html).to.contain('<title>' + title + '</title>')
74 expect(html).to.contain('<meta name="description" content="' + description + '" />')
75 expect(html).to.contain('<style class="custom-css-style">' + css + '</style>')
78 describe('Test config', function () {
81 before(async function () {
85 server = await runServer(1)
86 await setAccessTokensToServers([ server ])
89 it('Should have a correct config on a server with registration enabled', async function () {
90 const res = await getConfig(server.url)
93 expect(data.signup.allowed).to.be.true
96 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
100 registerUser(server.url, 'user1', 'super password'),
101 registerUser(server.url, 'user2', 'super password'),
102 registerUser(server.url, 'user3', 'super password')
105 const res = await getConfig(server.url)
106 const data = res.body
108 expect(data.signup.allowed).to.be.false
111 it('Should get the customized configuration', async function () {
112 const res = await getCustomConfig(server.url, server.accessToken)
113 const data = res.body as CustomConfig
115 checkInitialConfig(data)
118 it('Should have valid index html tags (title, description...)', async function () {
119 const res = await makeHTMLRequest(server.url, '/videos/trending')
121 const description = 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
122 'with WebTorrent and Angular.'
123 checkIndexTags(res.text, 'PeerTube', description, '')
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; }'
159 email: 'superadmin1@example.com'
176 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
178 const res = await getCustomConfig(server.url, server.accessToken)
179 const data = res.body
181 checkUpdatedConfig(data)
184 it('Should have valid index html updated tags (title, description...)', async function () {
185 const res = await makeHTMLRequest(server.url, '/videos/trending')
187 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
190 it('Should have the configuration updated after a restart', async function () {
193 killallServers([ server ])
195 await reRunServer(server)
197 const res = await getCustomConfig(server.url, server.accessToken)
198 const data = res.body
200 checkUpdatedConfig(data)
203 const resHtml = await makeHTMLRequest(server.url, '/videos/trending')
204 checkIndexTags(resHtml.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
207 it('Should fetch the about information', async function () {
208 const res = await getAbout(server.url)
209 const data: About = res.body
211 expect(data.instance.name).to.equal('PeerTube updated')
212 expect(data.instance.shortDescription).to.equal('my short description')
213 expect(data.instance.description).to.equal('my super description')
214 expect(data.instance.terms).to.equal('my super terms')
217 it('Should remove the custom configuration', async function () {
220 await deleteCustomConfig(server.url, server.accessToken)
222 const res = await getCustomConfig(server.url, server.accessToken)
223 const data = res.body
225 checkInitialConfig(data)
228 after(async function () {
229 killallServers([ server ])