1 /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */
3 import { expect } from 'chai'
4 import { wait } from '@shared/core-utils'
5 import { HttpStatusCode } from '@shared/models'
13 setAccessTokensToServers
14 } from '@shared/server-commands'
15 import { MockBlocklist } from '../shared'
17 describe('Official plugin auto-mute', function () {
18 const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
19 let servers: PeerTubeServer[]
20 let blocklistServer: MockBlocklist
23 before(async function () {
26 servers = await createMultipleServers(2)
27 await setAccessTokensToServers(servers)
29 for (const server of servers) {
30 await server.plugins.install({ npmName: 'peertube-plugin-auto-mute' })
33 blocklistServer = new MockBlocklist()
34 port = await blocklistServer.initialize()
36 await servers[0].videos.quickUpload({ name: 'video server 1' })
37 await servers[1].videos.quickUpload({ name: 'video server 2' })
39 await doubleFollow(servers[0], servers[1])
42 it('Should update plugin settings', async function () {
43 await servers[0].plugins.updateSettings({
44 npmName: 'peertube-plugin-auto-mute',
46 'blocklist-urls': `http://127.0.0.1:${port}/blocklist`,
47 'check-seconds-interval': 1
52 it('Should add a server blocklist', async function () {
53 blocklistServer.replace({
56 value: servers[1].host
63 const { total } = await servers[0].videos.list()
64 expect(total).to.equal(1)
67 it('Should remove a server blocklist', async function () {
68 blocklistServer.replace({
71 value: servers[1].host,
79 const { total } = await servers[0].videos.list()
80 expect(total).to.equal(2)
83 it('Should add an account blocklist', async function () {
84 blocklistServer.replace({
87 value: 'root@' + servers[1].host
94 const { total } = await servers[0].videos.list()
95 expect(total).to.equal(1)
98 it('Should remove an account blocklist', async function () {
99 blocklistServer.replace({
102 value: 'root@' + servers[1].host,
110 const { total } = await servers[0].videos.list()
111 expect(total).to.equal(2)
114 it('Should auto mute an account, manually unmute it and do not remute it automatically', async function () {
117 const account = 'root@' + servers[1].host
119 blocklistServer.replace({
123 updatedAt: new Date().toISOString()
131 const { total } = await servers[0].videos.list()
132 expect(total).to.equal(1)
135 await servers[0].blocklist.removeFromServerBlocklist({ account })
138 const { total } = await servers[0].videos.list()
139 expect(total).to.equal(2)
142 await killallServers([ servers[0] ])
143 await servers[0].run()
147 const { total } = await servers[0].videos.list()
148 expect(total).to.equal(2)
152 it('Should not expose the auto mute list', async function () {
153 await makeGetRequest({
155 path: '/plugins/auto-mute/router/api/v1/mute-list',
156 expectedStatus: HttpStatusCode.FORBIDDEN_403
160 it('Should enable auto mute list', async function () {
161 await servers[0].plugins.updateSettings({
162 npmName: 'peertube-plugin-auto-mute',
164 'blocklist-urls': '',
165 'check-seconds-interval': 1,
166 'expose-mute-list': true
170 await makeGetRequest({
172 path: '/plugins/auto-mute/router/api/v1/mute-list',
173 expectedStatus: HttpStatusCode.OK_200
177 it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
180 await servers[1].plugins.updateSettings({
181 npmName: 'peertube-plugin-auto-mute',
183 'blocklist-urls': 'http://' + servers[0].host + autoMuteListPath,
184 'check-seconds-interval': 1,
185 'expose-mute-list': false
189 await servers[0].blocklist.addToServerBlocklist({ account: 'root@' + servers[1].host })
190 await servers[0].blocklist.addToMyBlocklist({ server: servers[1].host })
192 const res = await makeGetRequest({
194 path: '/plugins/auto-mute/router/api/v1/mute-list',
195 expectedStatus: HttpStatusCode.OK_200
198 const data = res.body.data
199 expect(data).to.have.lengthOf(1)
200 expect(data[0].updatedAt).to.exist
201 expect(data[0].value).to.equal('root@' + servers[1].host)
205 for (const server of servers) {
206 const { total } = await server.videos.list()
207 expect(total).to.equal(1)
211 after(async function () {
212 await blocklistServer.terminate()
214 await cleanupTests(servers)