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