]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/friendsAdvanced.js
Fix tests
[github/Chocobozzz/PeerTube.git] / test / api / friendsAdvanced.js
1 ;(function () {
2 'use strict'
3
4 var chai = require('chai')
5 var expect = chai.expect
6
7 var utils = require('./utils')
8
9 describe('Test advanced friends', function () {
10 var apps = []
11 var urls = []
12
13 function makeFriend (pod_number, callback) {
14 return utils.makeFriend(urls[pod_number - 1], callback)
15 }
16
17 function getFriendsList (pod_number, end) {
18 return utils.getFriendsList(urls[pod_number - 1], end)
19 }
20
21 function uploadVideo (pod_number, callback) {
22 var name = 'my super video'
23 var description = 'my super description'
24 var fixture = 'video_short.webm'
25
26 return utils.uploadVideo(urls[pod_number - 1], name, description, fixture, callback)
27 }
28
29 beforeEach(function (done) {
30 this.timeout(30000)
31 utils.runMultipleServers(6, function (apps_run, urls_run) {
32 apps = apps_run
33 urls = urls_run
34 done()
35 })
36 })
37
38 afterEach(function (done) {
39 apps.forEach(function (app) {
40 process.kill(-app.pid)
41 })
42
43 if (this.ok) {
44 utils.flushTests(function () {
45 done()
46 })
47 } else {
48 done()
49 }
50 })
51
52 it('Should make friends with two pod each in a different group', function (done) {
53 this.timeout(20000)
54
55 // Pod 3 makes friend with the first one
56 makeFriend(3, function () {
57 // Pod 4 makes friend with the second one
58 makeFriend(4, function () {
59 // Now if the fifth wants to make friends with the third et the first
60 makeFriend(5, function () {
61 setTimeout(function () {
62 // It should have 0 friends
63 getFriendsList(5, function (err, res) {
64 if (err) throw err
65
66 expect(res.body.length).to.equal(0)
67
68 done()
69 })
70 }, 11000)
71 })
72 })
73 })
74 })
75
76 it('Should make friends with the pods 1, 2, 3', function (done) {
77 this.timeout(150000)
78
79 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
80 makeFriend(2, function () {
81 makeFriend(1, function () {
82 makeFriend(4, function () {
83 // Kill the server 4
84 apps[3].kill()
85
86 // Expulse pod 4 from pod 1 and 2
87 uploadVideo(1, function () {
88 uploadVideo(2, function () {
89 setTimeout(function () {
90 uploadVideo(1, function () {
91 uploadVideo(2, function () {
92 setTimeout(function () {
93 // Rerun server 4
94 utils.runServer(4, function (app, url) {
95 apps[3] = app
96 getFriendsList(4, function (err, res) {
97 if (err) throw err
98 // Pod 4 didn't know pod 1 and 2 removed it
99 expect(res.body.length).to.equal(3)
100
101 // Pod 6 ask pod 1, 2 and 3
102 makeFriend(6, function () {
103 getFriendsList(6, function (err, res) {
104 if (err) throw err
105
106 // Pod 4 should not be our friend
107 var result = res.body
108 expect(result.length).to.equal(3)
109 for (var pod of result) {
110 expect(pod.url).not.equal(urls[3])
111 }
112
113 done()
114 })
115 })
116 })
117 })
118 }, 15000)
119 })
120 })
121 }, 11000)
122 })
123 })
124 })
125 })
126 })
127 })
128 })
129 })()