]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - server/tests/utils/pods.js
Move video file metadata in their own table
[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,
d5f5a670
GS
8 quitFriends,
9 quitOneFriend
8d309058
C
10}
11
12// ---------------------- Export functions --------------------
13
14function 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
25function makeFriends (url, accessToken, expectedStatus, end) {
26 if (!end) {
27 end = expectedStatus
28 expectedStatus = 204
29 }
30
1e2564d3
C
31 // Which pod makes friends with which pod
32 const friendsMatrix = {
33 'http://localhost:9001': [
a4254ea1 34 'localhost:9002'
1e2564d3
C
35 ],
36 'http://localhost:9002': [
a4254ea1 37 'localhost:9003'
1e2564d3
C
38 ],
39 'http://localhost:9003': [
a4254ea1 40 'localhost:9001'
1e2564d3
C
41 ],
42 'http://localhost:9004': [
a4254ea1 43 'localhost:9002'
1e2564d3
C
44 ],
45 'http://localhost:9005': [
a4254ea1
C
46 'localhost:9001',
47 'localhost:9004'
1e2564d3
C
48 ],
49 'http://localhost:9006': [
a4254ea1
C
50 'localhost:9001',
51 'localhost:9002',
52 'localhost:9003'
1e2564d3
C
53 ]
54 }
8d309058
C
55 const path = '/api/v1/pods/makefriends'
56
57 // The first pod make friend with the third
58 request(url)
1e2564d3 59 .post(path)
8d309058
C
60 .set('Accept', 'application/json')
61 .set('Authorization', 'Bearer ' + accessToken)
a4254ea1 62 .send({ 'hosts': friendsMatrix[url] })
8d309058
C
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
72function 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
d5f5a670
GS
94function 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
8d309058
C
114// ---------------------------------------------------------------------------
115
116module.exports = podsUtils