diff options
author | Chocobozzz <me@florianbigard.com> | 2019-09-04 11:18:33 +0200 |
---|---|---|
committer | Chocobozzz <chocobozzz@cpy.re> | 2019-09-04 16:24:58 +0200 |
commit | 6f1b4fa417786c2015f16b435e872aa65378efd7 (patch) | |
tree | bcf97760b4819d3204f42592a9e6f052674b1f01 /server/tests | |
parent | 8424c4026afd7304880a4ce8138a04ffb3d8c938 (diff) | |
download | PeerTube-6f1b4fa417786c2015f16b435e872aa65378efd7.tar.gz PeerTube-6f1b4fa417786c2015f16b435e872aa65378efd7.tar.zst PeerTube-6f1b4fa417786c2015f16b435e872aa65378efd7.zip |
Add auto follow instances index support
Diffstat (limited to 'server/tests')
-rw-r--r-- | server/tests/api/server/auto-follows.ts | 83 |
1 files changed, 71 insertions, 12 deletions
diff --git a/server/tests/api/server/auto-follows.ts b/server/tests/api/server/auto-follows.ts index 32ad259c9..dea9191f2 100644 --- a/server/tests/api/server/auto-follows.ts +++ b/server/tests/api/server/auto-follows.ts | |||
@@ -6,10 +6,12 @@ import { | |||
6 | acceptFollower, | 6 | acceptFollower, |
7 | cleanupTests, | 7 | cleanupTests, |
8 | flushAndRunMultipleServers, | 8 | flushAndRunMultipleServers, |
9 | MockInstancesIndex, | ||
9 | ServerInfo, | 10 | ServerInfo, |
10 | setAccessTokensToServers, | 11 | setAccessTokensToServers, |
11 | unfollow, | 12 | unfollow, |
12 | updateCustomSubConfig | 13 | updateCustomSubConfig, |
14 | wait | ||
13 | } from '../../../../shared/extra-utils/index' | 15 | } from '../../../../shared/extra-utils/index' |
14 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort } from '../../../../shared/extra-utils/server/follows' | 16 | import { follow, getFollowersListPaginationAndSort, getFollowingListPaginationAndSort } from '../../../../shared/extra-utils/server/follows' |
15 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' | 17 | import { waitJobs } from '../../../../shared/extra-utils/server/jobs' |
@@ -22,13 +24,14 @@ async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: | |||
22 | const res = await getFollowersListPaginationAndSort(following.url, 0, 5, '-createdAt') | 24 | const res = await getFollowersListPaginationAndSort(following.url, 0, 5, '-createdAt') |
23 | const follows = res.body.data as ActorFollow[] | 25 | const follows = res.body.data as ActorFollow[] |
24 | 26 | ||
25 | if (exists === true) { | 27 | const follow = follows.find(f => { |
26 | expect(res.body.total).to.equal(1) | 28 | return f.follower.host === follower.host && f.state === 'accepted' |
29 | }) | ||
27 | 30 | ||
28 | expect(follows[ 0 ].follower.host).to.equal(follower.host) | 31 | if (exists === true) { |
29 | expect(follows[ 0 ].state).to.equal('accepted') | 32 | expect(follow).to.exist |
30 | } else { | 33 | } else { |
31 | expect(follows.filter(f => f.state === 'accepted')).to.have.lengthOf(0) | 34 | expect(follow).to.be.undefined |
32 | } | 35 | } |
33 | } | 36 | } |
34 | 37 | ||
@@ -36,13 +39,14 @@ async function checkFollow (follower: ServerInfo, following: ServerInfo, exists: | |||
36 | const res = await getFollowingListPaginationAndSort(follower.url, 0, 5, '-createdAt') | 39 | const res = await getFollowingListPaginationAndSort(follower.url, 0, 5, '-createdAt') |
37 | const follows = res.body.data as ActorFollow[] | 40 | const follows = res.body.data as ActorFollow[] |
38 | 41 | ||
39 | if (exists === true) { | 42 | const follow = follows.find(f => { |
40 | expect(res.body.total).to.equal(1) | 43 | return f.following.host === following.host && f.state === 'accepted' |
44 | }) | ||
41 | 45 | ||
42 | expect(follows[ 0 ].following.host).to.equal(following.host) | 46 | if (exists === true) { |
43 | expect(follows[ 0 ].state).to.equal('accepted') | 47 | expect(follow).to.exist |
44 | } else { | 48 | } else { |
45 | expect(follows.filter(f => f.state === 'accepted')).to.have.lengthOf(0) | 49 | expect(follow).to.be.undefined |
46 | } | 50 | } |
47 | } | 51 | } |
48 | } | 52 | } |
@@ -71,7 +75,7 @@ describe('Test auto follows', function () { | |||
71 | before(async function () { | 75 | before(async function () { |
72 | this.timeout(30000) | 76 | this.timeout(30000) |
73 | 77 | ||
74 | servers = await flushAndRunMultipleServers(2) | 78 | servers = await flushAndRunMultipleServers(3) |
75 | 79 | ||
76 | // Get the access tokens | 80 | // Get the access tokens |
77 | await setAccessTokensToServers(servers) | 81 | await setAccessTokensToServers(servers) |
@@ -142,6 +146,61 @@ describe('Test auto follows', function () { | |||
142 | }) | 146 | }) |
143 | }) | 147 | }) |
144 | 148 | ||
149 | describe('Auto follow index', function () { | ||
150 | const instanceIndexServer = new MockInstancesIndex() | ||
151 | |||
152 | before(async () => { | ||
153 | await instanceIndexServer.initialize() | ||
154 | }) | ||
155 | |||
156 | it('Should not auto follow index if the option is not enabled', async function () { | ||
157 | this.timeout(30000) | ||
158 | |||
159 | await wait(5000) | ||
160 | await waitJobs(servers) | ||
161 | |||
162 | await checkFollow(servers[ 0 ], servers[ 1 ], false) | ||
163 | await checkFollow(servers[ 1 ], servers[ 0 ], false) | ||
164 | }) | ||
165 | |||
166 | it('Should auto follow the index', async function () { | ||
167 | this.timeout(30000) | ||
168 | |||
169 | instanceIndexServer.addInstance(servers[1].host) | ||
170 | |||
171 | const config = { | ||
172 | followings: { | ||
173 | instance: { | ||
174 | autoFollowIndex: { | ||
175 | indexUrl: 'http://localhost:42100', | ||
176 | enabled: true | ||
177 | } | ||
178 | } | ||
179 | } | ||
180 | } | ||
181 | await updateCustomSubConfig(servers[0].url, servers[0].accessToken, config) | ||
182 | |||
183 | await wait(5000) | ||
184 | await waitJobs(servers) | ||
185 | |||
186 | await checkFollow(servers[ 0 ], servers[ 1 ], true) | ||
187 | |||
188 | await resetFollows(servers) | ||
189 | }) | ||
190 | |||
191 | it('Should follow new added instances in the index but not old ones', async function () { | ||
192 | this.timeout(30000) | ||
193 | |||
194 | instanceIndexServer.addInstance(servers[2].host) | ||
195 | |||
196 | await wait(5000) | ||
197 | await waitJobs(servers) | ||
198 | |||
199 | await checkFollow(servers[ 0 ], servers[ 1 ], false) | ||
200 | await checkFollow(servers[ 0 ], servers[ 2 ], true) | ||
201 | }) | ||
202 | }) | ||
203 | |||
145 | after(async function () { | 204 | after(async function () { |
146 | await cleanupTests(servers) | 205 | await cleanupTests(servers) |
147 | }) | 206 | }) |