aboutsummaryrefslogtreecommitdiffhomepage
path: root/server/tests
diff options
context:
space:
mode:
authorChocobozzz <florian.bigard@gmail.com>2016-11-14 20:45:00 +0100
committerChocobozzz <florian.bigard@gmail.com>2016-11-16 20:29:26 +0100
commita4254ea1738d3b963fd4ccb995ab63f70656d6c0 (patch)
tree5b86f5111b9ff764e41285198c15b5c24d4648f4 /server/tests
parent49abbbbedca83b9031d3e2eb3ae9ad9b6a7d96ed (diff)
downloadPeerTube-a4254ea1738d3b963fd4ccb995ab63f70656d6c0.tar.gz
PeerTube-a4254ea1738d3b963fd4ccb995ab63f70656d6c0.tar.zst
PeerTube-a4254ea1738d3b963fd4ccb995ab63f70656d6c0.zip
Server: adapt tests to host
Diffstat (limited to 'server/tests')
-rw-r--r--server/tests/api/check-params.js39
-rw-r--r--server/tests/api/friends-advanced.js2
-rw-r--r--server/tests/api/friends-basic.js18
-rw-r--r--server/tests/api/multiple-pods.js8
-rw-r--r--server/tests/api/single-pod.js18
-rw-r--r--server/tests/utils/pods.js20
-rw-r--r--server/tests/utils/servers.js1
7 files changed, 58 insertions, 48 deletions
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.js
index 07f41daab..444c2fc55 100644
--- a/server/tests/api/check-params.js
+++ b/server/tests/api/check-params.js
@@ -67,10 +67,10 @@ describe('Test parameters validator', function () {
67 67
68 describe('When making friends', function () { 68 describe('When making friends', function () {
69 const body = { 69 const body = {
70 urls: [ 'http://localhost:9002' ] 70 hosts: [ 'localhost:9002' ]
71 } 71 }
72 72
73 it('Should fail without urls', function (done) { 73 it('Should fail without hosts', function (done) {
74 request(server.url) 74 request(server.url)
75 .post(path + '/makefriends') 75 .post(path + '/makefriends')
76 .set('Authorization', 'Bearer ' + server.accessToken) 76 .set('Authorization', 'Bearer ' + server.accessToken)
@@ -78,28 +78,37 @@ describe('Test parameters validator', function () {
78 .expect(400, done) 78 .expect(400, done)
79 }) 79 })
80 80
81 it('Should fail with urls is not an array', function (done) { 81 it('Should fail if hosts is not an array', function (done) {
82 request(server.url) 82 request(server.url)
83 .post(path + '/makefriends') 83 .post(path + '/makefriends')
84 .send({ urls: 'http://localhost:9002' }) 84 .send({ hosts: 'localhost:9002' })
85 .set('Authorization', 'Bearer ' + server.accessToken) 85 .set('Authorization', 'Bearer ' + server.accessToken)
86 .set('Accept', 'application/json') 86 .set('Accept', 'application/json')
87 .expect(400, done) 87 .expect(400, done)
88 }) 88 })
89 89
90 it('Should fail if the array is not composed by urls', function (done) { 90 it('Should fail if the array is not composed by hosts', function (done) {
91 request(server.url) 91 request(server.url)
92 .post(path + '/makefriends') 92 .post(path + '/makefriends')
93 .send({ urls: [ 'http://localhost:9002', 'localhost:coucou' ] }) 93 .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
94 .set('Authorization', 'Bearer ' + server.accessToken) 94 .set('Authorization', 'Bearer ' + server.accessToken)
95 .set('Accept', 'application/json') 95 .set('Accept', 'application/json')
96 .expect(400, done) 96 .expect(400, done)
97 }) 97 })
98 98
99 it('Should fail if urls are not unique', function (done) { 99 it('Should fail if the array is composed with http schemes', function (done) {
100 request(server.url) 100 request(server.url)
101 .post(path + '/makefriends') 101 .post(path + '/makefriends')
102 .send({ urls: [ 'http://localhost:9002', 'http://localhost:9002' ] }) 102 .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
103 .set('Authorization', 'Bearer ' + server.accessToken)
104 .set('Accept', 'application/json')
105 .expect(400, done)
106 })
107
108 it('Should fail if hosts are not unique', function (done) {
109 request(server.url)
110 .post(path + '/makefriends')
111 .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
103 .set('Authorization', 'Bearer ' + server.accessToken) 112 .set('Authorization', 'Bearer ' + server.accessToken)
104 .set('Accept', 'application/json') 113 .set('Accept', 'application/json')
105 .expect(400, done) 114 .expect(400, done)
@@ -153,27 +162,27 @@ describe('Test parameters validator', function () {
153 162
154 it('Should fail without public key', function (done) { 163 it('Should fail without public key', function (done) {
155 const data = { 164 const data = {
156 url: 'http://coucou.com' 165 host: 'coucou.com'
157 } 166 }
158 requestsUtils.makePostBodyRequest(server.url, path, null, data, done) 167 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
159 }) 168 })
160 169
161 it('Should fail without an url', function (done) { 170 it('Should fail without an host', function (done) {
162 const data = { 171 const data = {
163 publicKey: 'mysuperpublickey' 172 publicKey: 'mysuperpublickey'
164 } 173 }
165 requestsUtils.makePostBodyRequest(server.url, path, null, data, done) 174 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
166 }) 175 })
167 176
168 it('Should fail with an incorrect url', function (done) { 177 it('Should fail with an incorrect host', function (done) {
169 const data = { 178 const data = {
170 url: 'coucou.com', 179 host: 'http://coucou.com',
171 publicKey: 'mysuperpublickey' 180 publicKey: 'mysuperpublickey'
172 } 181 }
173 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { 182 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
174 data.url = 'http://coucou' 183 data.host = 'http://coucou'
175 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () { 184 requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
176 data.url = 'coucou' 185 data.host = 'coucou'
177 requestsUtils.makePostBodyRequest(server.url, path, null, data, done) 186 requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
178 }) 187 })
179 }) 188 })
@@ -181,7 +190,7 @@ describe('Test parameters validator', function () {
181 190
182 it('Should succeed with the correct parameters', function (done) { 191 it('Should succeed with the correct parameters', function (done) {
183 const data = { 192 const data = {
184 url: 'http://coucou.com', 193 host: 'coucou.com',
185 publicKey: 'mysuperpublickey' 194 publicKey: 'mysuperpublickey'
186 } 195 }
187 requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200) 196 requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)
diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.js
index 0d24481ef..0a2d58d82 100644
--- a/server/tests/api/friends-advanced.js
+++ b/server/tests/api/friends-advanced.js
@@ -203,7 +203,7 @@ describe('Test advanced friends', function () {
203 const result = res.body 203 const result = res.body
204 expect(result.length).to.equal(3) 204 expect(result.length).to.equal(3)
205 for (const pod of result) { 205 for (const pod of result) {
206 expect(pod.url).not.equal(servers[3].url) 206 expect(pod.host).not.equal(servers[3].host)
207 } 207 }
208 208
209 done() 209 done()
diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.js
index f1393b5ec..a871f9838 100644
--- a/server/tests/api/friends-basic.js
+++ b/server/tests/api/friends-basic.js
@@ -22,7 +22,7 @@ describe('Test basic friends', function () {
22 const friends = [] 22 const friends = []
23 for (let i = 0; i < servers.length; i++) { 23 for (let i = 0; i < servers.length; i++) {
24 if (servers[i].url === serverToTest.url) continue 24 if (servers[i].url === serverToTest.url) continue
25 friends.push(servers[i].url) 25 friends.push(servers[i].host)
26 } 26 }
27 27
28 podsUtils.getFriendsList(serverToTest.url, function (err, res) { 28 podsUtils.getFriendsList(serverToTest.url, function (err, res) {
@@ -32,12 +32,12 @@ describe('Test basic friends', function () {
32 expect(result).to.be.an('array') 32 expect(result).to.be.an('array')
33 expect(result.length).to.equal(2) 33 expect(result.length).to.equal(2)
34 34
35 const resultUrls = [ result[0].url, result[1].url ] 35 const resultHosts = [ result[0].host, result[1].host ]
36 expect(resultUrls[0]).to.not.equal(resultUrls[1]) 36 expect(resultHosts[0]).to.not.equal(resultHosts[1])
37 37
38 const errorString = 'Friends url do not correspond for ' + serverToTest.url 38 const errorString = 'Friends host do not correspond for ' + serverToTest.host
39 expect(friends).to.contain(resultUrls[0], errorString) 39 expect(friends).to.contain(resultHosts[0], errorString)
40 expect(friends).to.contain(resultUrls[1], errorString) 40 expect(friends).to.contain(resultHosts[1], errorString)
41 callback() 41 callback()
42 }) 42 })
43 } 43 }
@@ -95,7 +95,7 @@ describe('Test basic friends', function () {
95 expect(result.length).to.equal(1) 95 expect(result.length).to.equal(1)
96 96
97 const pod = result[0] 97 const pod = result[0]
98 expect(pod.url).to.equal(servers[2].url) 98 expect(pod.host).to.equal(servers[2].host)
99 expect(pod.score).to.equal(20) 99 expect(pod.score).to.equal(20)
100 expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true 100 expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
101 101
@@ -112,7 +112,7 @@ describe('Test basic friends', function () {
112 expect(result.length).to.equal(1) 112 expect(result.length).to.equal(1)
113 113
114 const pod = result[0] 114 const pod = result[0]
115 expect(pod.url).to.equal(servers[1].url) 115 expect(pod.host).to.equal(servers[1].host)
116 expect(pod.score).to.equal(20) 116 expect(pod.score).to.equal(20)
117 expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true 117 expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
118 118
@@ -170,7 +170,7 @@ describe('Test basic friends', function () {
170 const result = res.body 170 const result = res.body
171 expect(result).to.be.an('array') 171 expect(result).to.be.an('array')
172 expect(result.length).to.equal(1) 172 expect(result.length).to.equal(1)
173 expect(result[0].url).not.to.be.equal(servers[1].url) 173 expect(result[0].host).not.to.be.equal(servers[1].host)
174 callback() 174 callback()
175 }) 175 })
176 }, next) 176 }, next)
diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.js
index 770cee035..be278d7c5 100644
--- a/server/tests/api/multiple-pods.js
+++ b/server/tests/api/multiple-pods.js
@@ -100,7 +100,7 @@ describe('Test multiple pods', function () {
100 const video = videos[0] 100 const video = videos[0]
101 expect(video.name).to.equal('my super name for pod 1') 101 expect(video.name).to.equal('my super name for pod 1')
102 expect(video.description).to.equal('my super description for pod 1') 102 expect(video.description).to.equal('my super description for pod 1')
103 expect(video.podUrl).to.equal('localhost:9001') 103 expect(video.podHost).to.equal('localhost:9001')
104 expect(video.magnetUri).to.exist 104 expect(video.magnetUri).to.exist
105 expect(video.duration).to.equal(10) 105 expect(video.duration).to.equal(10)
106 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ]) 106 expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
@@ -162,7 +162,7 @@ describe('Test multiple pods', function () {
162 const video = videos[1] 162 const video = videos[1]
163 expect(video.name).to.equal('my super name for pod 2') 163 expect(video.name).to.equal('my super name for pod 2')
164 expect(video.description).to.equal('my super description for pod 2') 164 expect(video.description).to.equal('my super description for pod 2')
165 expect(video.podUrl).to.equal('localhost:9002') 165 expect(video.podHost).to.equal('localhost:9002')
166 expect(video.magnetUri).to.exist 166 expect(video.magnetUri).to.exist
167 expect(video.duration).to.equal(5) 167 expect(video.duration).to.equal(5)
168 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ]) 168 expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
@@ -241,7 +241,7 @@ describe('Test multiple pods', function () {
241 241
242 expect(video1.name).to.equal('my super name for pod 3') 242 expect(video1.name).to.equal('my super name for pod 3')
243 expect(video1.description).to.equal('my super description for pod 3') 243 expect(video1.description).to.equal('my super description for pod 3')
244 expect(video1.podUrl).to.equal('localhost:9003') 244 expect(video1.podHost).to.equal('localhost:9003')
245 expect(video1.magnetUri).to.exist 245 expect(video1.magnetUri).to.exist
246 expect(video1.duration).to.equal(5) 246 expect(video1.duration).to.equal(5)
247 expect(video1.tags).to.deep.equal([ 'tag1p3' ]) 247 expect(video1.tags).to.deep.equal([ 'tag1p3' ])
@@ -250,7 +250,7 @@ describe('Test multiple pods', function () {
250 250
251 expect(video2.name).to.equal('my super name for pod 3-2') 251 expect(video2.name).to.equal('my super name for pod 3-2')
252 expect(video2.description).to.equal('my super description for pod 3-2') 252 expect(video2.description).to.equal('my super description for pod 3-2')
253 expect(video2.podUrl).to.equal('localhost:9003') 253 expect(video2.podHost).to.equal('localhost:9003')
254 expect(video2.magnetUri).to.exist 254 expect(video2.magnetUri).to.exist
255 expect(video2.duration).to.equal(5) 255 expect(video2.duration).to.equal(5)
256 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ]) 256 expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.js
index 3125312ca..65d1a7a65 100644
--- a/server/tests/api/single-pod.js
+++ b/server/tests/api/single-pod.js
@@ -77,7 +77,7 @@ describe('Test a single pod', function () {
77 const video = res.body.data[0] 77 const video = res.body.data[0]
78 expect(video.name).to.equal('my super name') 78 expect(video.name).to.equal('my super name')
79 expect(video.description).to.equal('my super description') 79 expect(video.description).to.equal('my super description')
80 expect(video.podUrl).to.equal('localhost:9001') 80 expect(video.podHost).to.equal('localhost:9001')
81 expect(video.magnetUri).to.exist 81 expect(video.magnetUri).to.exist
82 expect(video.author).to.equal('root') 82 expect(video.author).to.equal('root')
83 expect(video.isLocal).to.be.true 83 expect(video.isLocal).to.be.true
@@ -111,7 +111,7 @@ describe('Test a single pod', function () {
111 const video = res.body 111 const video = res.body
112 expect(video.name).to.equal('my super name') 112 expect(video.name).to.equal('my super name')
113 expect(video.description).to.equal('my super description') 113 expect(video.description).to.equal('my super description')
114 expect(video.podUrl).to.equal('localhost:9001') 114 expect(video.podHost).to.equal('localhost:9001')
115 expect(video.magnetUri).to.exist 115 expect(video.magnetUri).to.exist
116 expect(video.author).to.equal('root') 116 expect(video.author).to.equal('root')
117 expect(video.isLocal).to.be.true 117 expect(video.isLocal).to.be.true
@@ -138,7 +138,7 @@ describe('Test a single pod', function () {
138 const video = res.body.data[0] 138 const video = res.body.data[0]
139 expect(video.name).to.equal('my super name') 139 expect(video.name).to.equal('my super name')
140 expect(video.description).to.equal('my super description') 140 expect(video.description).to.equal('my super description')
141 expect(video.podUrl).to.equal('localhost:9001') 141 expect(video.podHost).to.equal('localhost:9001')
142 expect(video.author).to.equal('root') 142 expect(video.author).to.equal('root')
143 expect(video.isLocal).to.be.true 143 expect(video.isLocal).to.be.true
144 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 144 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
@@ -153,8 +153,8 @@ describe('Test a single pod', function () {
153 }) 153 })
154 }) 154 })
155 155
156 it('Should search the video by podUrl', function (done) { 156 it('Should search the video by podHost', function (done) {
157 videosUtils.searchVideo(server.url, '9001', 'podUrl', function (err, res) { 157 videosUtils.searchVideo(server.url, '9001', 'podHost', function (err, res) {
158 if (err) throw err 158 if (err) throw err
159 159
160 expect(res.body.total).to.equal(1) 160 expect(res.body.total).to.equal(1)
@@ -164,7 +164,7 @@ describe('Test a single pod', function () {
164 const video = res.body.data[0] 164 const video = res.body.data[0]
165 expect(video.name).to.equal('my super name') 165 expect(video.name).to.equal('my super name')
166 expect(video.description).to.equal('my super description') 166 expect(video.description).to.equal('my super description')
167 expect(video.podUrl).to.equal('localhost:9001') 167 expect(video.podHost).to.equal('localhost:9001')
168 expect(video.author).to.equal('root') 168 expect(video.author).to.equal('root')
169 expect(video.isLocal).to.be.true 169 expect(video.isLocal).to.be.true
170 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 170 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
@@ -190,7 +190,7 @@ describe('Test a single pod', function () {
190 const video = res.body.data[0] 190 const video = res.body.data[0]
191 expect(video.name).to.equal('my super name') 191 expect(video.name).to.equal('my super name')
192 expect(video.description).to.equal('my super description') 192 expect(video.description).to.equal('my super description')
193 expect(video.podUrl).to.equal('localhost:9001') 193 expect(video.podHost).to.equal('localhost:9001')
194 expect(video.author).to.equal('root') 194 expect(video.author).to.equal('root')
195 expect(video.isLocal).to.be.true 195 expect(video.isLocal).to.be.true
196 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ]) 196 expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
@@ -425,7 +425,7 @@ describe('Test a single pod', function () {
425 }) 425 })
426 426
427 it('Should search all the 9001 port videos', function (done) { 427 it('Should search all the 9001 port videos', function (done) {
428 videosUtils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) { 428 videosUtils.searchVideoWithPagination(server.url, '9001', 'podHost', 0, 15, function (err, res) {
429 if (err) throw err 429 if (err) throw err
430 430
431 const videos = res.body.data 431 const videos = res.body.data
@@ -437,7 +437,7 @@ describe('Test a single pod', function () {
437 }) 437 })
438 438
439 it('Should search all the localhost videos', function (done) { 439 it('Should search all the localhost videos', function (done) {
440 videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) { 440 videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podHost', 0, 15, function (err, res) {
441 if (err) throw err 441 if (err) throw err
442 442
443 const videos = res.body.data 443 const videos = res.body.data
diff --git a/server/tests/utils/pods.js b/server/tests/utils/pods.js
index a8551a49d..25b97edec 100644
--- a/server/tests/utils/pods.js
+++ b/server/tests/utils/pods.js
@@ -30,25 +30,25 @@ function makeFriends (url, accessToken, expectedStatus, end) {
30 // Which pod makes friends with which pod 30 // Which pod makes friends with which pod
31 const friendsMatrix = { 31 const friendsMatrix = {
32 'http://localhost:9001': [ 32 'http://localhost:9001': [
33 'http://localhost:9002' 33 'localhost:9002'
34 ], 34 ],
35 'http://localhost:9002': [ 35 'http://localhost:9002': [
36 'http://localhost:9003' 36 'localhost:9003'
37 ], 37 ],
38 'http://localhost:9003': [ 38 'http://localhost:9003': [
39 'http://localhost:9001' 39 'localhost:9001'
40 ], 40 ],
41 'http://localhost:9004': [ 41 'http://localhost:9004': [
42 'http://localhost:9002' 42 'localhost:9002'
43 ], 43 ],
44 'http://localhost:9005': [ 44 'http://localhost:9005': [
45 'http://localhost:9001', 45 'localhost:9001',
46 'http://localhost:9004' 46 'localhost:9004'
47 ], 47 ],
48 'http://localhost:9006': [ 48 'http://localhost:9006': [
49 'http://localhost:9001', 49 'localhost:9001',
50 'http://localhost:9002', 50 'localhost:9002',
51 'http://localhost:9003' 51 'localhost:9003'
52 ] 52 ]
53 } 53 }
54 const path = '/api/v1/pods/makefriends' 54 const path = '/api/v1/pods/makefriends'
@@ -58,7 +58,7 @@ function makeFriends (url, accessToken, expectedStatus, end) {
58 .post(path) 58 .post(path)
59 .set('Accept', 'application/json') 59 .set('Accept', 'application/json')
60 .set('Authorization', 'Bearer ' + accessToken) 60 .set('Authorization', 'Bearer ' + accessToken)
61 .send({ 'urls': friendsMatrix[url] }) 61 .send({ 'hosts': friendsMatrix[url] })
62 .expect(expectedStatus) 62 .expect(expectedStatus)
63 .end(function (err, res) { 63 .end(function (err, res) {
64 if (err) throw err 64 if (err) throw err
diff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.js
index d62838bc7..01c9a2f39 100644
--- a/server/tests/utils/servers.js
+++ b/server/tests/utils/servers.js
@@ -47,6 +47,7 @@ function runServer (number, callback) {
47 const server = { 47 const server = {
48 app: null, 48 app: null,
49 url: `http://localhost:${9000 + number}`, 49 url: `http://localhost:${9000 + number}`,
50 host: `localhost:${9000 + number}`,
50 client: { 51 client: {
51 id: null, 52 id: null,
52 secret: null 53 secret: null