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