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