1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { removeAccountFromServerBlocklist } from '@shared/extra-utils/users/blocklist'
11 setAccessTokensToServers,
15 } from '../../../shared/extra-utils'
18 flushAndRunMultipleServers,
22 } from '../../../shared/extra-utils/server/servers'
24 describe('Official plugin auto-mute', function () {
25 let servers: ServerInfo[]
26 let blocklistServer: MockBlocklist
28 before(async function () {
31 servers = await flushAndRunMultipleServers(2)
32 await setAccessTokensToServers(servers)
36 accessToken: servers[0].accessToken,
37 npmName: 'peertube-plugin-auto-mute'
40 blocklistServer = new MockBlocklist()
41 await blocklistServer.initialize()
43 await uploadVideoAndGetId({ server: servers[0], videoName: 'video server 1' })
44 await uploadVideoAndGetId({ server: servers[1], videoName: 'video server 2' })
46 await doubleFollow(servers[0], servers[1])
49 it('Should update plugin settings', async function () {
50 await updatePluginSettings({
52 accessToken: servers[0].accessToken,
53 npmName: 'peertube-plugin-auto-mute',
55 'blocklist-urls': 'http://localhost:42100/blocklist',
56 'check-seconds-interval': 1
61 it('Should add a server blocklist', async function () {
64 blocklistServer.replace({
67 value: 'localhost:' + servers[1].port
74 const res = await getVideosList(servers[0].url)
75 expect(res.body.total).to.equal(1)
78 it('Should remove a server blocklist', async function () {
81 blocklistServer.replace({
84 value: 'localhost:' + servers[1].port,
92 const res = await getVideosList(servers[0].url)
93 expect(res.body.total).to.equal(2)
96 it('Should add an account blocklist', async function () {
99 blocklistServer.replace({
102 value: 'root@localhost:' + servers[1].port
109 const res = await getVideosList(servers[0].url)
110 expect(res.body.total).to.equal(1)
113 it('Should remove an account blocklist', async function () {
116 blocklistServer.replace({
119 value: 'root@localhost:' + servers[1].port,
127 const res = await getVideosList(servers[0].url)
128 expect(res.body.total).to.equal(2)
131 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
134 const account = 'root@localhost:' + servers[1].port
136 blocklistServer.replace({
140 updatedAt: new Date().toISOString()
148 const res = await getVideosList(servers[0].url)
149 expect(res.body.total).to.equal(1)
152 await removeAccountFromServerBlocklist(servers[0].url, servers[0].accessToken, account)
155 const res = await getVideosList(servers[0].url)
156 expect(res.body.total).to.equal(2)
159 killallServers([ servers[0] ])
160 await reRunServer(servers[0])
164 const res = await getVideosList(servers[0].url)
165 expect(res.body.total).to.equal(2)
169 after(async function () {
170 await cleanupTests(servers)