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