aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/server/follows-moderation.ts
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/server/follows-moderation.ts')
-rw-r--r--server/tests/api/server/follows-moderation.ts83
1 files changed, 76 insertions, 7 deletions
diff --git a/server/tests/api/server/follows-moderation.ts b/server/tests/api/server/follows-moderation.ts
index a360706f2..0bb3aa866 100644
--- a/server/tests/api/server/follows-moderation.ts
+++ b/server/tests/api/server/follows-moderation.ts
@@ -3,6 +3,7 @@
3import * as chai from 'chai' 3import * as chai from 'chai'
4import 'mocha' 4import 'mocha'
5import { 5import {
6 acceptFollower,
6 flushAndRunMultipleServers, 7 flushAndRunMultipleServers,
7 killallServers, 8 killallServers,
8 ServerInfo, 9 ServerInfo,
@@ -13,19 +14,21 @@ import {
13 follow, 14 follow,
14 getFollowersListPaginationAndSort, 15 getFollowersListPaginationAndSort,
15 getFollowingListPaginationAndSort, 16 getFollowingListPaginationAndSort,
16 removeFollower 17 removeFollower,
18 rejectFollower
17} from '../../../../shared/utils/server/follows' 19} from '../../../../shared/utils/server/follows'
18import { waitJobs } from '../../../../shared/utils/server/jobs' 20import { waitJobs } from '../../../../shared/utils/server/jobs'
19import { ActorFollow } from '../../../../shared/models/actors' 21import { ActorFollow } from '../../../../shared/models/actors'
20 22
21const expect = chai.expect 23const expect = chai.expect
22 24
23async function checkHasFollowers (servers: ServerInfo[]) { 25async function checkServer1And2HasFollowers (servers: ServerInfo[], state = 'accepted') {
24 { 26 {
25 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt') 27 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
26 expect(res.body.total).to.equal(1) 28 expect(res.body.total).to.equal(1)
27 29
28 const follow = res.body.data[0] as ActorFollow 30 const follow = res.body.data[0] as ActorFollow
31 expect(follow.state).to.equal(state)
29 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') 32 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
30 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') 33 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
31 } 34 }
@@ -35,6 +38,7 @@ async function checkHasFollowers (servers: ServerInfo[]) {
35 expect(res.body.total).to.equal(1) 38 expect(res.body.total).to.equal(1)
36 39
37 const follow = res.body.data[0] as ActorFollow 40 const follow = res.body.data[0] as ActorFollow
41 expect(follow.state).to.equal(state)
38 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube') 42 expect(follow.follower.url).to.equal('http://localhost:9001/accounts/peertube')
39 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube') 43 expect(follow.following.url).to.equal('http://localhost:9002/accounts/peertube')
40 } 44 }
@@ -58,7 +62,7 @@ describe('Test follows moderation', function () {
58 before(async function () { 62 before(async function () {
59 this.timeout(30000) 63 this.timeout(30000)
60 64
61 servers = await flushAndRunMultipleServers(2) 65 servers = await flushAndRunMultipleServers(3)
62 66
63 // Get the access tokens 67 // Get the access tokens
64 await setAccessTokensToServers(servers) 68 await setAccessTokensToServers(servers)
@@ -73,7 +77,7 @@ describe('Test follows moderation', function () {
73 }) 77 })
74 78
75 it('Should have correct follows', async function () { 79 it('Should have correct follows', async function () {
76 await checkHasFollowers(servers) 80 await checkServer1And2HasFollowers(servers)
77 }) 81 })
78 82
79 it('Should remove follower on server 2', async function () { 83 it('Should remove follower on server 2', async function () {
@@ -90,7 +94,8 @@ describe('Test follows moderation', function () {
90 const subConfig = { 94 const subConfig = {
91 followers: { 95 followers: {
92 instance: { 96 instance: {
93 enabled: false 97 enabled: false,
98 manualApproval: false
94 } 99 }
95 } 100 }
96 } 101 }
@@ -107,7 +112,8 @@ describe('Test follows moderation', function () {
107 const subConfig = { 112 const subConfig = {
108 followers: { 113 followers: {
109 instance: { 114 instance: {
110 enabled: true 115 enabled: true,
116 manualApproval: false
111 } 117 }
112 } 118 }
113 } 119 }
@@ -117,7 +123,70 @@ describe('Test follows moderation', function () {
117 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken) 123 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
118 await waitJobs(servers) 124 await waitJobs(servers)
119 125
120 await checkHasFollowers(servers) 126 await checkServer1And2HasFollowers(servers)
127 })
128
129 it('Should manually approve followers', async function () {
130 this.timeout(20000)
131
132 await removeFollower(servers[1].url, servers[1].accessToken, servers[0])
133 await waitJobs(servers)
134
135 const subConfig = {
136 followers: {
137 instance: {
138 enabled: true,
139 manualApproval: true
140 }
141 }
142 }
143
144 await updateCustomSubConfig(servers[1].url, servers[1].accessToken, subConfig)
145 await updateCustomSubConfig(servers[2].url, servers[2].accessToken, subConfig)
146
147 await follow(servers[0].url, [ servers[1].url ], servers[0].accessToken)
148 await waitJobs(servers)
149
150 await checkServer1And2HasFollowers(servers, 'pending')
151 })
152
153 it('Should accept a follower', async function () {
154 await acceptFollower(servers[1].url, servers[1].accessToken, 'peertube@localhost:9001')
155 await waitJobs(servers)
156
157 await checkServer1And2HasFollowers(servers)
158 })
159
160 it('Should reject another follower', async function () {
161 this.timeout(20000)
162
163 await follow(servers[0].url, [ servers[2].url ], servers[0].accessToken)
164 await waitJobs(servers)
165
166 {
167 const res = await getFollowingListPaginationAndSort(servers[0].url, 0, 5, 'createdAt')
168 expect(res.body.total).to.equal(2)
169 }
170
171 {
172 const res = await getFollowersListPaginationAndSort(servers[1].url, 0, 5, 'createdAt')
173 expect(res.body.total).to.equal(1)
174 }
175
176 {
177 const res = await getFollowersListPaginationAndSort(servers[2].url, 0, 5, 'createdAt')
178 expect(res.body.total).to.equal(1)
179 }
180
181 await rejectFollower(servers[2].url, servers[2].accessToken, 'peertube@localhost:9001')
182 await waitJobs(servers)
183
184 await checkServer1And2HasFollowers(servers)
185
186 {
187 const res = await getFollowersListPaginationAndSort(servers[ 2 ].url, 0, 5, 'createdAt')
188 expect(res.body.total).to.equal(0)
189 }
121 }) 190 })
122 191
123 after(async function () { 192 after(async function () {