]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/pods.js
Server: remove useless hash affectations
[github/Chocobozzz/PeerTube.git] / server / tests / utils / pods.js
CommitLineData
8d309058
C
1'use strict'
2
3const request = require('supertest')
4
5const podsUtils = {
c4403b29
C
6 getFriendsList,
7 makeFriends,
8 quitFriends
8d309058
C
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
1e2564d3
C
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 }
8d309058
C
54 const path = '/api/v1/pods/makefriends'
55
56 // The first pod make friend with the third
57 request(url)
1e2564d3 58 .post(path)
8d309058
C
59 .set('Accept', 'application/json')
60 .set('Authorization', 'Bearer ' + accessToken)
1e2564d3 61 .send({ 'urls': friendsMatrix[url] })
8d309058
C
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