]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/api/server/config.ts
Reorganize imports
[github/Chocobozzz/PeerTube.git] / server / tests / api / server / config.ts
index 55cf2a1b86fe684729027051b8c825cd016dc8b7..fd61e95df2d9060a16b426fba9c85f9a17a5712d 100644 (file)
@@ -2,24 +2,20 @@
 
 import 'mocha'
 import * as chai from 'chai'
-import { HttpStatusCode } from '@shared/core-utils'
 import {
   cleanupTests,
-  flushAndRunServer,
+  createSingleServer,
   killallServers,
   makeGetRequest,
   parallelTests,
-  registerUser,
-  reRunServer,
-  ServerInfo,
-  setAccessTokensToServers,
-  uploadVideo
+  PeerTubeServer,
+  setAccessTokensToServers
 } from '@shared/extra-utils'
-import { CustomConfig } from '@shared/models'
+import { CustomConfig, HttpStatusCode } from '@shared/models'
 
 const expect = chai.expect
 
-function checkInitialConfig (server: ServerInfo, data: CustomConfig) {
+function checkInitialConfig (server: PeerTubeServer, data: CustomConfig) {
   expect(data.instance.name).to.equal('PeerTube')
   expect(data.instance.shortDescription).to.equal(
     'PeerTube, an ActivityPub-federated video streaming platform using P2P directly in your web browser.'
@@ -206,17 +202,17 @@ function checkUpdatedConfig (data: CustomConfig) {
 }
 
 describe('Test config', function () {
-  let server: ServerInfo = null
+  let server: PeerTubeServer = null
 
   before(async function () {
     this.timeout(30000)
 
-    server = await flushAndRunServer(1)
+    server = await createSingleServer(1)
     await setAccessTokensToServers([ server ])
   })
 
   it('Should have a correct config on a server with registration enabled', async function () {
-    const data = await server.configCommand.getConfig()
+    const data = await server.config.getConfig()
 
     expect(data.signup.allowed).to.be.true
   })
@@ -225,32 +221,32 @@ describe('Test config', function () {
     this.timeout(5000)
 
     await Promise.all([
-      registerUser(server.url, 'user1', 'super password'),
-      registerUser(server.url, 'user2', 'super password'),
-      registerUser(server.url, 'user3', 'super password')
+      server.users.register({ username: 'user1' }),
+      server.users.register({ username: 'user2' }),
+      server.users.register({ username: 'user3' })
     ])
 
-    const data = await server.configCommand.getConfig()
+    const data = await server.config.getConfig()
 
     expect(data.signup.allowed).to.be.false
   })
 
   it('Should have the correct video allowed extensions', async function () {
-    const data = await server.configCommand.getConfig()
+    const data = await server.config.getConfig()
 
     expect(data.video.file.extensions).to.have.lengthOf(3)
     expect(data.video.file.extensions).to.contain('.mp4')
     expect(data.video.file.extensions).to.contain('.webm')
     expect(data.video.file.extensions).to.contain('.ogv')
 
-    await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
-    await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415)
+    await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
+    await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.UNSUPPORTED_MEDIA_TYPE_415 })
 
     expect(data.contactForm.enabled).to.be.true
   })
 
   it('Should get the customized configuration', async function () {
-    const data = await server.configCommand.getCustomConfig()
+    const data = await server.config.getCustomConfig()
 
     checkInitialConfig(server, data)
   })
@@ -427,16 +423,16 @@ describe('Test config', function () {
         }
       }
     }
-    await server.configCommand.updateCustomConfig({ newCustomConfig })
+    await server.config.updateCustomConfig({ newCustomConfig })
 
-    const data = await server.configCommand.getCustomConfig()
+    const data = await server.config.getCustomConfig()
     checkUpdatedConfig(data)
   })
 
   it('Should have the correct updated video allowed extensions', async function () {
     this.timeout(10000)
 
-    const data = await server.configCommand.getConfig()
+    const data = await server.config.getConfig()
 
     expect(data.video.file.extensions).to.have.length.above(4)
     expect(data.video.file.extensions).to.contain('.mp4')
@@ -449,8 +445,8 @@ describe('Test config', function () {
     expect(data.video.file.extensions).to.contain('.ogg')
     expect(data.video.file.extensions).to.contain('.flac')
 
-    await uploadVideo(server.url, server.accessToken, { fixture: 'video_short.mkv' }, HttpStatusCode.OK_200)
-    await uploadVideo(server.url, server.accessToken, { fixture: 'sample.ogg' }, HttpStatusCode.OK_200)
+    await server.videos.upload({ attributes: { fixture: 'video_short.mkv' }, expectedStatus: HttpStatusCode.OK_200 })
+    await server.videos.upload({ attributes: { fixture: 'sample.ogg' }, expectedStatus: HttpStatusCode.OK_200 })
   })
 
   it('Should have the configuration updated after a restart', async function () {
@@ -458,15 +454,15 @@ describe('Test config', function () {
 
     await killallServers([ server ])
 
-    await reRunServer(server)
+    await server.run()
 
-    const data = await server.configCommand.getCustomConfig()
+    const data = await server.config.getCustomConfig()
 
     checkUpdatedConfig(data)
   })
 
   it('Should fetch the about information', async function () {
-    const data = await server.configCommand.getAbout()
+    const data = await server.config.getAbout()
 
     expect(data.instance.name).to.equal('PeerTube updated')
     expect(data.instance.shortDescription).to.equal('my short description')
@@ -488,9 +484,9 @@ describe('Test config', function () {
   it('Should remove the custom configuration', async function () {
     this.timeout(10000)
 
-    await server.configCommand.deleteCustomConfig()
+    await server.config.deleteCustomConfig()
 
-    const data = await server.configCommand.getCustomConfig()
+    const data = await server.config.getCustomConfig()
     checkInitialConfig(server, data)
   })
 
@@ -501,7 +497,7 @@ describe('Test config', function () {
       const res = await makeGetRequest({
         url: server.url,
         path: '/api/v1/config',
-        statusCodeExpected: 200
+        expectedStatus: 200
       })
 
       expect(res.headers['x-frame-options']).to.exist
@@ -514,13 +510,13 @@ describe('Test config', function () {
         frameguard: { enabled: false }
       }
     }
-    server = await reRunServer(server, config)
+    await server.run(config)
 
     {
       const res = await makeGetRequest({
         url: server.url,
         path: '/api/v1/config',
-        statusCodeExpected: 200
+        expectedStatus: 200
       })
 
       expect(res.headers['x-frame-options']).to.not.exist