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