aboutsummaryrefslogtreecommitdiffhomepage
path: root/test/api/friendsAdvanced.js
diff options
context:
space:
mode:
Diffstat (limited to 'test/api/friendsAdvanced.js')
-rw-r--r--test/api/friendsAdvanced.js154
1 files changed, 154 insertions, 0 deletions
diff --git a/test/api/friendsAdvanced.js b/test/api/friendsAdvanced.js
new file mode 100644
index 000000000..ccddac4dc
--- /dev/null
+++ b/test/api/friendsAdvanced.js
@@ -0,0 +1,154 @@
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) {
106 this.timeout(100000)
107
108 // Pods 1, 2, 3 and 4 become friends
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 () {
117 uploadVideo(1, function () {
118 uploadVideo(2, function () {
119 uploadVideo(2, function () {
120 // Rerun server 4
121 utils.runServer(4, function (app, url) {
122 apps[3] = app
123 getFriendsList(4, function (err, res) {
124 if (err) throw err
125 // Pod 4 didn't know pod 1 and 2 removed it
126 expect(res.body.length).to.equal(3)
127
128 // Pod 6 ask pod 1, 2 and 3
129 makeFriend(6, function () {
130 getFriendsList(6, function (err, res) {
131 if (err) throw err
132
133 // Pod 4 should not be our friend
134 var result = res.body
135 expect(result.length).to.equal(3)
136 for (var pod of result) {
137 expect(pod.url).not.equal(urls[3])
138 }
139
140 done()
141 })
142 })
143 })
144 })
145 })
146 })
147 })
148 })
149 })
150 })
151 })
152 })
153 })
154})()