+async function checkServer1And2HasFollowers (servers: PeerTubeServer[], state = 'accepted') {
+ const fns = [
+ servers[0].follows.getFollowings.bind(servers[0].follows),
+ servers[1].follows.getFollowers.bind(servers[1].follows)
+ ]
+
+ for (const fn of fns) {
+ const body = await fn({ start: 0, count: 5, sort: 'createdAt' })
+ expect(body.total).to.equal(1)
+
+ const follow = body.data[0]
+ expect(follow.state).to.equal(state)
+ expect(follow.follower.url).to.equal(servers[0].url + '/accounts/peertube')
+ expect(follow.following.url).to.equal(servers[1].url + '/accounts/peertube')
+ }
+}
+
+async function checkFollows (options: {
+ follower: PeerTubeServer
+ followerState: FollowState | 'deleted'
+
+ following: PeerTubeServer
+ followingState: FollowState | 'deleted'
+}) {
+ const { follower, followerState, followingState, following } = options
+
+ const followerUrl = follower.url + '/accounts/peertube'
+ const followingUrl = following.url + '/accounts/peertube'
+ const finder = (d: ActorFollow) => d.follower.url === followerUrl && d.following.url === followingUrl
+
+ {
+ const { data } = await follower.follows.getFollowings()
+ const follow = data.find(finder)
+
+ if (followerState === 'deleted') {
+ expect(follow).to.not.exist
+ } else {
+ expect(follow.state).to.equal(followerState)
+ expect(follow.follower.url).to.equal(followerUrl)
+ expect(follow.following.url).to.equal(followingUrl)
+ }
+ }
+
+ {
+ const { data } = await following.follows.getFollowers()
+ const follow = data.find(finder)
+
+ if (followingState === 'deleted') {
+ expect(follow).to.not.exist
+ } else {
+ expect(follow.state).to.equal(followingState)
+ expect(follow.follower.url).to.equal(followerUrl)
+ expect(follow.following.url).to.equal(followingUrl)
+ }
+ }
+}
+
+async function checkNoFollowers (servers: PeerTubeServer[]) {
+ const fns = [
+ servers[0].follows.getFollowings.bind(servers[0].follows),
+ servers[1].follows.getFollowers.bind(servers[1].follows)
+ ]
+
+ for (const fn of fns) {
+ const body = await fn({ start: 0, count: 5, sort: 'createdAt', state: 'accepted' })
+ expect(body.total).to.equal(0)
+ }
+}