]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blame - test/api/friendsAdvanced.js
Add a pool of requests instead of making a request at each action (add
[github/Chocobozzz/PeerTube.git] / test / api / friendsAdvanced.js
CommitLineData
3bcb78b3
C
1;(function () {
2 'use strict'
3
4 var request = require('supertest')
5 var chai = require('chai')
6 var expect = chai.expect
7
8 var utils = require('../utils')
9
10 describe('Test advanced friends', function () {
11 var path = '/api/v1/pods/makefriends'
12 var apps = []
13 var urls = []
14
15 function makeFriend (pod_number, callback) {
16 // The first pod make friend with the third
17 request(urls[pod_number - 1])
18 .get(path)
19 .set('Accept', 'application/json')
20 .expect(204)
21 .end(function (err, res) {
22 if (err) throw err
23
24 // Wait for the request between pods
25 setTimeout(function () {
26 callback()
27 }, 1000)
28 })
29 }
30
31 function getFriendsList (pod_number, end) {
32 var path = '/api/v1/pods/'
33
34 request(urls[pod_number - 1])
35 .get(path)
36 .set('Accept', 'application/json')
37 .expect(200)
38 .expect('Content-Type', /json/)
39 .end(end)
40 }
41
42 function uploadVideo (pod_number, callback) {
43 var path = '/api/v1/videos'
44
45 request(urls[pod_number - 1])
46 .post(path)
47 .set('Accept', 'application/json')
48 .field('name', 'my super video')
49 .field('description', 'my super description')
50 .attach('input_video', __dirname + '/../fixtures/video_short.webm')
51 .expect(201)
52 .end(function (err) {
53 if (err) throw err
54
55 // Wait for the retry requests
56 setTimeout(callback, 10000)
57 })
58 }
59
60 beforeEach(function (done) {
61 this.timeout(30000)
62 utils.runMultipleServers(6, function (apps_run, urls_run) {
63 apps = apps_run
64 urls = urls_run
65 done()
66 })
67 })
68
69 afterEach(function (done) {
70 apps.forEach(function (app) {
71 process.kill(-app.pid)
72 })
73
74 if (this.ok) {
75 utils.flushTests(function () {
76 done()
77 })
78 } else {
79 done()
80 }
81 })
82
83 it('Should make friends with two pod each in a different group', function (done) {
84 this.timeout(10000)
85
86 // Pod 3 makes friend with the first one
87 makeFriend(3, function () {
88 // Pod 4 makes friend with the second one
89 makeFriend(4, function () {
90 // Now if the fifth wants to make friends with the third et the first
91 makeFriend(5, function () {
92 // It should have 0 friends
93 getFriendsList(5, function (err, res) {
94 if (err) throw err
95
96 expect(res.body.length).to.equal(0)
97
98 done()
99 })
100 })
101 })
102 })
103 })
104
105 it('Should make friends with the pods 1, 2, 3', function (done) {
0b697522 106 this.timeout(150000)
3bcb78b3 107
0b697522 108 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
3bcb78b3
C
109 makeFriend(2, function () {
110 makeFriend(1, function () {
111 makeFriend(4, function () {
112 // Kill the server 4
113 apps[3].kill()
114
115 // Expulse pod 4 from pod 1 and 2
116 uploadVideo(1, function () {
0b697522
C
117 setTimeout(function () {
118 uploadVideo(1, function () {
119 setTimeout(function () {
120 uploadVideo(2, function () {
121 setTimeout(function () {
122 uploadVideo(2, function () {
123 setTimeout(function () {
124 // Rerun server 4
125 utils.runServer(4, function (app, url) {
126 apps[3] = app
127 getFriendsList(4, function (err, res) {
128 if (err) throw err
129 // Pod 4 didn't know pod 1 and 2 removed it
130 expect(res.body.length).to.equal(3)
131
132 // Pod 6 ask pod 1, 2 and 3
133 makeFriend(6, function () {
134 getFriendsList(6, function (err, res) {
135 if (err) throw err
136
137 // Pod 4 should not be our friend
138 var result = res.body
139 expect(result.length).to.equal(3)
140 for (var pod of result) {
141 expect(pod.url).not.equal(urls[3])
142 }
143
144 done()
145 })
146 })
147 })
148 })
149 }, 11000)
3bcb78b3 150 })
0b697522 151 }, 11000)
3bcb78b3 152 })
0b697522 153 }, 11000)
3bcb78b3 154 })
0b697522 155 }, 11000)
3bcb78b3
C
156 })
157 })
158 })
159 })
160 })
161 })
162})()