]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
7d21b6ce9cfdb2a116fdbb58766cd1d88c81c946
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
1 /* tslint:disable:no-unused-expression */
2
3 import 'mocha'
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
9
10 import {
11 getConfig,
12 flushTests,
13 runServer,
14 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
15 } from '../../utils/index'
16
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.'
22 )
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
44 }
45
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
70 }
71
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>')
76 }
77
78 describe('Test config', function () {
79 let server = null
80
81 before(async function () {
82 this.timeout(30000)
83
84 await flushTests()
85 server = await runServer(1)
86 await setAccessTokensToServers([ server ])
87 })
88
89 it('Should have a correct config on a server with registration enabled', async function () {
90 const res = await getConfig(server.url)
91 const data = res.body
92
93 expect(data.signup.allowed).to.be.true
94 })
95
96 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
97 this.timeout(5000)
98
99 await Promise.all([
100 registerUser(server.url, 'user1', 'super password'),
101 registerUser(server.url, 'user2', 'super password'),
102 registerUser(server.url, 'user3', 'super password')
103 ])
104
105 const res = await getConfig(server.url)
106 const data = res.body
107
108 expect(data.signup.allowed).to.be.false
109 })
110
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
114
115 checkInitialConfig(data)
116 })
117
118 it('Should have valid index html tags (title, description...)', async function () {
119 const res = await makeHTMLRequest(server.url, '/videos/trending')
120
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, '')
124 })
125
126 it('Should update the customized configuration', async function () {
127 const newCustomConfig: CustomConfig = {
128 instance: {
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',
135 customizations: {
136 javascript: 'alert("coucou")',
137 css: 'body { background-color: red; }'
138 }
139 },
140 services: {
141 twitter: {
142 username: '@Kuja',
143 whitelisted: true
144 }
145 },
146 cache: {
147 previews: {
148 size: 2
149 },
150 captions: {
151 size: 3
152 }
153 },
154 signup: {
155 enabled: false,
156 limit: 5
157 },
158 admin: {
159 email: 'superadmin1@example.com'
160 },
161 user: {
162 videoQuota: 5242881
163 },
164 transcoding: {
165 enabled: true,
166 threads: 1,
167 resolutions: {
168 '240p': false,
169 '360p': true,
170 '480p': true,
171 '720p': false,
172 '1080p': false
173 }
174 }
175 }
176 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
177
178 const res = await getCustomConfig(server.url, server.accessToken)
179 const data = res.body
180
181 checkUpdatedConfig(data)
182 })
183
184 it('Should have valid index html updated tags (title, description...)', async function () {
185 const res = await makeHTMLRequest(server.url, '/videos/trending')
186
187 checkIndexTags(res.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
188 })
189
190 it('Should have the configuration updated after a restart', async function () {
191 this.timeout(10000)
192
193 killallServers([ server ])
194
195 await reRunServer(server)
196
197 const res = await getCustomConfig(server.url, server.accessToken)
198 const data = res.body
199
200 checkUpdatedConfig(data)
201
202 // Check HTML too
203 const resHtml = await makeHTMLRequest(server.url, '/videos/trending')
204 checkIndexTags(resHtml.text, 'PeerTube updated', 'my short description', 'body { background-color: red; }')
205 })
206
207 it('Should fetch the about information', async function () {
208 const res = await getAbout(server.url)
209 const data: About = res.body
210
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')
215 })
216
217 it('Should remove the custom configuration', async function () {
218 this.timeout(10000)
219
220 await deleteCustomConfig(server.url, server.accessToken)
221
222 const res = await getCustomConfig(server.url, server.accessToken)
223 const data = res.body
224
225 checkInitialConfig(data)
226 })
227
228 after(async function () {
229 killallServers([ server ])
230 })
231 })