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