aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/friends-advanced.ts
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2017-11-17 12:05:59 +0100
committerChocobozzz <florian.bigard@gmail.com>2017-11-27 19:40:52 +0100
commit975e6e0e44e2f2b25f804cd48a62e2a8d9e8117a (patch)
tree87ee25f3033f0fe0da76ee3649bb24cae0509c0e /server/tests/api/friends-advanced.ts
parentafffe98839db7ccbfa9fb8b7d1413b97900fdc73 (diff)
downloadPeerTube-975e6e0e44e2f2b25f804cd48a62e2a8d9e8117a.tar.gz
PeerTube-975e6e0e44e2f2b25f804cd48a62e2a8d9e8117a.tar.zst
PeerTube-975e6e0e44e2f2b25f804cd48a62e2a8d9e8117a.zip
Fix video full description
Diffstat (limited to 'server/tests/api/friends-advanced.ts')
-rw-r--r--server/tests/api/friends-advanced.ts292
1 files changed, 0 insertions, 292 deletions
diff --git a/server/tests/api/friends-advanced.ts b/server/tests/api/friends-advanced.ts
deleted file mode 100644
index 654c959fd..000000000
--- a/server/tests/api/friends-advanced.ts
+++ /dev/null
@@ -1,292 +0,0 @@
1/* tslint:disable:no-unused-expression */
2
3import 'mocha'
4import * as chai from 'chai'
5const expect = chai.expect
6
7import {
8 ServerInfo,
9 flushTests,
10 runServer,
11 uploadVideo,
12 quitFriends,
13 getVideosList,
14 wait,
15 setAccessTokensToServers,
16 flushAndRunMultipleServers,
17 killallServers,
18 makeFriends,
19 getFriendsList,
20 quitOneFriend
21} from '../utils'
22
23describe('Test advanced friends', function () {
24 let servers: ServerInfo[] = []
25
26 async function makeFriendsWrapper (podNumber: number) {
27 const server = servers[podNumber - 1]
28 return makeFriends(server.url, server.accessToken)
29 }
30
31 async function quitFriendsWrapper (podNumber: number) {
32 const server = servers[podNumber - 1]
33 return quitFriends(server.url, server.accessToken)
34 }
35
36 async function removeFriendWrapper (podNumber: number, podNumberToRemove: number) {
37 const server = servers[podNumber - 1]
38 const serverToRemove = servers[podNumberToRemove - 1]
39
40 const res = await getFriendsList(server.url)
41
42 let friendsList = res.body.data
43 let podToRemove = friendsList.find(friend => (friend.host === serverToRemove.host))
44
45 return quitOneFriend(server.url, server.accessToken, podToRemove.id)
46 }
47
48 async function getFriendsListWrapper (podNumber: number) {
49 const server = servers[podNumber - 1]
50 return getFriendsList(server.url)
51 }
52
53 async function uploadVideoWrapper (podNumber: number) {
54 const videoAttributes = {
55 tags: [ 'tag1', 'tag2' ]
56 }
57 const server = servers[podNumber - 1]
58
59 return uploadVideo(server.url, server.accessToken, videoAttributes)
60 }
61
62 async function getVideosWrapper (podNumber: number) {
63 return getVideosList(servers[podNumber - 1].url)
64 }
65
66 // ---------------------------------------------------------------
67
68 before(async function () {
69 this.timeout(120000)
70
71 servers = await flushAndRunMultipleServers(6)
72 await setAccessTokensToServers(servers)
73 })
74
75 it('Should not make friends with two different groups', async function () {
76 this.timeout(20000)
77
78 // Pod 3 makes friend with the first one
79 await makeFriendsWrapper(3)
80
81 // Pod 4 makes friend with the second one
82 await makeFriendsWrapper(4)
83
84 // Now if the fifth wants to make friends with the third and the first
85 await makeFriendsWrapper(5)
86
87 await wait(11000)
88
89 // It should have 0 friends
90 const res = await getFriendsListWrapper(5)
91 expect(res.body.data.length).to.equal(0)
92 })
93
94 it('Should quit all friends', async function () {
95 this.timeout(10000)
96
97 await quitFriendsWrapper(1)
98 await quitFriendsWrapper(2)
99
100 const serverNumbersToTest = [ 1, 2, 3, 4, 5, 6 ]
101 for (const i of serverNumbersToTest) {
102 const res = await getFriendsListWrapper(i)
103 expect(res.body.data.length).to.equal(0)
104 }
105 })
106
107 it('Should remove bad pod and new pod should not become friend with it', async function () {
108 this.timeout(200000)
109
110 // Pods 1, 2, 3 and 4 become friends
111 await makeFriendsWrapper(2)
112 await makeFriendsWrapper(1)
113 await makeFriendsWrapper(4)
114
115 // Check the pods 1, 2, 3 and 4 are friends
116 let serverNumbersToTest = [ 1, 2, 3, 4 ]
117 for (const i of serverNumbersToTest) {
118 const res = await getFriendsListWrapper(i)
119 expect(res.body.data.length).to.equal(3)
120 }
121
122 // Wait initial video channel requests
123 await wait(11000)
124
125 // Kill pod 4
126 servers[3].app.kill()
127
128 // Remove pod 4 from pod 1 and 2
129 await uploadVideoWrapper(1)
130 await uploadVideoWrapper(2)
131
132 await wait(11000)
133
134 await uploadVideoWrapper(1)
135 await uploadVideoWrapper(2)
136
137 await wait(11000)
138
139 await uploadVideoWrapper(1)
140 await uploadVideoWrapper(2)
141
142 await wait(11000)
143
144 await uploadVideoWrapper(1)
145 await uploadVideoWrapper(2)
146
147 await wait(11000)
148
149 serverNumbersToTest = [ 1, 2 ]
150
151 for (const i of serverNumbersToTest) {
152 const res = await getFriendsListWrapper(i)
153
154 // Pod 4 should not be our friend
155 const friends = res.body.data
156 expect(friends.length).to.equal(2)
157
158 for (const pod of friends) {
159 expect(pod.host).not.equal(servers[3].host)
160 }
161 }
162
163 // Rerun server 4
164 const newServer = await runServer(4)
165 servers[3].app = newServer.app
166 servers[3].app
167
168 // Pod 4 didn't know pod 1 and 2 removed it
169 const res1 = await getFriendsListWrapper(4)
170 expect(res1.body.data.length).to.equal(3)
171
172 // Pod 3 didn't upload video, it's still friend with pod 3
173 const res2 = await getFriendsListWrapper(3)
174 expect(res2.body.data.length).to.equal(3)
175
176 // Pod 6 asks pod 1, 2 and 3
177 await makeFriendsWrapper(6)
178
179 await wait(11000)
180
181 const res3 = await getFriendsListWrapper(6)
182
183 // Pod 4 should not be our friend
184 const friends = res3.body.data
185 expect(friends.length).to.equal(3)
186 for (const pod of friends) {
187 expect(pod.host).not.equal(servers[3].host)
188 }
189 })
190
191 // Pod 1 is friend with : 2 3 6
192 // Pod 2 is friend with : 1 3 6
193 // Pod 3 is friend with : 1 2 4 6
194 // Pod 4 is friend with : 1 2 3
195 // Pod 6 is friend with : 1 2 3
196 it('Should pod 1 quit friends', async function () {
197 this.timeout(25000)
198
199 // Upload a video on server 3 for additional tests
200 await uploadVideoWrapper(3)
201
202 await wait(15000)
203
204 // Pod 1 remove friends
205 await quitFriendsWrapper(1)
206
207 const res1 = await getVideosWrapper(1)
208 const videos1 = res1.body.data
209 expect(videos1).to.be.an('array')
210 expect(videos1.length).to.equal(4)
211
212 const res2 = await getVideosWrapper(2)
213 const videos2 = res2.body.data
214 expect(videos2).to.be.an('array')
215 expect(videos2.length).to.equal(5)
216 })
217
218 // Pod 1 is friend with nothing
219 // Pod 2 is friend with : 3 6
220 // Pod 3 is friend with : 2 4 6
221 // Pod 4 is friend with : 2 3
222 // Pod 6 is friend with : 2 3
223 it('Should make friends between pod 1, 2, 3 and 6 and exchange their videos', async function () {
224 this.timeout(30000)
225
226 await makeFriendsWrapper(1)
227
228 await wait(22000)
229
230 const res = await getVideosWrapper(1)
231 const videos = res.body.data
232 expect(videos).to.be.an('array')
233 expect(videos.length).to.equal(9)
234 })
235
236 // Pod 1 is friend with : 2 3 6
237 // Pod 2 is friend with : 1 3 6
238 // Pod 3 is friend with : 1 2 4 6
239 // Pod 4 is friend with : 2 3
240 // Pod 6 is friend with : 1 2 3
241 it('Should allow pod 6 to quit pod 1, 2 and 3 and be friend with pod 3', async function () {
242 this.timeout(30000)
243
244 // Pod 3 should have 4 friends
245 const res1 = await getFriendsListWrapper(3)
246 const friendsList1 = res1.body.data
247 expect(friendsList1).to.be.an('array')
248 expect(friendsList1.length).to.equal(4)
249
250 // Pod 1, 2, 6 should have 3 friends each
251 let serverNumbersToTest = [ 1, 2, 6 ]
252 for (const i of serverNumbersToTest) {
253 const res = await getFriendsListWrapper(i)
254 const friendsList = res.body.data
255 expect(friendsList).to.be.an('array')
256 expect(friendsList.length).to.equal(3)
257 }
258
259 await removeFriendWrapper(6, 1)
260 await removeFriendWrapper(6, 2)
261
262 // Pod 6 should now have only 1 friend (and it should be Pod 3)
263 const res2 = await getFriendsListWrapper(6)
264 const friendsList2 = res2.body.data
265 expect(friendsList2).to.be.an('array')
266 expect(friendsList2.length).to.equal(1)
267 expect(friendsList2[0].host).to.equal(servers[2].host)
268
269 // Pod 1 & 2 should not know friend 6 anymore
270 serverNumbersToTest = [ 1, 2 ]
271 for (const i of serverNumbersToTest) {
272 const res = await getFriendsListWrapper(i)
273 const friendsList = res.body.data
274 expect(friendsList).to.be.an('array')
275 expect(friendsList.length).to.equal(2)
276 }
277
278 // Pod 3 should know every pod
279 const res3 = await getFriendsListWrapper(3)
280 const friendsList3 = res3.body.data
281 expect(friendsList3).to.be.an('array')
282 expect(friendsList3.length).to.equal(4)
283 })
284
285 after(async function () {
286 killallServers(servers)
287
288 if (this['ok']) {
289 await flushTests()
290 }
291 })
292})