]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/config.ts
Introduce server commands
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
index 1d9ea31df442bbca17480ecc05bab420b4c1055e..55cf2a1b86fe684729027051b8c825cd016dc8b7 100644 (file)
@@ -2,15 +2,10 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { About } from '../../../../shared/models/server/about.model'
-import { CustomConfig } from '../../../../shared/models/server/custom-config.model'
+import { HttpStatusCode } from '@shared/core-utils'
 import {
   cleanupTests,
-  deleteCustomConfig,
   flushAndRunServer,
-  getAbout,
-  getConfig,
-  getCustomConfig,
   killallServers,
   makeGetRequest,
   parallelTests,
@@ -18,11 +13,9 @@ import {
   reRunServer,
   ServerInfo,
   setAccessTokensToServers,
-  updateCustomConfig,
   uploadVideo
-} from '../../../../shared/extra-utils'
-import { ServerConfig } from '../../../../shared/models'
-import { HttpStatusCode } from '../../../../shared/core-utils/miscs/http-error-codes'
+} from '@shared/extra-utils'
+import { CustomConfig } from '@shared/models'
 
 const expect = chai.expect
 
@@ -60,6 +53,7 @@ function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
 
   expect(data.signup.enabled).to.be.true
   expect(data.signup.limit).to.equal(4)
+  expect(data.signup.minimumAge).to.equal(16)
   expect(data.signup.requiresEmailVerification).to.be.false
 
   expect(data.admin.email).to.equal('admin' + server.internalServerNumber + '@example.com')
@@ -151,6 +145,7 @@ function checkUpdatedConfig (data: CustomConfig) {
   expect(data.signup.enabled).to.be.false
   expect(data.signup.limit).to.equal(5)
   expect(data.signup.requiresEmailVerification).to.be.false
+  expect(data.signup.minimumAge).to.equal(10)
 
   // We override admin email in parallel tests, so skip this exception
   if (parallelTests() === false) {
@@ -211,7 +206,7 @@ function checkUpdatedConfig (data: CustomConfig) {
 }
 
 describe('Test config', function () {
-  let server = null
+  let server: ServerInfo = null
 
   before(async function () {
     this.timeout(30000)
@@ -221,8 +216,7 @@ describe('Test config', function () {
   })
 
   it('Should have a correct config on a server with registration enabled', async function () {
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.signup.allowed).to.be.true
   })
@@ -236,15 +230,13 @@ describe('Test config', function () {
       registerUser(server.url, 'user3', 'super password')
     ])
 
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.signup.allowed).to.be.false
   })
 
   it('Should have the correct video allowed extensions', async function () {
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.video.file.extensions).to.have.lengthOf(3)
     expect(data.video.file.extensions).to.contain('.mp4')
@@ -258,8 +250,7 @@ describe('Test config', function () {
   })
 
   it('Should get the customized configuration', async function () {
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body as CustomConfig
+    const data = await server.configCommand.getCustomConfig()
 
     checkInitialConfig(server, data)
   })
@@ -316,7 +307,8 @@ describe('Test config', function () {
       signup: {
         enabled: false,
         limit: 5,
-        requiresEmailVerification: false
+        requiresEmailVerification: false,
+        minimumAge: 10
       },
       admin: {
         email: 'superadmin1@example.com'
@@ -435,19 +427,16 @@ describe('Test config', function () {
         }
       }
     }
-    await updateCustomConfig(server.url, server.accessToken, newCustomConfig)
-
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body
+    await server.configCommand.updateCustomConfig({ newCustomConfig })
 
+    const data = await server.configCommand.getCustomConfig()
     checkUpdatedConfig(data)
   })
 
   it('Should have the correct updated video allowed extensions', async function () {
     this.timeout(10000)
 
-    const res = await getConfig(server.url)
-    const data: ServerConfig = res.body
+    const data = await server.configCommand.getConfig()
 
     expect(data.video.file.extensions).to.have.length.above(4)
     expect(data.video.file.extensions).to.contain('.mp4')
@@ -467,19 +456,17 @@ describe('Test config', function () {
   it('Should have the configuration updated after a restart', async function () {
     this.timeout(10000)
 
-    killallServers([ server ])
+    await killallServers([ server ])
 
     await reRunServer(server)
 
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body
+    const data = await server.configCommand.getCustomConfig()
 
     checkUpdatedConfig(data)
   })
 
   it('Should fetch the about information', async function () {
-    const res = await getAbout(server.url)
-    const data: About = res.body
+    const data = await server.configCommand.getAbout()
 
     expect(data.instance.name).to.equal('PeerTube updated')
     expect(data.instance.shortDescription).to.equal('my short description')
@@ -501,11 +488,9 @@ describe('Test config', function () {
   it('Should remove the custom configuration', async function () {
     this.timeout(10000)
 
-    await deleteCustomConfig(server.url, server.accessToken)
-
-    const res = await getCustomConfig(server.url, server.accessToken)
-    const data = res.body
+    await server.configCommand.deleteCustomConfig()
 
+    const data = await server.configCommand.getCustomConfig()
     checkInitialConfig(server, data)
   })
 
@@ -522,7 +507,7 @@ describe('Test config', function () {
       expect(res.headers['x-frame-options']).to.exist
     }
 
-    killallServers([ server ])
+    await killallServers([ server ])
 
     const config = {
       security: {