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