]> git.immae.eu Git - github/Chocobozzz/PeerTube.git/blob - test/api/friendsAdvanced.js
Tests refractoring
[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(10000)
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 // It should have 0 friends
62 getFriendsList(5, function (err, res) {
63 if (err) throw err
64
65 expect(res.body.length).to.equal(0)
66
67 done()
68 })
69 })
70 })
71 })
72 })
73
74 it('Should make friends with the pods 1, 2, 3', function (done) {
75 this.timeout(150000)
76
77 // Pods 1, 2, 3 and 4 become friends (yes this is beautiful)
78 makeFriend(2, function () {
79 makeFriend(1, function () {
80 makeFriend(4, function () {
81 // Kill the server 4
82 apps[3].kill()
83
84 // Expulse pod 4 from pod 1 and 2
85 uploadVideo(1, function () {
86 setTimeout(function () {
87 uploadVideo(1, function () {
88 setTimeout(function () {
89 uploadVideo(2, function () {
90 setTimeout(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 }, 11000)
119 })
120 }, 11000)
121 })
122 }, 11000)
123 })
124 }, 11000)
125 })
126 })
127 })
128 })
129 })
130 })
131 })()