Add test for auto mute list router
This commit is contained in:
parent
60c8b8a5d7
commit
3a7a261f33
|
@ -2,11 +2,16 @@
|
||||||
|
|
||||||
import 'mocha'
|
import 'mocha'
|
||||||
import { expect } from 'chai'
|
import { expect } from 'chai'
|
||||||
import { removeAccountFromServerBlocklist } from '@shared/extra-utils/users/blocklist'
|
import {
|
||||||
|
addAccountToServerBlocklist,
|
||||||
|
addServerToAccountBlocklist,
|
||||||
|
removeAccountFromServerBlocklist
|
||||||
|
} from '@shared/extra-utils/users/blocklist'
|
||||||
import {
|
import {
|
||||||
doubleFollow,
|
doubleFollow,
|
||||||
getVideosList,
|
getVideosList,
|
||||||
installPlugin,
|
installPlugin,
|
||||||
|
makeGetRequest,
|
||||||
MockBlocklist,
|
MockBlocklist,
|
||||||
setAccessTokensToServers,
|
setAccessTokensToServers,
|
||||||
updatePluginSettings,
|
updatePluginSettings,
|
||||||
|
@ -22,6 +27,7 @@ import {
|
||||||
} from '../../../shared/extra-utils/server/servers'
|
} from '../../../shared/extra-utils/server/servers'
|
||||||
|
|
||||||
describe('Official plugin auto-mute', function () {
|
describe('Official plugin auto-mute', function () {
|
||||||
|
const autoMuteListPath = '/plugins/auto-mute/router/api/v1/mute-list'
|
||||||
let servers: ServerInfo[]
|
let servers: ServerInfo[]
|
||||||
let blocklistServer: MockBlocklist
|
let blocklistServer: MockBlocklist
|
||||||
|
|
||||||
|
@ -31,11 +37,13 @@ describe('Official plugin auto-mute', function () {
|
||||||
servers = await flushAndRunMultipleServers(2)
|
servers = await flushAndRunMultipleServers(2)
|
||||||
await setAccessTokensToServers(servers)
|
await setAccessTokensToServers(servers)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
await installPlugin({
|
await installPlugin({
|
||||||
url: servers[0].url,
|
url: server.url,
|
||||||
accessToken: servers[0].accessToken,
|
accessToken: server.accessToken,
|
||||||
npmName: 'peertube-plugin-auto-mute'
|
npmName: 'peertube-plugin-auto-mute'
|
||||||
})
|
})
|
||||||
|
}
|
||||||
|
|
||||||
blocklistServer = new MockBlocklist()
|
blocklistServer = new MockBlocklist()
|
||||||
await blocklistServer.initialize()
|
await blocklistServer.initialize()
|
||||||
|
@ -166,6 +174,69 @@ describe('Official plugin auto-mute', function () {
|
||||||
}
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
|
it('Should not expose the auto mute list', async function () {
|
||||||
|
await makeGetRequest({
|
||||||
|
url: servers[0].url,
|
||||||
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
||||||
|
statusCodeExpected: 403
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should enable auto mute list', async function () {
|
||||||
|
await updatePluginSettings({
|
||||||
|
url: servers[0].url,
|
||||||
|
accessToken: servers[0].accessToken,
|
||||||
|
npmName: 'peertube-plugin-auto-mute',
|
||||||
|
settings: {
|
||||||
|
'blocklist-urls': '',
|
||||||
|
'check-seconds-interval': 1,
|
||||||
|
'expose-mute-list': true
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await makeGetRequest({
|
||||||
|
url: servers[0].url,
|
||||||
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
||||||
|
statusCodeExpected: 200
|
||||||
|
})
|
||||||
|
})
|
||||||
|
|
||||||
|
it('Should mute an account on server 1, and server 2 auto mutes it', async function () {
|
||||||
|
this.timeout(20000)
|
||||||
|
|
||||||
|
await updatePluginSettings({
|
||||||
|
url: servers[1].url,
|
||||||
|
accessToken: servers[1].accessToken,
|
||||||
|
npmName: 'peertube-plugin-auto-mute',
|
||||||
|
settings: {
|
||||||
|
'blocklist-urls': 'http://localhost:' + servers[0].port + autoMuteListPath,
|
||||||
|
'check-seconds-interval': 1,
|
||||||
|
'expose-mute-list': false
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
|
await addAccountToServerBlocklist(servers[0].url, servers[0].accessToken, 'root@localhost:' + servers[1].port)
|
||||||
|
await addServerToAccountBlocklist(servers[0].url, servers[0].accessToken, 'localhost:' + servers[1].port)
|
||||||
|
|
||||||
|
const res = await makeGetRequest({
|
||||||
|
url: servers[0].url,
|
||||||
|
path: '/plugins/auto-mute/router/api/v1/mute-list',
|
||||||
|
statusCodeExpected: 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)
|
||||||
|
|
||||||
|
await wait(2000)
|
||||||
|
|
||||||
|
for (const server of servers) {
|
||||||
|
const res = await getVideosList(server.url)
|
||||||
|
expect(res.body.total).to.equal(1)
|
||||||
|
}
|
||||||
|
})
|
||||||
|
|
||||||
after(async function () {
|
after(async function () {
|
||||||
await cleanupTests(servers)
|
await cleanupTests(servers)
|
||||||
})
|
})
|
||||||
|
|
|
@ -1,2 +1,2 @@
|
||||||
export * from './auth-ldap'
|
import './auth-ldap'
|
||||||
export * from './auto-mute'
|
import './auto-mute'
|
||||||
|
|
Loading…
Reference in New Issue