]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/api/server/config.ts
Add esperanto, lojban, klingon and kotava (audio/subtitle) languages
[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, 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 describe('Test config', function () {
73 let server = null
74
75 before(async function () {
76 this.timeout(30000)
77
78 await flushTests()
79 server = await runServer(1)
80 await setAccessTokensToServers([ server ])
81 })
82
83 it('Should have a correct config on a server with registration enabled', async function () {
84 const res = await getConfig(server.url)
85 const data = res.body
86
87 expect(data.signup.allowed).to.be.true
88 })
89
90 it('Should have a correct config on a server with registration enabled and a users limit', async function () {
91 this.timeout(5000)
92
93 await Promise.all([
94 registerUser(server.url, 'user1', 'super password'),
95 registerUser(server.url, 'user2', 'super password'),
96 registerUser(server.url, 'user3', 'super password')
97 ])
98
99 const res = await getConfig(server.url)
100 const data = res.body
101
102 expect(data.signup.allowed).to.be.false
103 })
104
105 it('Should get the customized configuration', async function () {
106 const res = await getCustomConfig(server.url, server.accessToken)
107 const data = res.body as CustomConfig
108
109 checkInitialConfig(data)
110 })
111
112 it('Should update the customized configuration', async function () {
113 const newCustomConfig: CustomConfig = {
114 instance: {
115 name: 'PeerTube updated',
116 shortDescription: 'my short description',
117 description: 'my super description',
118 terms: 'my super terms',
119 defaultClientRoute: '/videos/recently-added',
120 defaultNSFWPolicy: 'blur' as 'blur',
121 customizations: {
122 javascript: 'alert("coucou")',
123 css: 'body { background-color: red; }'
124 }
125 },
126 services: {
127 twitter: {
128 username: '@Kuja',
129 whitelisted: true
130 }
131 },
132 cache: {
133 previews: {
134 size: 2
135 },
136 captions: {
137 size: 3
138 }
139 },
140 signup: {
141 enabled: false,
142 limit: 5
143 },
144 admin: {
145 email: 'superadmin1@example.com'
146 },
147 user: {
148 videoQuota: 5242881
149 },
150 transcoding: {
151 enabled: true,
152 threads: 1,
153 resolutions: {
154 '240p': false,
155 '360p': true,
156 '480p': true,
157 '720p': false,
158 '1080p': false
159 }
160 }
161 }
162 await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
163
164 const res = await getCustomConfig(server.url, server.accessToken)
165 const data = res.body
166
167 checkUpdatedConfig(data)
168 })
169
170 it('Should have the configuration updated after a restart', async function () {
171 this.timeout(10000)
172
173 killallServers([ server ])
174
175 await reRunServer(server)
176
177 const res = await getCustomConfig(server.url, server.accessToken)
178 const data = res.body
179
180 checkUpdatedConfig(data)
181 })
182
183 it('Should fetch the about information', async function () {
184 const res = await getAbout(server.url)
185 const data: About = res.body
186
187 expect(data.instance.name).to.equal('PeerTube updated')
188 expect(data.instance.shortDescription).to.equal('my short description')
189 expect(data.instance.description).to.equal('my super description')
190 expect(data.instance.terms).to.equal('my super terms')
191 })
192
193 it('Should remove the custom configuration', async function () {
194 this.timeout(10000)
195
196 await deleteCustomConfig(server.url, server.accessToken)
197
198 const res = await getCustomConfig(server.url, server.accessToken)
199 const data = res.body
200
201 checkInitialConfig(data)
202 })
203
204 after(async function () {
205 killallServers([ server ])
206 })
207 })