X-Git-Url: https://git.immae.eu/?a=blobdiff_plain;f=server%2Ftests%2Fapi%2Fserver%2Ffollows-moderation.ts;h=45e56518a2196713c033153e3af8fe5bd56b7336;hb=7b97127e8ba718d673b8a43afa964d136723e6a2;hp=deeaac85a0859b5b51d680f2ef26a2c9172dc531;hpb=863477173efa82a4412d2e522aa46462249f9199;p=github%2FChocobozzz%2FPeerTube.git diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts index deeaac85a..45e56518a 100644 --- a/server/tests/api/server/follows-moderation.ts +++ b/server/tests/api/server/follows-moderation.ts @@ -96,247 +96,273 @@ describe('Test follows moderation', function () { commands = servers.map(s => s.follows) }) - it('Should have server 1 following server 2', async function () { - this.timeout(30000) + describe('Default behaviour', function () { - await commands[0].follow({ hosts: [ servers[1].url ] }) + it('Should have server 1 following server 2', async function () { + this.timeout(30000) - await waitJobs(servers) - }) + await commands[0].follow({ hosts: [ servers[1].url ] }) - it('Should have correct follows', async function () { - await checkServer1And2HasFollowers(servers) - }) + await waitJobs(servers) + }) - it('Should remove follower on server 2', async function () { - this.timeout(10000) + it('Should have correct follows', async function () { + await checkServer1And2HasFollowers(servers) + }) - await commands[1].removeFollower({ follower: servers[0] }) + it('Should remove follower on server 2', async function () { + this.timeout(10000) - await waitJobs(servers) - }) + await commands[1].removeFollower({ follower: servers[0] }) - it('Should not not have follows anymore', async function () { - await checkNoFollowers(servers) + await waitJobs(servers) + }) + + it('Should not not have follows anymore', async function () { + await checkNoFollowers(servers) + }) }) - it('Should disable followers on server 2', async function () { - this.timeout(10000) + describe('Disabled/Enabled followers', function () { - const subConfig = { - followers: { - instance: { - enabled: false, - manualApproval: false + it('Should disable followers on server 2', async function () { + this.timeout(10000) + + const subConfig = { + followers: { + instance: { + enabled: false, + manualApproval: false + } } } - } - await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await commands[0].follow({ hosts: [ servers[1].url ] }) - await waitJobs(servers) + await commands[0].follow({ hosts: [ servers[1].url ] }) + await waitJobs(servers) - await checkNoFollowers(servers) - }) + await checkNoFollowers(servers) + }) - it('Should re enable followers on server 2', async function () { - this.timeout(10000) + it('Should re enable followers on server 2', async function () { + this.timeout(10000) - const subConfig = { - followers: { - instance: { - enabled: true, - manualApproval: false + const subConfig = { + followers: { + instance: { + enabled: true, + manualApproval: false + } } } - } - await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await commands[0].follow({ hosts: [ servers[1].url ] }) - await waitJobs(servers) + await commands[0].follow({ hosts: [ servers[1].url ] }) + await waitJobs(servers) - await checkServer1And2HasFollowers(servers) + await checkServer1And2HasFollowers(servers) + }) }) - it('Should manually approve followers', async function () { - this.timeout(20000) + describe('Manual approbation', function () { + + it('Should manually approve followers', async function () { + this.timeout(20000) - await commands[0].unfollow({ target: servers[1] }) - await waitJobs(servers) + await commands[0].unfollow({ target: servers[1] }) + await waitJobs(servers) - const subConfig = { - followers: { - instance: { - enabled: true, - manualApproval: true + const subConfig = { + followers: { + instance: { + enabled: true, + manualApproval: true + } } } - } - - await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) - await servers[2].config.updateCustomSubConfig({ newConfig: subConfig }) - - await commands[0].follow({ hosts: [ servers[1].url ] }) - await waitJobs(servers) - - await checkServer1And2HasFollowers(servers, 'pending') - }) - - it('Should accept a follower', async function () { - this.timeout(10000) - await commands[1].acceptFollower({ follower: 'peertube@' + servers[0].host }) - await waitJobs(servers) + await servers[1].config.updateCustomSubConfig({ newConfig: subConfig }) + await servers[2].config.updateCustomSubConfig({ newConfig: subConfig }) - await checkServer1And2HasFollowers(servers) - }) + await commands[0].follow({ hosts: [ servers[1].url ] }) + await waitJobs(servers) - it('Should reject another follower', async function () { - this.timeout(20000) + await checkServer1And2HasFollowers(servers, 'pending') + }) - await commands[0].follow({ hosts: [ servers[2].url ] }) - await waitJobs(servers) + it('Should accept a follower', async function () { + this.timeout(10000) - { - const body = await commands[0].getFollowings() - expect(body.total).to.equal(2) - } + await commands[1].acceptFollower({ follower: 'peertube@' + servers[0].host }) + await waitJobs(servers) - { - const body = await commands[1].getFollowers() - expect(body.total).to.equal(1) - } + await checkServer1And2HasFollowers(servers) + }) - { - const body = await commands[2].getFollowers() - expect(body.total).to.equal(1) - } + it('Should reject another follower', async function () { + this.timeout(20000) - await commands[2].rejectFollower({ follower: 'peertube@' + servers[0].host }) - await waitJobs(servers) + await commands[0].follow({ hosts: [ servers[2].url ] }) + await waitJobs(servers) - { // server 1 { - const { data } = await commands[0].getFollowings({ state: 'accepted' }) - expect(data).to.have.lengthOf(1) + const body = await commands[0].getFollowings() + expect(body.total).to.equal(2) } { - const { data } = await commands[0].getFollowings({ state: 'rejected' }) - expect(data).to.have.lengthOf(1) - expectStartWith(data[0].following.url, servers[2].url) + const body = await commands[1].getFollowers() + expect(body.total).to.equal(1) } - } - { // server 3 { - const { data } = await commands[2].getFollowers({ state: 'accepted' }) - expect(data).to.have.lengthOf(0) + const body = await commands[2].getFollowers() + expect(body.total).to.equal(1) } - { - const { data } = await commands[2].getFollowers({ state: 'rejected' }) - expect(data).to.have.lengthOf(1) - expectStartWith(data[0].follower.url, servers[0].url) + await commands[2].rejectFollower({ follower: 'peertube@' + servers[0].host }) + await waitJobs(servers) + + { // server 1 + { + const { data } = await commands[0].getFollowings({ state: 'accepted' }) + expect(data).to.have.lengthOf(1) + } + + { + const { data } = await commands[0].getFollowings({ state: 'rejected' }) + expect(data).to.have.lengthOf(1) + expectStartWith(data[0].following.url, servers[2].url) + } } - } + + { // server 3 + { + const { data } = await commands[2].getFollowers({ state: 'accepted' }) + expect(data).to.have.lengthOf(0) + } + + { + const { data } = await commands[2].getFollowers({ state: 'rejected' }) + expect(data).to.have.lengthOf(1) + expectStartWith(data[0].follower.url, servers[0].url) + } + } + }) + + it('Should still auto accept channel followers', async function () { + await commands[0].follow({ handles: [ 'root_channel@' + servers[1].host ] }) + + await waitJobs(servers) + + const body = await commands[0].getFollowings() + const follow = body.data[0] + expect(follow.following.name).to.equal('root_channel') + expect(follow.state).to.equal('accepted') + }) }) - it('Should not change the follow on refollow with and without auto accept', async function () { - const run = async () => { - await commands[0].follow({ hosts: [ servers[2].url ] }) + describe('Accept/reject state', function () { + + it('Should not change the follow on refollow with and without auto accept', async function () { + const run = async () => { + await commands[0].follow({ hosts: [ servers[2].url ] }) + await waitJobs(servers) + + await checkFollows({ + follower: servers[0], + followerState: 'rejected', + following: servers[2], + followingState: 'rejected' + }) + } + + await servers[2].config.updateExistingSubConfig({ newConfig: { followers: { instance: { manualApproval: false } } } }) + await run() + + await servers[2].config.updateExistingSubConfig({ newConfig: { followers: { instance: { manualApproval: true } } } }) + await run() + }) + + it('Should not change the rejected status on unfollow', async function () { + await commands[0].unfollow({ target: servers[2] }) await waitJobs(servers) await checkFollows({ follower: servers[0], - followerState: 'rejected', + followerState: 'deleted', following: servers[2], followingState: 'rejected' }) - } - - await servers[2].config.updateExistingSubConfig({ newConfig: { followers: { instance: { manualApproval: false } } } }) - await run() - - await servers[2].config.updateExistingSubConfig({ newConfig: { followers: { instance: { manualApproval: true } } } }) - await run() - }) - - it('Should not change the rejected status on unfollow', async function () { - await commands[0].unfollow({ target: servers[2] }) - await waitJobs(servers) - - await checkFollows({ - follower: servers[0], - followerState: 'deleted', - following: servers[2], - followingState: 'rejected' }) - }) - it('Should delete the follower and add again the follower', async function () { - await commands[2].removeFollower({ follower: servers[0] }) - await waitJobs(servers) + it('Should delete the follower and add again the follower', async function () { + await commands[2].removeFollower({ follower: servers[0] }) + await waitJobs(servers) - await commands[0].follow({ hosts: [ servers[2].url ] }) - await waitJobs(servers) + await commands[0].follow({ hosts: [ servers[2].url ] }) + await waitJobs(servers) - await checkFollows({ - follower: servers[0], - followerState: 'pending', - following: servers[2], - followingState: 'pending' + await checkFollows({ + follower: servers[0], + followerState: 'pending', + following: servers[2], + followingState: 'pending' + }) }) - }) - it('Should be able to reject a previously accepted follower', async function () { - await commands[1].rejectFollower({ follower: 'peertube@' + servers[0].host }) - await waitJobs(servers) + it('Should be able to reject a previously accepted follower', async function () { + await commands[1].rejectFollower({ follower: 'peertube@' + servers[0].host }) + await waitJobs(servers) - await checkFollows({ - follower: servers[0], - followerState: 'rejected', - following: servers[1], - followingState: 'rejected' + await checkFollows({ + follower: servers[0], + followerState: 'rejected', + following: servers[1], + followingState: 'rejected' + }) }) - }) - it('Should be able to re accept a previously rejected follower', async function () { - await commands[1].acceptFollower({ follower: 'peertube@' + servers[0].host }) - await waitJobs(servers) + it('Should be able to re accept a previously rejected follower', async function () { + await commands[1].acceptFollower({ follower: 'peertube@' + servers[0].host }) + await waitJobs(servers) - await checkFollows({ - follower: servers[0], - followerState: 'accepted', - following: servers[1], - followingState: 'accepted' + await checkFollows({ + follower: servers[0], + followerState: 'accepted', + following: servers[1], + followingState: 'accepted' + }) }) }) - it('Should ignore follow requests of muted servers', async function () { - await servers[1].blocklist.addToServerBlocklist({ server: servers[0].host }) + describe('Muted servers', function () { - await commands[0].unfollow({ target: servers[1] }) + it('Should ignore follow requests of muted servers', async function () { + await servers[1].blocklist.addToServerBlocklist({ server: servers[0].host }) - await waitJobs(servers) + await commands[0].unfollow({ target: servers[1] }) - await checkFollows({ - follower: servers[0], - followerState: 'deleted', - following: servers[1], - followingState: 'deleted' - }) + await waitJobs(servers) + + await checkFollows({ + follower: servers[0], + followerState: 'deleted', + following: servers[1], + followingState: 'deleted' + }) - await commands[0].follow({ hosts: [ servers[1].host ] }) - await waitJobs(servers) + await commands[0].follow({ hosts: [ servers[1].host ] }) + await waitJobs(servers) - await checkFollows({ - follower: servers[0], - followerState: 'rejected', - following: servers[1], - followingState: 'deleted' + await checkFollows({ + follower: servers[0], + followerState: 'rejected', + following: servers[1], + followingState: 'deleted' + }) }) })