aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api')
-rw-r--r--server/tests/api/check-params/config.ts5
-rw-r--r--server/tests/api/check-params/users-admin.ts12
-rw-r--r--server/tests/api/server/config-defaults.ts78
-rw-r--r--server/tests/api/server/config.ts7
4 files changed, 90 insertions, 12 deletions
diff --git a/server/tests/api/check-params/config.ts b/server/tests/api/check-params/config.ts
index 93a3f3eb9..f49a4b868 100644
--- a/server/tests/api/check-params/config.ts
+++ b/server/tests/api/check-params/config.ts
@@ -90,6 +90,11 @@ describe('Test config API validators', function () {
90 enabled: false 90 enabled: false
91 }, 91 },
92 user: { 92 user: {
93 history: {
94 videos: {
95 enabled: true
96 }
97 },
93 videoQuota: 5242881, 98 videoQuota: 5242881,
94 videoQuotaDaily: 318742 99 videoQuotaDaily: 318742
95 }, 100 },
diff --git a/server/tests/api/check-params/users-admin.ts b/server/tests/api/check-params/users-admin.ts
index be2496bb4..819da0bb2 100644
--- a/server/tests/api/check-params/users-admin.ts
+++ b/server/tests/api/check-params/users-admin.ts
@@ -216,18 +216,6 @@ describe('Test users admin API validators', function () {
216 }) 216 })
217 }) 217 })
218 218
219 it('Should fail without a videoQuota', async function () {
220 const fields = omit(baseCorrectParams, [ 'videoQuota' ])
221
222 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
223 })
224
225 it('Should fail without a videoQuotaDaily', async function () {
226 const fields = omit(baseCorrectParams, [ 'videoQuotaDaily' ])
227
228 await makePostBodyRequest({ url: server.url, path, token: server.accessToken, fields })
229 })
230
231 it('Should fail with an invalid videoQuota', async function () { 219 it('Should fail with an invalid videoQuota', async function () {
232 const fields = { ...baseCorrectParams, videoQuota: -5 } 220 const fields = { ...baseCorrectParams, videoQuota: -5 }
233 221
diff --git a/server/tests/api/server/config-defaults.ts b/server/tests/api/server/config-defaults.ts
index d3b3a2447..041032f2b 100644
--- a/server/tests/api/server/config-defaults.ts
+++ b/server/tests/api/server/config-defaults.ts
@@ -204,6 +204,84 @@ describe('Test config defaults', function () {
204 }) 204 })
205 }) 205 })
206 206
207 describe('Default user attributes', function () {
208 it('Should create a user and register a user with the default config', async function () {
209 await server.config.updateCustomSubConfig({
210 newConfig: {
211 user: {
212 history: {
213 videos: {
214 enabled: true
215 }
216 },
217 videoQuota : -1,
218 videoQuotaDaily: -1
219 },
220 signup: {
221 enabled: true,
222 requiresApproval: false
223 }
224 }
225 })
226
227 const config = await server.config.getConfig()
228
229 expect(config.user.videoQuota).to.equal(-1)
230 expect(config.user.videoQuotaDaily).to.equal(-1)
231
232 const user1Token = await server.users.generateUserAndToken('user1')
233 const user1 = await server.users.getMyInfo({ token: user1Token })
234
235 const user = { displayName: 'super user 2', username: 'user2', password: 'super password' }
236 const channel = { name: 'my_user_2_channel', displayName: 'my channel' }
237 await server.registrations.register({ ...user, channel })
238 const user2Token = await server.login.getAccessToken(user)
239 const user2 = await server.users.getMyInfo({ token: user2Token })
240
241 for (const user of [ user1, user2 ]) {
242 expect(user.videosHistoryEnabled).to.be.true
243 expect(user.videoQuota).to.equal(-1)
244 expect(user.videoQuotaDaily).to.equal(-1)
245 }
246 })
247
248 it('Should update config and create a user and register a user with the new default config', async function () {
249 await server.config.updateCustomSubConfig({
250 newConfig: {
251 user: {
252 history: {
253 videos: {
254 enabled: false
255 }
256 },
257 videoQuota : 5242881,
258 videoQuotaDaily: 318742
259 },
260 signup: {
261 enabled: true,
262 requiresApproval: false
263 }
264 }
265 })
266
267 const user3Token = await server.users.generateUserAndToken('user3')
268 const user3 = await server.users.getMyInfo({ token: user3Token })
269
270 const user = { displayName: 'super user 4', username: 'user4', password: 'super password' }
271 const channel = { name: 'my_user_4_channel', displayName: 'my channel' }
272 await server.registrations.register({ ...user, channel })
273 const user4Token = await server.login.getAccessToken(user)
274 const user4 = await server.users.getMyInfo({ token: user4Token })
275
276 for (const user of [ user3, user4 ]) {
277 expect(user.videosHistoryEnabled).to.be.false
278 expect(user.videoQuota).to.equal(5242881)
279 expect(user.videoQuotaDaily).to.equal(318742)
280 }
281 })
282
283 })
284
207 after(async function () { 285 after(async function () {
208 await cleanupTests([ server ]) 286 await cleanupTests([ server ])
209 }) 287 })
diff --git a/server/tests/api/server/config.ts b/server/tests/api/server/config.ts
index de7c2f6e2..3683c4ae1 100644
--- a/server/tests/api/server/config.ts
+++ b/server/tests/api/server/config.ts
@@ -56,6 +56,7 @@ function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
56 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com') 56 expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
57 expect(data.contactForm.enabled).to.be.true 57 expect(data.contactForm.enabled).to.be.true
58 58
59 expect(data.user.history.videos.enabled).to.be.true
59 expect(data.user.videoQuota).to.equal(5242880) 60 expect(data.user.videoQuota).to.equal(5242880)
60 expect(data.user.videoQuotaDaily).to.equal(-1) 61 expect(data.user.videoQuotaDaily).to.equal(-1)
61 62
@@ -164,6 +165,7 @@ function checkUpdatedConfig (data: CustomConfig) {
164 165
165 expect(data.contactForm.enabled).to.be.false 166 expect(data.contactForm.enabled).to.be.false
166 167
168 expect(data.user.history.videos.enabled).to.be.false
167 expect(data.user.videoQuota).to.equal(5242881) 169 expect(data.user.videoQuota).to.equal(5242881)
168 expect(data.user.videoQuotaDaily).to.equal(318742) 170 expect(data.user.videoQuotaDaily).to.equal(318742)
169 171
@@ -298,6 +300,11 @@ const newCustomConfig: CustomConfig = {
298 enabled: false 300 enabled: false
299 }, 301 },
300 user: { 302 user: {
303 history: {
304 videos: {
305 enabled: false
306 }
307 },
301 videoQuota: 5242881, 308 videoQuota: 5242881,
302 videoQuotaDaily: 318742 309 videoQuotaDaily: 318742
303 }, 310 },