]>
Commit | Line | Data |
---|---|---|
8d309058 C |
1 | 'use strict' |
2 | ||
3 | const request = require('supertest') | |
4 | ||
5 | const podsUtils = { | |
6 | getFriendsList: getFriendsList, | |
7 | makeFriends: makeFriends, | |
8 | quitFriends: quitFriends | |
9 | } | |
10 | ||
11 | // ---------------------- Export functions -------------------- | |
12 | ||
13 | function 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 | ||
24 | function makeFriends (url, accessToken, expectedStatus, end) { | |
25 | if (!end) { | |
26 | end = expectedStatus | |
27 | expectedStatus = 204 | |
28 | } | |
29 | ||
30 | const path = '/api/v1/pods/makefriends' | |
31 | ||
32 | // The first pod make friend with the third | |
33 | request(url) | |
34 | .get(path) | |
35 | .set('Accept', 'application/json') | |
36 | .set('Authorization', 'Bearer ' + accessToken) | |
37 | .expect(expectedStatus) | |
38 | .end(function (err, res) { | |
39 | if (err) throw err | |
40 | ||
41 | // Wait for the request between pods | |
42 | setTimeout(end, 1000) | |
43 | }) | |
44 | } | |
45 | ||
46 | function quitFriends (url, accessToken, expectedStatus, end) { | |
47 | if (!end) { | |
48 | end = expectedStatus | |
49 | expectedStatus = 204 | |
50 | } | |
51 | ||
52 | const path = '/api/v1/pods/quitfriends' | |
53 | ||
54 | // The first pod make friend with the third | |
55 | request(url) | |
56 | .get(path) | |
57 | .set('Accept', 'application/json') | |
58 | .set('Authorization', 'Bearer ' + accessToken) | |
59 | .expect(expectedStatus) | |
60 | .end(function (err, res) { | |
61 | if (err) throw err | |
62 | ||
63 | // Wait for the request between pods | |
64 | setTimeout(end, 1000) | |
65 | }) | |
66 | } | |
67 | ||
68 | // --------------------------------------------------------------------------- | |
69 | ||
70 | module.exports = podsUtils |