aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests/api/friendsBasic.js
diff options
context:
space:
mode:
Diffstat (limited to 'server/tests/api/friendsBasic.js')
-rw-r--r--server/tests/api/friendsBasic.js39
1 files changed, 22 insertions, 17 deletions
diff --git a/server/tests/api/friendsBasic.js b/server/tests/api/friendsBasic.js
index c9e3bc9ad..68817e852 100644
--- a/server/tests/api/friendsBasic.js
+++ b/server/tests/api/friendsBasic.js
@@ -3,13 +3,17 @@
3const async = require('async') 3const async = require('async')
4const chai = require('chai') 4const chai = require('chai')
5const expect = chai.expect 5const expect = chai.expect
6const request = require('supertest')
7 6
8const utils = require('./utils') 7const utils = require('./utils')
9 8
10describe('Test basic friends', function () { 9describe('Test basic friends', function () {
11 let servers = [] 10 let servers = []
12 11
12 function makeFriends (podNumber, callback) {
13 const server = servers[podNumber - 1]
14 return utils.makeFriends(server.url, server.accessToken, callback)
15 }
16
13 function testMadeFriends (servers, serverToTest, callback) { 17 function testMadeFriends (servers, serverToTest, callback) {
14 const friends = [] 18 const friends = []
15 for (let i = 0; i < servers.length; i++) { 19 for (let i = 0; i < servers.length; i++) {
@@ -39,7 +43,15 @@ describe('Test basic friends', function () {
39 this.timeout(20000) 43 this.timeout(20000)
40 utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) { 44 utils.flushAndRunMultipleServers(3, function (serversRun, urlsRun) {
41 servers = serversRun 45 servers = serversRun
42 done() 46
47 async.each(servers, function (server, callbackEach) {
48 utils.loginAndGetAccessToken(server, function (err, accessToken) {
49 if (err) return callbackEach(err)
50
51 server.accessToken = accessToken
52 callbackEach()
53 })
54 }, done)
43 }) 55 })
44 }) 56 })
45 57
@@ -59,16 +71,10 @@ describe('Test basic friends', function () {
59 it('Should make friends', function (done) { 71 it('Should make friends', function (done) {
60 this.timeout(10000) 72 this.timeout(10000)
61 73
62 const path = '/api/v1/pods/makefriends'
63
64 async.series([ 74 async.series([
65 // The second pod make friend with the third 75 // The second pod make friend with the third
66 function (next) { 76 function (next) {
67 request(servers[1].url) 77 makeFriends(2, next)
68 .get(path)
69 .set('Accept', 'application/json')
70 .expect(204)
71 .end(next)
72 }, 78 },
73 // Wait for the request between pods 79 // Wait for the request between pods
74 function (next) { 80 function (next) {
@@ -102,11 +108,7 @@ describe('Test basic friends', function () {
102 }, 108 },
103 // Finally the first pod make friend with the second pod 109 // Finally the first pod make friend with the second pod
104 function (next) { 110 function (next) {
105 request(servers[0].url) 111 makeFriends(1, next)
106 .get(path)
107 .set('Accept', 'application/json')
108 .expect(204)
109 .end(next)
110 }, 112 },
111 // Wait for the request between pods 113 // Wait for the request between pods
112 function (next) { 114 function (next) {
@@ -123,14 +125,16 @@ describe('Test basic friends', function () {
123 }) 125 })
124 126
125 it('Should not be allowed to make friend again', function (done) { 127 it('Should not be allowed to make friend again', function (done) {
126 utils.makeFriends(servers[1].url, 409, done) 128 const server = servers[1]
129 utils.makeFriends(server.url, server.accessToken, 409, done)
127 }) 130 })
128 131
129 it('Should quit friends of pod 2', function (done) { 132 it('Should quit friends of pod 2', function (done) {
130 async.series([ 133 async.series([
131 // Pod 1 quit friends 134 // Pod 1 quit friends
132 function (next) { 135 function (next) {
133 utils.quitFriends(servers[1].url, next) 136 const server = servers[1]
137 utils.quitFriends(server.url, server.accessToken, next)
134 }, 138 },
135 // Pod 1 should not have friends anymore 139 // Pod 1 should not have friends anymore
136 function (next) { 140 function (next) {
@@ -162,7 +166,8 @@ describe('Test basic friends', function () {
162 }) 166 })
163 167
164 it('Should allow pod 2 to make friend again', function (done) { 168 it('Should allow pod 2 to make friend again', function (done) {
165 utils.makeFriends(servers[1].url, function () { 169 const server = servers[1]
170 utils.makeFriends(server.url, server.accessToken, function () {
166 async.each(servers, function (server, callback) { 171 async.each(servers, function (server, callback) {
167 testMadeFriends(servers, server, callback) 172 testMadeFriends(servers, server, callback)
168 }, done) 173 }, done)