aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/utils/pods.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/utils/pods.js')
-rw-r--r--server/tests/utils/pods.js95
1 files changed, 95 insertions, 0 deletions
diff --git a/server/tests/utils/pods.js b/server/tests/utils/pods.js
new file mode 100644
index 000000000..a8551a49d
--- /dev/null
+++ b/server/tests/utils/pods.js
@@ -0,0 +1,95 @@
1'use strict'
2
3const request = require('supertest')
4
5const podsUtils = {
6 getFriendsList,
7 makeFriends,
8 quitFriends
9}
10
11// ---------------------- Export functions --------------------
12
13function getFriendsList (url, end) {
14 const path = '/api/v1/pods/'
15
16 request(url)
17 .get(path)
18 .set('Accept', 'application/json')
19 .expect(200)
20 .expect('Content-Type', /json/)
21 .end(end)
22}
23
24function makeFriends (url, accessToken, expectedStatus, end) {
25 if (!end) {
26 end = expectedStatus
27 expectedStatus = 204
28 }
29
30 // Which pod makes friends with which pod
31 const friendsMatrix = {
32 'http://localhost:9001': [
33 'http://localhost:9002'
34 ],
35 'http://localhost:9002': [
36 'http://localhost:9003'
37 ],
38 'http://localhost:9003': [
39 'http://localhost:9001'
40 ],
41 'http://localhost:9004': [
42 'http://localhost:9002'
43 ],
44 'http://localhost:9005': [
45 'http://localhost:9001',
46 'http://localhost:9004'
47 ],
48 'http://localhost:9006': [
49 'http://localhost:9001',
50 'http://localhost:9002',
51 'http://localhost:9003'
52 ]
53 }
54 const path = '/api/v1/pods/makefriends'
55
56 // The first pod make friend with the third
57 request(url)
58 .post(path)
59 .set('Accept', 'application/json')
60 .set('Authorization', 'Bearer ' + accessToken)
61 .send({ 'urls': friendsMatrix[url] })
62 .expect(expectedStatus)
63 .end(function (err, res) {
64 if (err) throw err
65
66 // Wait for the request between pods
67 setTimeout(end, 1000)
68 })
69}
70
71function quitFriends (url, accessToken, expectedStatus, end) {
72 if (!end) {
73 end = expectedStatus
74 expectedStatus = 204
75 }
76
77 const path = '/api/v1/pods/quitfriends'
78
79 // The first pod make friend with the third
80 request(url)
81 .get(path)
82 .set('Accept', 'application/json')
83 .set('Authorization', 'Bearer ' + accessToken)
84 .expect(expectedStatus)
85 .end(function (err, res) {
86 if (err) throw err
87
88 // Wait for the request between pods
89 setTimeout(end, 1000)
90 })
91}
92
93// ---------------------------------------------------------------------------
94
95module.exports = podsUtils