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