1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
4 import { expect } from 'chai'
5 import { wait } from '@shared/core-utils'
6 import { HttpStatusCode } from '@shared/models'
14 setAccessTokensToServers
15 } from '@shared/server-commands'
16 import { MockBlocklist } from '../shared'
18 describe('Official plugin auto-mute', function () {
19 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
20 let servers: PeerTubeServer[]
21 let blocklistServer: MockBlocklist
24 before(async function () {
27 servers = await createMultipleServers(2)
28 await setAccessTokensToServers(servers)
30 for (const server of servers) {
31 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
34 blocklistServer = new MockBlocklist()
35 port = await blocklistServer.initialize()
37 await servers[0].videos.quickUpload({ name: 'video server 1' })
38 await servers[1].videos.quickUpload({ name: 'video server 2' })
40 await doubleFollow(servers[0], servers[1])
43 it('Should update plugin settings', async function () {
44 await servers[0].plugins.updateSettings({
45 npmName: 'peertube-plugin-auto-mute',
47 'blocklist-urls': `http://localhost:${port}/blocklist`,
48 'check-seconds-interval': 1
53 it('Should add a server blocklist', async function () {
56 blocklistServer.replace({
59 value: 'localhost:' + servers[1].port
66 const { total } = await servers[0].videos.list()
67 expect(total).to.equal(1)
70 it('Should remove a server blocklist', async function () {
73 blocklistServer.replace({
76 value: 'localhost:' + servers[1].port,
84 const { total } = await servers[0].videos.list()
85 expect(total).to.equal(2)
88 it('Should add an account blocklist', async function () {
91 blocklistServer.replace({
94 value: 'root@localhost:' + servers[1].port
101 const { total } = await servers[0].videos.list()
102 expect(total).to.equal(1)
105 it('Should remove an account blocklist', async function () {
108 blocklistServer.replace({
111 value: 'root@localhost:' + servers[1].port,
119 const { total } = await servers[0].videos.list()
120 expect(total).to.equal(2)
123 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
126 const account = 'root@localhost:' + servers[1].port
128 blocklistServer.replace({
132 updatedAt: new Date().toISOString()
140 const { total } = await servers[0].videos.list()
141 expect(total).to.equal(1)
144 await servers[0].blocklist.removeFromServerBlocklist({ account })
147 const { total } = await servers[0].videos.list()
148 expect(total).to.equal(2)
151 await killallServers([ servers[0] ])
152 await servers[0].run()
156 const { total } = await servers[0].videos.list()
157 expect(total).to.equal(2)
161 it('Should not expose the auto mute list', async function () {
162 await makeGetRequest({
164 path: '/plugins/auto-mute/router/api/v1/mute-list',
165 expectedStatus: HttpStatusCode.FORBIDDEN_403
169 it('Should enable auto mute list', async function () {
170 await servers[0].plugins.updateSettings({
171 npmName: 'peertube-plugin-auto-mute',
173 'blocklist-urls': '',
174 'check-seconds-interval': 1,
175 'expose-mute-list': true
179 await makeGetRequest({
181 path: '/plugins/auto-mute/router/api/v1/mute-list',
182 expectedStatus: HttpStatusCode.OK_200
186 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
189 await servers[1].plugins.updateSettings({
190 npmName: 'peertube-plugin-auto-mute',
192 'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
193 'check-seconds-interval': 1,
194 'expose-mute-list': false
198 await servers[0].blocklist.addToServerBlocklist({ account: 'root@localhost:' + servers[1].port })
199 await servers[0].blocklist.addToMyBlocklist({ server: 'localhost:' + servers[1].port })
201 const res = await makeGetRequest({
203 path: '/plugins/auto-mute/router/api/v1/mute-list',
204 expectedStatus: HttpStatusCode.OK_200
207 const data = res.body.data
208 expect(data).to.have.lengthOf(1)
209 expect(data[0].updatedAt).to.exist
210 expect(data[0].value).to.equal('root@localhost:' + servers[1].port)
214 for (const server of servers) {
215 const { total } = await server.videos.list()
216 expect(total).to.equal(1)
220 after(async function () {
221 await blocklistServer.terminate()
223 await cleanupTests(servers)