]>
Commit | Line | Data |
---|---|---|
a1587156 | 1 | /* eslint-disable @typescript-eslint/no-unused-expressions,@typescript-eslint/require-await */ |
8424c402 | 2 | |
86347717 | 3 | import { expect } from 'chai' |
c55e3d72 C |
4 | import { MockInstancesIndex } from '@server/tests/shared' |
5 | import { wait } from '@shared/core-utils' | |
6 | import { cleanupTests, createMultipleServers, PeerTubeServer, setAccessTokensToServers, waitJobs } from '@shared/server-commands' | |
8424c402 | 7 | |
254d3579 | 8 | async function checkFollow (follower: PeerTubeServer, following: PeerTubeServer, exists: boolean) { |
8424c402 | 9 | { |
89d241a7 | 10 | const body = await following.follows.getFollowers({ start: 0, count: 5, sort: '-createdAt' }) |
c3d29f69 | 11 | const follow = body.data.find(f => f.follower.host === follower.host && f.state === 'accepted') |
8424c402 | 12 | |
1cf0df02 C |
13 | if (exists === true) expect(follow, `Follower ${follower.url} should exist on ${following.url}`).to.exist |
14 | else expect(follow, `Follower ${follower.url} should not exist on ${following.url}`).to.be.undefined | |
8424c402 C |
15 | } |
16 | ||
17 | { | |
89d241a7 | 18 | const body = await follower.follows.getFollowings({ start: 0, count: 5, sort: '-createdAt' }) |
c3d29f69 | 19 | const follow = body.data.find(f => f.following.host === following.host && f.state === 'accepted') |
8424c402 | 20 | |
1cf0df02 C |
21 | if (exists === true) expect(follow, `Following ${following.url} should exist on ${follower.url}`).to.exist |
22 | else expect(follow, `Following ${following.url} should not exist on ${follower.url}`).to.be.undefined | |
8424c402 C |
23 | } |
24 | } | |
25 | ||
254d3579 | 26 | async function server1Follows2 (servers: PeerTubeServer[]) { |
4d029ef8 | 27 | await servers[0].follows.follow({ hosts: [ servers[1].host ] }) |
8424c402 C |
28 | |
29 | await waitJobs(servers) | |
30 | } | |
31 | ||
254d3579 | 32 | async function resetFollows (servers: PeerTubeServer[]) { |
8424c402 | 33 | try { |
89d241a7 C |
34 | await servers[0].follows.unfollow({ target: servers[1] }) |
35 | await servers[1].follows.unfollow({ target: servers[0] }) | |
a1587156 C |
36 | } catch { /* empty */ |
37 | } | |
8424c402 C |
38 | |
39 | await waitJobs(servers) | |
40 | ||
41 | await checkFollow(servers[0], servers[1], false) | |
42 | await checkFollow(servers[1], servers[0], false) | |
43 | } | |
44 | ||
45 | describe('Test auto follows', function () { | |
254d3579 | 46 | let servers: PeerTubeServer[] = [] |
8424c402 C |
47 | |
48 | before(async function () { | |
3b2006bb | 49 | this.timeout(120000) |
8424c402 | 50 | |
254d3579 | 51 | servers = await createMultipleServers(3) |
8424c402 C |
52 | |
53 | // Get the access tokens | |
54 | await setAccessTokensToServers(servers) | |
55 | }) | |
56 | ||
57 | describe('Auto follow back', function () { | |
58 | ||
59 | it('Should not auto follow back if the option is not enabled', async function () { | |
60 | this.timeout(15000) | |
61 | ||
62 | await server1Follows2(servers) | |
63 | ||
64 | await checkFollow(servers[0], servers[1], true) | |
65 | await checkFollow(servers[1], servers[0], false) | |
66 | ||
67 | await resetFollows(servers) | |
68 | }) | |
69 | ||
70 | it('Should auto follow back on auto accept if the option is enabled', async function () { | |
71 | this.timeout(15000) | |
72 | ||
73 | const config = { | |
74 | followings: { | |
75 | instance: { | |
76 | autoFollowBack: { enabled: true } | |
77 | } | |
78 | } | |
79 | } | |
89d241a7 | 80 | await servers[1].config.updateCustomSubConfig({ newConfig: config }) |
8424c402 C |
81 | |
82 | await server1Follows2(servers) | |
83 | ||
84 | await checkFollow(servers[0], servers[1], true) | |
85 | await checkFollow(servers[1], servers[0], true) | |
86 | ||
87 | await resetFollows(servers) | |
88 | }) | |
89 | ||
90 | it('Should wait the acceptation before auto follow back', async function () { | |
91 | this.timeout(30000) | |
92 | ||
93 | const config = { | |
94 | followings: { | |
95 | instance: { | |
96 | autoFollowBack: { enabled: true } | |
97 | } | |
98 | }, | |
99 | followers: { | |
100 | instance: { | |
101 | manualApproval: true | |
102 | } | |
103 | } | |
104 | } | |
89d241a7 | 105 | await servers[1].config.updateCustomSubConfig({ newConfig: config }) |
8424c402 C |
106 | |
107 | await server1Follows2(servers) | |
108 | ||
109 | await checkFollow(servers[0], servers[1], false) | |
110 | await checkFollow(servers[1], servers[0], false) | |
111 | ||
89d241a7 | 112 | await servers[1].follows.acceptFollower({ follower: 'peertube@' + servers[0].host }) |
8424c402 C |
113 | await waitJobs(servers) |
114 | ||
115 | await checkFollow(servers[0], servers[1], true) | |
116 | await checkFollow(servers[1], servers[0], true) | |
117 | ||
118 | await resetFollows(servers) | |
2ba613a5 C |
119 | |
120 | config.followings.instance.autoFollowBack.enabled = false | |
121 | config.followers.instance.manualApproval = false | |
89d241a7 | 122 | await servers[1].config.updateCustomSubConfig({ newConfig: config }) |
8424c402 C |
123 | }) |
124 | }) | |
125 | ||
6f1b4fa4 C |
126 | describe('Auto follow index', function () { |
127 | const instanceIndexServer = new MockInstancesIndex() | |
f6500729 | 128 | let port: number |
6f1b4fa4 C |
129 | |
130 | before(async () => { | |
f6500729 | 131 | port = await instanceIndexServer.initialize() |
6f1b4fa4 C |
132 | }) |
133 | ||
134 | it('Should not auto follow index if the option is not enabled', async function () { | |
135 | this.timeout(30000) | |
136 | ||
137 | await wait(5000) | |
138 | await waitJobs(servers) | |
139 | ||
a1587156 C |
140 | await checkFollow(servers[0], servers[1], false) |
141 | await checkFollow(servers[1], servers[0], false) | |
6f1b4fa4 C |
142 | }) |
143 | ||
144 | it('Should auto follow the index', async function () { | |
145 | this.timeout(30000) | |
146 | ||
147 | instanceIndexServer.addInstance(servers[1].host) | |
148 | ||
149 | const config = { | |
150 | followings: { | |
151 | instance: { | |
152 | autoFollowIndex: { | |
2732eeff | 153 | indexUrl: `http://127.0.0.1:${port}/api/v1/instances/hosts`, |
6f1b4fa4 C |
154 | enabled: true |
155 | } | |
156 | } | |
157 | } | |
158 | } | |
89d241a7 | 159 | await servers[0].config.updateCustomSubConfig({ newConfig: config }) |
6f1b4fa4 C |
160 | |
161 | await wait(5000) | |
162 | await waitJobs(servers) | |
163 | ||
a1587156 | 164 | await checkFollow(servers[0], servers[1], true) |
6f1b4fa4 C |
165 | |
166 | await resetFollows(servers) | |
167 | }) | |
168 | ||
169 | it('Should follow new added instances in the index but not old ones', async function () { | |
170 | this.timeout(30000) | |
171 | ||
172 | instanceIndexServer.addInstance(servers[2].host) | |
173 | ||
174 | await wait(5000) | |
175 | await waitJobs(servers) | |
176 | ||
a1587156 C |
177 | await checkFollow(servers[0], servers[1], false) |
178 | await checkFollow(servers[0], servers[2], true) | |
6f1b4fa4 | 179 | }) |
cf0c8ee5 C |
180 | |
181 | after(async function () { | |
182 | await instanceIndexServer.terminate() | |
183 | }) | |
6f1b4fa4 C |
184 | }) |
185 | ||
8424c402 C |
186 | after(async function () { |
187 | await cleanupTests(servers) | |
188 | }) | |
189 | }) |