]>
Commit | Line | Data |
---|---|---|
0e1dc3e7 C |
1 | /* tslint:disable:no-unused-expression */ |
2 | ||
3 | import 'mocha' | |
4 | import * as chai from 'chai' | |
09cababd C |
5 | import { About } from '../../../../shared/models/server/about.model' |
6 | import { CustomConfig } from '../../../../shared/models/server/custom-config.model' | |
36f9424f | 7 | import { deleteCustomConfig, getAbout, killallServers, reRunServer } from '../../utils' |
0e1dc3e7 C |
8 | const expect = chai.expect |
9 | ||
10 | import { | |
11 | getConfig, | |
12 | flushTests, | |
13 | runServer, | |
fd206f0b | 14 | registerUser, getCustomConfig, setAccessTokensToServers, updateCustomConfig |
c5d31dba | 15 | } from '../../utils/index' |
0e1dc3e7 C |
16 | |
17 | describe('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 | |
fd206f0b C |
65 | expect(data.cache.previews.size).to.equal(1) |
66 | expect(data.signup.enabled).to.be.true | |
67 | expect(data.signup.limit).to.equal(4) | |
68 | expect(data.admin.email).to.equal('admin1@example.com') | |
69 | expect(data.user.videoQuota).to.equal(5242880) | |
70 | expect(data.transcoding.enabled).to.be.false | |
71 | expect(data.transcoding.threads).to.equal(2) | |
72 | expect(data.transcoding.resolutions['240p']).to.be.true | |
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.true | |
76 | expect(data.transcoding.resolutions['1080p']).to.be.true | |
77 | }) | |
78 | ||
79 | it('Should update the customized configuration', async function () { | |
80 | const newCustomConfig = { | |
66b16caf C |
81 | instance: { |
82 | name: 'PeerTube updated', | |
2e3a0215 | 83 | shortDescription: 'my short description', |
66b16caf | 84 | description: 'my super description', |
00b5556c | 85 | terms: 'my super terms', |
901637bb | 86 | defaultClientRoute: '/videos/recently-added', |
0883b324 | 87 | defaultNSFWPolicy: 'blur' as 'blur', |
00b5556c C |
88 | customizations: { |
89 | javascript: 'alert("coucou")', | |
90 | css: 'body { background-color: red; }' | |
91 | } | |
66b16caf | 92 | }, |
fd206f0b C |
93 | cache: { |
94 | previews: { | |
95 | size: 2 | |
96 | } | |
97 | }, | |
98 | signup: { | |
99 | enabled: false, | |
100 | limit: 5 | |
101 | }, | |
102 | admin: { | |
103 | email: 'superadmin1@example.com' | |
104 | }, | |
105 | user: { | |
106 | videoQuota: 5242881 | |
107 | }, | |
108 | transcoding: { | |
109 | enabled: true, | |
110 | threads: 1, | |
111 | resolutions: { | |
112 | '240p': false, | |
113 | '360p': true, | |
114 | '480p': true, | |
115 | '720p': false, | |
116 | '1080p': false | |
117 | } | |
118 | } | |
119 | } | |
120 | await updateCustomConfig(server.url, server.accessToken, newCustomConfig) | |
121 | ||
122 | const res = await getCustomConfig(server.url, server.accessToken) | |
123 | const data = res.body | |
124 | ||
66b16caf | 125 | expect(data.instance.name).to.equal('PeerTube updated') |
2e3a0215 | 126 | expect(data.instance.shortDescription).to.equal('my short description') |
66b16caf C |
127 | expect(data.instance.description).to.equal('my super description') |
128 | expect(data.instance.terms).to.equal('my super terms') | |
901637bb | 129 | expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') |
0883b324 | 130 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') |
00b5556c C |
131 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') |
132 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') | |
36f9424f | 133 | expect(data.cache.previews.size).to.equal(2) |
fd206f0b C |
134 | expect(data.signup.enabled).to.be.false |
135 | expect(data.signup.limit).to.equal(5) | |
136 | expect(data.admin.email).to.equal('superadmin1@example.com') | |
137 | expect(data.user.videoQuota).to.equal(5242881) | |
138 | expect(data.transcoding.enabled).to.be.true | |
139 | expect(data.transcoding.threads).to.equal(1) | |
140 | expect(data.transcoding.resolutions['240p']).to.be.false | |
141 | expect(data.transcoding.resolutions['360p']).to.be.true | |
142 | expect(data.transcoding.resolutions['480p']).to.be.true | |
143 | expect(data.transcoding.resolutions['720p']).to.be.false | |
144 | expect(data.transcoding.resolutions['1080p']).to.be.false | |
145 | }) | |
146 | ||
147 | it('Should have the configuration updated after a restart', async function () { | |
23e27dd5 C |
148 | this.timeout(10000) |
149 | ||
fd206f0b C |
150 | killallServers([ server ]) |
151 | ||
152 | await reRunServer(server) | |
153 | ||
154 | const res = await getCustomConfig(server.url, server.accessToken) | |
155 | const data = res.body | |
156 | ||
36f9424f | 157 | expect(data.instance.name).to.equal('PeerTube updated') |
2e3a0215 | 158 | expect(data.instance.shortDescription).to.equal('my short description') |
36f9424f C |
159 | expect(data.instance.description).to.equal('my super description') |
160 | expect(data.instance.terms).to.equal('my super terms') | |
901637bb | 161 | expect(data.instance.defaultClientRoute).to.equal('/videos/recently-added') |
0883b324 | 162 | expect(data.instance.defaultNSFWPolicy).to.equal('blur') |
00b5556c C |
163 | expect(data.instance.customizations.javascript).to.equal('alert("coucou")') |
164 | expect(data.instance.customizations.css).to.equal('body { background-color: red; }') | |
fd206f0b C |
165 | expect(data.cache.previews.size).to.equal(2) |
166 | expect(data.signup.enabled).to.be.false | |
167 | expect(data.signup.limit).to.equal(5) | |
168 | expect(data.admin.email).to.equal('superadmin1@example.com') | |
169 | expect(data.user.videoQuota).to.equal(5242881) | |
170 | expect(data.transcoding.enabled).to.be.true | |
171 | expect(data.transcoding.threads).to.equal(1) | |
172 | expect(data.transcoding.resolutions['240p']).to.be.false | |
173 | expect(data.transcoding.resolutions['360p']).to.be.true | |
174 | expect(data.transcoding.resolutions['480p']).to.be.true | |
175 | expect(data.transcoding.resolutions['720p']).to.be.false | |
176 | expect(data.transcoding.resolutions['1080p']).to.be.false | |
177 | }) | |
178 | ||
36f9424f C |
179 | it('Should fetch the about information', async function () { |
180 | const res = await getAbout(server.url) | |
181 | const data: About = res.body | |
182 | ||
183 | expect(data.instance.name).to.equal('PeerTube updated') | |
2e3a0215 | 184 | expect(data.instance.shortDescription).to.equal('my short description') |
36f9424f C |
185 | expect(data.instance.description).to.equal('my super description') |
186 | expect(data.instance.terms).to.equal('my super terms') | |
187 | }) | |
188 | ||
fd206f0b | 189 | it('Should remove the custom configuration', async function () { |
23e27dd5 C |
190 | this.timeout(10000) |
191 | ||
fd206f0b C |
192 | await deleteCustomConfig(server.url, server.accessToken) |
193 | ||
194 | const res = await getCustomConfig(server.url, server.accessToken) | |
195 | const data = res.body | |
196 | ||
00b5556c | 197 | expect(data.instance.name).to.equal('PeerTube') |
2e3a0215 C |
198 | expect(data.instance.shortDescription).to.equal( |
199 | 'PeerTube, a federated (ActivityPub) video streaming platform using P2P (BitTorrent) directly in the web browser ' + | |
200 | 'with WebTorrent and Angular.' | |
201 | ) | |
00b5556c C |
202 | expect(data.instance.description).to.equal('Welcome to this PeerTube instance!') |
203 | expect(data.instance.terms).to.equal('No terms for now.') | |
901637bb | 204 | expect(data.instance.defaultClientRoute).to.equal('/videos/trending') |
0883b324 | 205 | expect(data.instance.defaultNSFWPolicy).to.equal('display') |
00b5556c C |
206 | expect(data.instance.customizations.css).to.be.empty |
207 | expect(data.instance.customizations.javascript).to.be.empty | |
fd206f0b C |
208 | expect(data.cache.previews.size).to.equal(1) |
209 | expect(data.signup.enabled).to.be.true | |
210 | expect(data.signup.limit).to.equal(4) | |
211 | expect(data.admin.email).to.equal('admin1@example.com') | |
212 | expect(data.user.videoQuota).to.equal(5242880) | |
213 | expect(data.transcoding.enabled).to.be.false | |
214 | expect(data.transcoding.threads).to.equal(2) | |
215 | expect(data.transcoding.resolutions['240p']).to.be.true | |
216 | expect(data.transcoding.resolutions['360p']).to.be.true | |
217 | expect(data.transcoding.resolutions['480p']).to.be.true | |
218 | expect(data.transcoding.resolutions['720p']).to.be.true | |
219 | expect(data.transcoding.resolutions['1080p']).to.be.true | |
220 | }) | |
221 | ||
0e1dc3e7 C |
222 | after(async function () { |
223 | process.kill(-server.app.pid) | |
224 | ||
225 | // Keep the logs if the test failed | |
226 | if (this['ok']) { | |
227 | await flushTests() | |
228 | } | |
229 | }) | |
230 | }) |