]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame_incremental - server/tests/api/server/config.ts
Add ability to remove an instance follower in API
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
... / ...
CommitLineData
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5import { About } from '../../../../shared/models/server/about.model'
6import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
7import {
8 deleteCustomConfig,
9 getAbout,
10 killallServers,
11 reRunServer,
12 flushTests,
13 getConfig,
14 getCustomConfig,
15 registerUser,
16 runServer,
17 setAccessTokensToServers,
18 updateCustomConfig
19} from '../../../../shared/utils'
20import { ServerConfig } from '../../../../shared/models'
21
22const expect = chai.expect
23
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.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
37
38 expect(data.services.twitter.username).to.equal('@Chocobozzz')
39 expect(data.services.twitter.whitelisted).to.be.false
40
41 expect(data.cache.previews.size).to.equal(1)
42 expect(data.cache.captions.size).to.equal(1)
43
44 expect(data.signup.enabled).to.be.true
45 expect(data.signup.limit).to.equal(4)
46 expect(data.signup.requiresEmailVerification).to.be.false
47
48 expect(data.admin.email).to.equal('admin1@example.com')
49 expect(data.contactForm.enabled).to.be.true
50
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
62
63 expect(data.import.videos.http.enabled).to.be.true
64 expect(data.import.videos.torrent.enabled).to.be.true
65 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.false
66}
67
68function checkUpdatedConfig (data: CustomConfig) {
69 expect(data.instance.name).to.equal('PeerTube updated')
70 expect(data.instance.shortDescription).to.equal('my short description')
71 expect(data.instance.description).to.equal('my super description')
72 expect(data.instance.terms).to.equal('my super terms')
73 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
74 expect(data.instance.isNSFW).to.be.true
75 expect(data.instance.defaultNSFWPolicy).to.equal('blur')
76 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
77 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
78
79 expect(data.services.twitter.username).to.equal('@Kuja')
80 expect(data.services.twitter.whitelisted).to.be.true
81
82 expect(data.cache.previews.size).to.equal(2)
83 expect(data.cache.captions.size).to.equal(3)
84
85 expect(data.signup.enabled).to.be.false
86 expect(data.signup.limit).to.equal(5)
87 expect(data.signup.requiresEmailVerification).to.be.false
88
89 expect(data.admin.email).to.equal('superadmin1@example.com')
90 expect(data.contactForm.enabled).to.be.false
91
92 expect(data.user.videoQuota).to.equal(5242881)
93 expect(data.user.videoQuotaDaily).to.equal(318742)
94
95 expect(data.transcoding.enabled).to.be.true
96 expect(data.transcoding.threads).to.equal(1)
97 expect(data.transcoding.allowAdditionalExtensions).to.be.true
98 expect(data.transcoding.resolutions['240p']).to.be.false
99 expect(data.transcoding.resolutions['360p']).to.be.true
100 expect(data.transcoding.resolutions['480p']).to.be.true
101 expect(data.transcoding.resolutions['720p']).to.be.false
102 expect(data.transcoding.resolutions['1080p']).to.be.false
103 expect(data.transcoding.hls.enabled).to.be.false
104
105 expect(data.import.videos.http.enabled).to.be.false
106 expect(data.import.videos.torrent.enabled).to.be.false
107 expect(data.autoBlacklist.videos.ofUsers.enabled).to.be.true
108}
109
110describe('Test config', function () {
111 let server = null
112
113 before(async function () {
114 this.timeout(30000)
115
116 await flushTests()
117 server = await runServer(1)
118 await setAccessTokensToServers([ server ])
119 })
120
121 it('Should have a correct config on a server with registration enabled', async function () {
122 const res = await getConfig(server.url)
123 const data: ServerConfig = res.body
124
125 expect(data.signup.allowed).to.be.true
126 })
127
128 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
129 this.timeout(5000)
130
131 await Promise.all([
132 registerUser(server.url, 'user1', 'super password'),
133 registerUser(server.url, 'user2', 'super password'),
134 registerUser(server.url, 'user3', 'super password')
135 ])
136
137 const res = await getConfig(server.url)
138 const data: ServerConfig = res.body
139
140 expect(data.signup.allowed).to.be.false
141 })
142
143 it('Should have the correct video allowed extensions', async function () {
144 const res = await getConfig(server.url)
145 const data: ServerConfig = res.body
146
147 expect(data.video.file.extensions).to.have.lengthOf(3)
148 expect(data.video.file.extensions).to.contain('.mp4')
149 expect(data.video.file.extensions).to.contain('.webm')
150 expect(data.video.file.extensions).to.contain('.ogv')
151
152 expect(data.contactForm.enabled).to.be.true
153 })
154
155 it('Should get the customized configuration', async function () {
156 const res = await getCustomConfig(server.url, server.accessToken)
157 const data = res.body as CustomConfig
158
159 checkInitialConfig(data)
160 })
161
162 it('Should update the customized configuration', async function () {
163 const newCustomConfig: CustomConfig = {
164 instance: {
165 name: 'PeerTube updated',
166 shortDescription: 'my short description',
167 description: 'my super description',
168 terms: 'my super terms',
169 defaultClientRoute: '/videos/recently-added',
170 isNSFW: true,
171 defaultNSFWPolicy: 'blur' as 'blur',
172 customizations: {
173 javascript: 'alert("coucou")',
174 css: 'body { background-color: red; }'
175 }
176 },
177 services: {
178 twitter: {
179 username: '@Kuja',
180 whitelisted: true
181 }
182 },
183 cache: {
184 previews: {
185 size: 2
186 },
187 captions: {
188 size: 3
189 }
190 },
191 signup: {
192 enabled: false,
193 limit: 5,
194 requiresEmailVerification: false
195 },
196 admin: {
197 email: 'superadmin1@example.com'
198 },
199 contactForm: {
200 enabled: false
201 },
202 user: {
203 videoQuota: 5242881,
204 videoQuotaDaily: 318742
205 },
206 transcoding: {
207 enabled: true,
208 allowAdditionalExtensions: true,
209 threads: 1,
210 resolutions: {
211 '240p': false,
212 '360p': true,
213 '480p': true,
214 '720p': false,
215 '1080p': false
216 },
217 hls: {
218 enabled: false
219 }
220 },
221 import: {
222 videos: {
223 http: {
224 enabled: false
225 },
226 torrent: {
227 enabled: false
228 }
229 }
230 },
231 autoBlacklist: {
232 videos: {
233 ofUsers: {
234 enabled: true
235 }
236 }
237 }
238 }
239 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
240
241 const res = await getCustomConfig(server.url, server.accessToken)
242 const data = res.body
243
244 checkUpdatedConfig(data)
245 })
246
247 it('Should have the correct updated video allowed extensions', async function () {
248 const res = await getConfig(server.url)
249 const data: ServerConfig = res.body
250
251 expect(data.video.file.extensions).to.have.length.above(3)
252 expect(data.video.file.extensions).to.contain('.mp4')
253 expect(data.video.file.extensions).to.contain('.webm')
254 expect(data.video.file.extensions).to.contain('.ogv')
255 expect(data.video.file.extensions).to.contain('.flv')
256 expect(data.video.file.extensions).to.contain('.mkv')
257 })
258
259 it('Should have the configuration updated after a restart', async function () {
260 this.timeout(10000)
261
262 killallServers([ server ])
263
264 await reRunServer(server)
265
266 const res = await getCustomConfig(server.url, server.accessToken)
267 const data = res.body
268
269 checkUpdatedConfig(data)
270 })
271
272 it('Should fetch the about information', async function () {
273 const res = await getAbout(server.url)
274 const data: About = res.body
275
276 expect(data.instance.name).to.equal('PeerTube updated')
277 expect(data.instance.shortDescription).to.equal('my short description')
278 expect(data.instance.description).to.equal('my super description')
279 expect(data.instance.terms).to.equal('my super terms')
280 })
281
282 it('Should remove the custom configuration', async function () {
283 this.timeout(10000)
284
285 await deleteCustomConfig(server.url, server.accessToken)
286
287 const res = await getCustomConfig(server.url, server.accessToken)
288 const data = res.body
289
290 checkInitialConfig(data)
291 })
292
293 after(async function () {
294 killallServers([ server ])
295 })
296})