]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/api/server/config.ts
Add reverse proxy test in travis
[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'
36f9424f 7import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils'
0e1dc3e7
C
8const expect = chai.expect
9
10import {
11 getConfig,
12 flushTests,
13 runServer,
fd206f0b 14 registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig
c5d31dba 15} from '../../utils/index'
0e1dc3e7
C
16
17describe('Test config', function () {
18 let server = null
19
20 before(async function () {
e212f887 21 this.timeout(30000)
0e1dc3e7
C
22
23 await flushTests()
24 server = await runServer(1)
fd206f0b 25 await setAccessTokensToServers([ server ])
0e1dc3e7
C
26 })
27
28 it('Should have a correct config on a server with registration enabled', async function () {
29 const res = await getConfig(server.url)
30 const data = res.body
31
32 expect(data.signup.allowed).to.be.true
33 })
34
35 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
652b3056
C
36 this.timeout(5000)
37
47e0652b
C
38 await Promise.all([
39 registerUser(server.url, 'user1', 'super password'),
40 registerUser(server.url, 'user2', 'super password'),
41 registerUser(server.url, 'user3', 'super password')
42 ])
0e1dc3e7
C
43
44 const res = await getConfig(server.url)
45 const data = res.body
46
47 expect(data.signup.allowed).to.be.false
48 })
49
fd206f0b
C
50 it('Should get the customized configuration', async function () {
51 const res = await getCustomConfig(server.url, server.accessToken)
00b5556c 52 const data = res.body as CustomConfig
fd206f0b 53
66b16caf 54 expect(data.instance.name).to.equal('PeerTube')
2e3a0215
C
55 expect(data.instance.shortDescription).to.equal(
56 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
57 'with WebTorrent and Angular.'
58 )
c4377f4b
C
59 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
60 expect(data.instance.terms).to.equal('No terms for now.')
901637bb 61 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
00b5556c
C
62 expect(data.instance.customizations.css).to.be.empty
63 expect(data.instance.customizations.javascript).to.be.empty
fd206f0b
C
64 expect(data.cache.previews.size).to.equal(1)
65 expect(data.signup.enabled).to.be.true
66 expect(data.signup.limit).to.equal(4)
67 expect(data.admin.email).to.equal('admin1@example.com')
68 expect(data.user.videoQuota).to.equal(5242880)
69 expect(data.transcoding.enabled).to.be.false
70 expect(data.transcoding.threads).to.equal(2)
71 expect(data.transcoding.resolutions['240p']).to.be.true
72 expect(data.transcoding.resolutions['360p']).to.be.true
73 expect(data.transcoding.resolutions['480p']).to.be.true
74 expect(data.transcoding.resolutions['720p']).to.be.true
75 expect(data.transcoding.resolutions['1080p']).to.be.true
76 })
77
78 it('Should update the customized configuration', async function () {
79 const newCustomConfig = {
66b16caf
C
80 instance: {
81 name: 'PeerTube updated',
2e3a0215 82 shortDescription: 'my short description',
66b16caf 83 description: 'my super description',
00b5556c 84 terms: 'my super terms',
901637bb 85 defaultClientRoute: '/videos/recently-added',
00b5556c
C
86 customizations: {
87 javascript: 'alert("coucou")',
88 css: 'body { background-color: red; }'
89 }
66b16caf 90 },
fd206f0b
C
91 cache: {
92 previews: {
93 size: 2
94 }
95 },
96 signup: {
97 enabled: false,
98 limit: 5
99 },
100 admin: {
101 email: 'superadmin1@example.com'
102 },
103 user: {
104 videoQuota: 5242881
105 },
106 transcoding: {
107 enabled: true,
108 threads: 1,
109 resolutions: {
110 '240p': false,
111 '360p': true,
112 '480p': true,
113 '720p': false,
114 '1080p': false
115 }
116 }
117 }
118 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
119
120 const res = await getCustomConfig(server.url, server.accessToken)
121 const data = res.body
122
66b16caf 123 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 124 expect(data.instance.shortDescription).to.equal('my short description')
66b16caf
C
125 expect(data.instance.description).to.equal('my super description')
126 expect(data.instance.terms).to.equal('my super terms')
901637bb 127 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
00b5556c
C
128 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
129 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
36f9424f 130 expect(data.cache.previews.size).to.equal(2)
fd206f0b
C
131 expect(data.signup.enabled).to.be.false
132 expect(data.signup.limit).to.equal(5)
133 expect(data.admin.email).to.equal('superadmin1@example.com')
134 expect(data.user.videoQuota).to.equal(5242881)
135 expect(data.transcoding.enabled).to.be.true
136 expect(data.transcoding.threads).to.equal(1)
137 expect(data.transcoding.resolutions['240p']).to.be.false
138 expect(data.transcoding.resolutions['360p']).to.be.true
139 expect(data.transcoding.resolutions['480p']).to.be.true
140 expect(data.transcoding.resolutions['720p']).to.be.false
141 expect(data.transcoding.resolutions['1080p']).to.be.false
142 })
143
144 it('Should have the configuration updated after a restart', async function () {
23e27dd5
C
145 this.timeout(10000)
146
fd206f0b
C
147 killallServers([ server ])
148
149 await reRunServer(server)
150
151 const res = await getCustomConfig(server.url, server.accessToken)
152 const data = res.body
153
36f9424f 154 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 155 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
156 expect(data.instance.description).to.equal('my super description')
157 expect(data.instance.terms).to.equal('my super terms')
901637bb 158 expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added')
00b5556c
C
159 expect(data.instance.customizations.javascript).to.equal('alert("coucou")')
160 expect(data.instance.customizations.css).to.equal('body { background-color: red; }')
fd206f0b
C
161 expect(data.cache.previews.size).to.equal(2)
162 expect(data.signup.enabled).to.be.false
163 expect(data.signup.limit).to.equal(5)
164 expect(data.admin.email).to.equal('superadmin1@example.com')
165 expect(data.user.videoQuota).to.equal(5242881)
166 expect(data.transcoding.enabled).to.be.true
167 expect(data.transcoding.threads).to.equal(1)
168 expect(data.transcoding.resolutions['240p']).to.be.false
169 expect(data.transcoding.resolutions['360p']).to.be.true
170 expect(data.transcoding.resolutions['480p']).to.be.true
171 expect(data.transcoding.resolutions['720p']).to.be.false
172 expect(data.transcoding.resolutions['1080p']).to.be.false
173 })
174
36f9424f
C
175 it('Should fetch the about information', async function () {
176 const res = await getAbout(server.url)
177 const data: About = res.body
178
179 expect(data.instance.name).to.equal('PeerTube updated')
2e3a0215 180 expect(data.instance.shortDescription).to.equal('my short description')
36f9424f
C
181 expect(data.instance.description).to.equal('my super description')
182 expect(data.instance.terms).to.equal('my super terms')
183 })
184
fd206f0b 185 it('Should remove the custom configuration', async function () {
23e27dd5
C
186 this.timeout(10000)
187
fd206f0b
C
188 await deleteCustomConfig(server.url, server.accessToken)
189
190 const res = await getCustomConfig(server.url, server.accessToken)
191 const data = res.body
192
00b5556c 193 expect(data.instance.name).to.equal('PeerTube')
2e3a0215
C
194 expect(data.instance.shortDescription).to.equal(
195 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' +
196 'with WebTorrent and Angular.'
197 )
00b5556c
C
198 expect(data.instance.description).to.equal('Welcome to this PeerTube instance!')
199 expect(data.instance.terms).to.equal('No terms for now.')
901637bb 200 expect(data.instance.defaultClientRoute).to.equal('/videos/trending')
00b5556c
C
201 expect(data.instance.customizations.css).to.be.empty
202 expect(data.instance.customizations.javascript).to.be.empty
fd206f0b
C
203 expect(data.cache.previews.size).to.equal(1)
204 expect(data.signup.enabled).to.be.true
205 expect(data.signup.limit).to.equal(4)
206 expect(data.admin.email).to.equal('admin1@example.com')
207 expect(data.user.videoQuota).to.equal(5242880)
208 expect(data.transcoding.enabled).to.be.false
209 expect(data.transcoding.threads).to.equal(2)
210 expect(data.transcoding.resolutions['240p']).to.be.true
211 expect(data.transcoding.resolutions['360p']).to.be.true
212 expect(data.transcoding.resolutions['480p']).to.be.true
213 expect(data.transcoding.resolutions['720p']).to.be.true
214 expect(data.transcoding.resolutions['1080p']).to.be.true
215 })
216
0e1dc3e7
C
217 after(async function () {
218 process.kill(-server.app.pid)
219
220 // Keep the logs if the test failed
221 if (this['ok']) {
222 await flushTests()
223 }
224 })
225})