3 var async = require('async')
4 var chai = require('chai')
5 var expect = chai.expect
6 var request = require('supertest')
8 var utils = require('./utils')
10 describe('Test basic friends', function () {
14 function testMadeFriends (urls, url_to_test, callback) {
16 for (var i = 0; i < urls.length; i++) {
17 if (urls[i] === url_to_test) continue
21 utils.getFriendsList(url_to_test, function (err, res) {
25 var result_urls = [ result[0].url, result[1].url ]
26 expect(result).to.be.an('array')
27 expect(result.length).to.equal(2)
28 expect(result_urls[0]).to.not.equal(result_urls[1])
30 var error_string = 'Friends url do not correspond for ' + url_to_test
31 expect(friends).to.contain(result_urls[0], error_string)
32 expect(friends).to.contain(result_urls[1], error_string)
37 // ---------------------------------------------------------------
39 before(function (done) {
41 utils.flushAndRunMultipleServers(3, function (apps_run, urls_run) {
48 it('Should not have friends', function (done) {
49 async.each(urls, function (url, callback) {
50 utils.getFriendsList(url, function (err, res) {
54 expect(result).to.be.an('array')
55 expect(result.length).to.equal(0)
61 it('Should make friends', function (done) {
64 var path = '/api/v1/pods/makefriends'
67 // The second pod make friend with the third
71 .set('Accept', 'application/json')
75 // Wait for the request between pods
77 setTimeout(next, 1000)
79 // The second pod should have the third as a friend
81 utils.getFriendsList(urls[1], function (err, res) {
85 expect(result).to.be.an('array')
86 expect(result.length).to.equal(1)
87 expect(result[0].url).to.be.equal(urls[2])
92 // Same here, the third pod should have the second pod as a friend
94 utils.getFriendsList(urls[2], function (err, res) {
98 expect(result).to.be.an('array')
99 expect(result.length).to.equal(1)
100 expect(result[0].url).to.be.equal(urls[1])
105 // Finally the first pod make friend with the second pod
109 .set('Accept', 'application/json')
113 // Wait for the request between pods
115 setTimeout(next, 1000)
118 // Now each pod should be friend with the other ones
121 async.each(urls, function (url, callback) {
122 testMadeFriends(urls, url, callback)
127 it('Should not be allowed to make friend again', function (done) {
128 utils.makeFriends(urls[1], 409, done)
131 it('Should quit friends of pod 2', function (done) {
133 // Pod 1 quit friends
135 utils.quitFriends(urls[1], next)
137 // Pod 1 should not have friends anymore
139 utils.getFriendsList(urls[1], function (err, res) {
142 var result = res.body
143 expect(result).to.be.an('array')
144 expect(result.length).to.equal(0)
149 // Other pods shouldn't have pod 1 too
151 async.each([ urls[0], urls[2] ], function (url, callback) {
152 utils.getFriendsList(url, function (err, res) {
155 var result = res.body
156 expect(result).to.be.an('array')
157 expect(result.length).to.equal(1)
158 expect(result[0].url).not.to.be.equal(urls[1])
166 it('Should allow pod 2 to make friend again', function (done) {
167 utils.makeFriends(urls[1], function () {
168 async.each(urls, function (url, callback) {
169 testMadeFriends(urls, url, callback)
174 after(function (done) {
175 apps.forEach(function (app) {
176 process.kill(-app.pid)
180 utils.flushTests(done)