]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - server/tests/utils/pods.js
25b97edec99685dce89f5996c80cb2147b8aae76
[github/Chocobozzz/PeerTube.git] / server / tests / utils / pods.js
1 'use strict'
2
3 const request = require('supertest')
4
5 const podsUtils = {
6 getFriendsList,
7 makeFriends,
8 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 // Which pod makes friends with which pod
31 const friendsMatrix = {
32 'http://localhost:9001': [
33 'localhost:9002'
34 ],
35 'http://localhost:9002': [
36 'localhost:9003'
37 ],
38 'http://localhost:9003': [
39 'localhost:9001'
40 ],
41 'http://localhost:9004': [
42 'localhost:9002'
43 ],
44 'http://localhost:9005': [
45 'localhost:9001',
46 'localhost:9004'
47 ],
48 'http://localhost:9006': [
49 'localhost:9001',
50 'localhost:9002',
51 '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({ 'hosts': 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
71 function 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
95 module.exports = podsUtils