]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blobdiff - server/tests/external-plugins/auto-mute.ts
Merge branch 'release/5.0.0' into develop
[github/Chocobozzz/PeerTube.git] / server / tests / external-plugins / auto-mute.ts
index 81a96744e10f7ba7dd064b4beb5b669d7968a274..cfed76e8856c7a2931bd66b842a4f3e2beb2bd8a 100644 (file)
@@ -1,51 +1,49 @@
 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
 
-import 'mocha'
 import { expect } from 'chai'
-import { HttpStatusCode } from '@shared/core-utils'
+import { wait } from '@shared/core-utils'
+import { HttpStatusCode } from '@shared/models'
 import {
   cleanupTests,
+  createMultipleServers,
   doubleFollow,
-  flushAndRunMultipleServers,
   killallServers,
   makeGetRequest,
-  MockBlocklist,
-  reRunServer,
-  ServerInfo,
-  setAccessTokensToServers,
-  wait
-} from '@shared/extra-utils'
+  PeerTubeServer,
+  setAccessTokensToServers
+} from '@shared/server-commands'
+import { MockBlocklist } from '../shared'
 
 describe('Official plugin auto-mute', function () {
   const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
-  let servers: ServerInfo[]
+  let servers: PeerTubeServer[]
   let blocklistServer: MockBlocklist
   let port: number
 
   before(async function () {
-    this.timeout(30000)
+    this.timeout(120000)
 
-    servers = await flushAndRunMultipleServers(2)
+    servers = await createMultipleServers(2)
     await setAccessTokensToServers(servers)
 
     for (const server of servers) {
-      await server.pluginsCommand.install({ npmName: 'peertube-plugin-auto-mute' })
+      await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
     }
 
     blocklistServer = new MockBlocklist()
     port = await blocklistServer.initialize()
 
-    await await servers[0].videosCommand.quickUpload({ name: 'video server 1' })
-    await await servers[1].videosCommand.quickUpload({ name: 'video server 2' })
+    await servers[0].videos.quickUpload({ name: 'video server 1' })
+    await servers[1].videos.quickUpload({ name: 'video server 2' })
 
     await doubleFollow(servers[0], servers[1])
   })
 
   it('Should update plugin settings', async function () {
-    await servers[0].pluginsCommand.updateSettings({
+    await servers[0].plugins.updateSettings({
       npmName: 'peertube-plugin-auto-mute',
       settings: {
-        'blocklist-urls': `http://localhost:${port}/blocklist`,
+        'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
         'check-seconds-interval': 1
       }
     })
@@ -57,14 +55,14 @@ describe('Official plugin auto-mute', function () {
     blocklistServer.replace({
       data: [
         {
-          value: 'localhost:' + servers[1].port
+          value: servers[1].host
         }
       ]
     })
 
     await wait(2000)
 
-    const { total } = await servers[0].videosCommand.list()
+    const { total } = await servers[0].videos.list()
     expect(total).to.equal(1)
   })
 
@@ -74,7 +72,7 @@ describe('Official plugin auto-mute', function () {
     blocklistServer.replace({
       data: [
         {
-          value: 'localhost:' + servers[1].port,
+          value: servers[1].host,
           action: 'remove'
         }
       ]
@@ -82,7 +80,7 @@ describe('Official plugin auto-mute', function () {
 
     await wait(2000)
 
-    const { total } = await servers[0].videosCommand.list()
+    const { total } = await servers[0].videos.list()
     expect(total).to.equal(2)
   })
 
@@ -92,14 +90,14 @@ describe('Official plugin auto-mute', function () {
     blocklistServer.replace({
       data: [
         {
-          value: 'root@localhost:' + servers[1].port
+          value: 'root@' + servers[1].host
         }
       ]
     })
 
     await wait(2000)
 
-    const { total } = await servers[0].videosCommand.list()
+    const { total } = await servers[0].videos.list()
     expect(total).to.equal(1)
   })
 
@@ -109,7 +107,7 @@ describe('Official plugin auto-mute', function () {
     blocklistServer.replace({
       data: [
         {
-          value: 'root@localhost:' + servers[1].port,
+          value: 'root@' + servers[1].host,
           action: 'remove'
         }
       ]
@@ -117,14 +115,14 @@ describe('Official plugin auto-mute', function () {
 
     await wait(2000)
 
-    const { total } = await servers[0].videosCommand.list()
+    const { total } = await servers[0].videos.list()
     expect(total).to.equal(2)
   })
 
   it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
     this.timeout(20000)
 
-    const account = 'root@localhost:' + servers[1].port
+    const account = 'root@' + servers[1].host
 
     blocklistServer.replace({
       data: [
@@ -138,23 +136,23 @@ describe('Official plugin auto-mute', function () {
     await wait(2000)
 
     {
-      const { total } = await servers[0].videosCommand.list()
+      const { total } = await servers[0].videos.list()
       expect(total).to.equal(1)
     }
 
-    await servers[0].blocklistCommand.removeFromServerBlocklist({ account })
+    await servers[0].blocklist.removeFromServerBlocklist({ account })
 
     {
-      const { total } = await servers[0].videosCommand.list()
+      const { total } = await servers[0].videos.list()
       expect(total).to.equal(2)
     }
 
     await killallServers([ servers[0] ])
-    await reRunServer(servers[0])
+    await servers[0].run()
     await wait(2000)
 
     {
-      const { total } = await servers[0].videosCommand.list()
+      const { total } = await servers[0].videos.list()
       expect(total).to.equal(2)
     }
   })
@@ -163,12 +161,12 @@ describe('Official plugin auto-mute', function () {
     await makeGetRequest({
       url: servers[0].url,
       path: '/plugins/auto-mute/router/api/v1/mute-list',
-      statusCodeExpected: HttpStatusCode.FORBIDDEN_403
+      expectedStatus: HttpStatusCode.FORBIDDEN_403
     })
   })
 
   it('Should enable auto mute list', async function () {
-    await servers[0].pluginsCommand.updateSettings({
+    await servers[0].plugins.updateSettings({
       npmName: 'peertube-plugin-auto-mute',
       settings: {
         'blocklist-urls': '',
@@ -180,40 +178,40 @@ describe('Official plugin auto-mute', function () {
     await makeGetRequest({
       url: servers[0].url,
       path: '/plugins/auto-mute/router/api/v1/mute-list',
-      statusCodeExpected: HttpStatusCode.OK_200
+      expectedStatus: HttpStatusCode.OK_200
     })
   })
 
   it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
     this.timeout(20000)
 
-    await servers[1].pluginsCommand.updateSettings({
+    await servers[1].plugins.updateSettings({
       npmName: 'peertube-plugin-auto-mute',
       settings: {
-        'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
+        'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
         'check-seconds-interval': 1,
         'expose-mute-list': false
       }
     })
 
-    await servers[0].blocklistCommand.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
-    await servers[0].blocklistCommand.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
+    await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
+    await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
 
     const res = await makeGetRequest({
       url: servers[0].url,
       path: '/plugins/auto-mute/router/api/v1/mute-list',
-      statusCodeExpected: HttpStatusCode.OK_200
+      expectedStatus: HttpStatusCode.OK_200
     })
 
     const data = res.body.data
     expect(data).to.have.lengthOf(1)
     expect(data[0].updatedAt).to.exist
-    expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
+    expect(data[0].value).to.equal('root@' + servers[1].host)
 
     await wait(2000)
 
     for (const server of servers) {
-      const { total } = await server.videosCommand.list()
+      const { total } = await server.videos.list()
       expect(total).to.equal(1)
     }
   })