]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Merge branch 'release/v1.2.0'
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
CommitLineData
0e1dc3e7
C
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
09cababd
C
5import { About } from '../../../../shared/models/server/about.model'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
0e1dc3e7 7import {
9639bd17 8 deleteCustomConfig,
9 getAbout,
10 killallServers,
11 reRunServer,
0e1dc3e7 12 flushTests,
5bcfd029
C
13 getConfig,
14 getCustomConfig,
15 registerUser,
0e1dc3e7 16 runServer,
5bcfd029
C
17 setAccessTokensToServers,
18 updateCustomConfig
9639bd17 19} from '../../../../shared/utils'
14e2014a 20import { ServerConfig } from '../../../../shared/models'
0e1dc3e7 21
5bcfd029
C
22const expect = chai.expect
23
40e87e9e
C
24function 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.'
29 )
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
a4101923 36
40e87e9e
C
37 expect(data.services.twitter.username).to.equal('@Chocobozzz')
38 expect(data.services.twitter.whitelisted).to.be.false
a4101923 39
40e87e9e
C
40 expect(data.cache.previews.size).to.equal(1)
41 expect(data.cache.captions.size).to.equal(1)
a4101923 42
40e87e9e
C
43 expect(data.signup.enabled).to.be.true
44 expect(data.signup.limit).to.equal(4)
d9eaee39 45 expect(data.signup.requiresEmailVerification).to.be.false
a4101923 46
40e87e9e 47 expect(data.admin.email).to.equal('admin1@example.com')
a4101923
C
48 expect(data.contactForm.enabled).to.be.true
49
40e87e9e 50 expect(data.user.videoQuota).to.equal(5242880)
9ee92651 51 expect(data.user.videoQuotaDaily).to.equal(-1)
40e87e9e 52 expect(data.transcoding.enabled).to.be.false
14e2014a 53 expect(data.transcoding.allowAdditionalExtensions).to.be.false
40e87e9e
C
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
5d08a6a7 60 expect(data.import.videos.http.enabled).to.be.true
a84b8fa5 61 expect(data.import.videos.torrent.enabled).to.be.true
40e87e9e
C
62}
63
64function 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; }')
a4101923 73
40e87e9e
C
74 expect(data.services.twitter.username).to.equal('@Kuja')
75 expect(data.services.twitter.whitelisted).to.be.true
a4101923 76
40e87e9e
C
77 expect(data.cache.previews.size).to.equal(2)
78 expect(data.cache.captions.size).to.equal(3)
a4101923 79
40e87e9e
C
80 expect(data.signup.enabled).to.be.false
81 expect(data.signup.limit).to.equal(5)
d9eaee39 82 expect(data.signup.requiresEmailVerification).to.be.true
a4101923 83
40e87e9e 84 expect(data.admin.email).to.equal('superadmin1@example.com')
a4101923
C
85 expect(data.contactForm.enabled).to.be.false
86
40e87e9e 87 expect(data.user.videoQuota).to.equal(5242881)
bee0abff 88 expect(data.user.videoQuotaDaily).to.equal(318742)
a4101923 89
40e87e9e
C
90 expect(data.transcoding.enabled).to.be.true
91 expect(data.transcoding.threads).to.equal(1)
14e2014a 92 expect(data.transcoding.allowAdditionalExtensions).to.be.true
40e87e9e
C
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
a4101923 98
5d08a6a7 99 expect(data.import.videos.http.enabled).to.be.false
a84b8fa5 100 expect(data.import.videos.torrent.enabled).to.be.false
40e87e9e
C
101}
102
0e1dc3e7
C
103describe('Test config', function () {
104 let server = null
105
106 before(async function () {
e212f887 107 this.timeout(30000)
0e1dc3e7
C
108
109 await flushTests()
110 server = await runServer(1)
fd206f0b 111 await setAccessTokensToServers([ server ])
0e1dc3e7
C
112 })
113
114 it('Should have a correct config on a server with registration enabled', async function () {
115 const res = await getConfig(server.url)
14e2014a 116 const data: ServerConfig = res.body
0e1dc3e7
C
117
118 expect(data.signup.allowed).to.be.true
119 })
120
121 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
652b3056
C
122 this.timeout(5000)
123
47e0652b
C
124 await Promise.all([
125 registerUser(server.url, 'user1', 'super password'),
126 registerUser(server.url, 'user2', 'super password'),
127 registerUser(server.url, 'user3', 'super password')
128 ])
0e1dc3e7
C
129
130 const res = await getConfig(server.url)
14e2014a 131 const data: ServerConfig = res.body
0e1dc3e7
C
132
133 expect(data.signup.allowed).to.be.false
134 })
135
14e2014a
C
136 it('Should have the correct video allowed extensions', async function () {
137 const res = await getConfig(server.url)
138 const data: ServerConfig = res.body
139
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')
a4101923
C
144
145 expect(data.contactForm.enabled).to.be.true
14e2014a
C
146 })
147
fd206f0b
C
148 it('Should get the customized configuration', async function () {
149 const res = await getCustomConfig(server.url, server.accessToken)
00b5556c 150 const data = res.body as CustomConfig
fd206f0b 151
40e87e9e 152 checkInitialConfig(data)
fd206f0b
C
153 })
154
155 it('Should update the customized configuration', async function () {
40e87e9e 156 const newCustomConfig: CustomConfig = {
66b16caf
C
157 instance: {
158 name: 'PeerTube updated',
2e3a0215 159 shortDescription: 'my short description',
66b16caf 160 description: 'my super description',
00b5556c 161 terms: 'my super terms',
901637bb 162 defaultClientRoute: '/videos/recently-added',
0883b324 163 defaultNSFWPolicy: 'blur' as 'blur',
00b5556c
C
164 customizations: {
165 javascript: 'alert("coucou")',
166 css: 'body { background-color: red; }'
167 }
66b16caf 168 },
8be1afa1
C
169 services: {
170 twitter: {
171 username: '@Kuja',
172 whitelisted: true
173 }
174 },
fd206f0b
C
175 cache: {
176 previews: {
177 size: 2
40e87e9e
C
178 },
179 captions: {
180 size: 3
fd206f0b
C
181 }
182 },
183 signup: {
184 enabled: false,
d9eaee39
JM
185 limit: 5,
186 requiresEmailVerification: true
fd206f0b
C
187 },
188 admin: {
189 email: 'superadmin1@example.com'
190 },
a4101923
C
191 contactForm: {
192 enabled: false
193 },
fd206f0b 194 user: {
bee0abff
FA
195 videoQuota: 5242881,
196 videoQuotaDaily: 318742
fd206f0b
C
197 },
198 transcoding: {
199 enabled: true,
14e2014a 200 allowAdditionalExtensions: true,
fd206f0b
C
201 threads: 1,
202 resolutions: {
203 '240p': false,
204 '360p': true,
205 '480p': true,
206 '720p': false,
207 '1080p': false
208 }
5d08a6a7
C
209 },
210 import: {
211 videos: {
212 http: {
213 enabled: false
a84b8fa5
C
214 },
215 torrent: {
216 enabled: false
5d08a6a7
C
217 }
218 }
fd206f0b
C
219 }
220 }
221 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
222
223 const res = await getCustomConfig(server.url, server.accessToken)
224 const data = res.body
225
40e87e9e 226 checkUpdatedConfig(data)
fd206f0b
C
227 })
228
14e2014a
C
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
232
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')
239 })
240
fd206f0b 241 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
242 this.timeout(10000)
243
fd206f0b
C
244 killallServers([ server ])
245
246 await reRunServer(server)
247
248 const res = await getCustomConfig(server.url, server.accessToken)
249 const data = res.body
250
40e87e9e 251 checkUpdatedConfig(data)
fd206f0b
C
252 })
253
36f9424f
C
254 it('Should fetch the about information', async function () {
255 const res = await getAbout(server.url)
256 const data: About = res.body
257
258 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 259 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
260 expect(data.instance.description).to.equal('my super description')
261 expect(data.instance.terms).to.equal('my super terms')
262 })
263
fd206f0b 264 it('Should remove the custom configuration', async function () {
23e27dd5
C
265 this.timeout(10000)
266
fd206f0b
C
267 await deleteCustomConfig(server.url, server.accessToken)
268
269 const res = await getCustomConfig(server.url, server.accessToken)
270 const data = res.body
271
40e87e9e 272 checkInitialConfig(data)
fd206f0b
C
273 })
274
0e1dc3e7 275 after(async function () {
3cd0734f 276 killallServers([ server ])
0e1dc3e7
C
277 })
278})