Server: adapt tests to host
authorChocobozzz <florian.bigard@gmail.com>
Mon, 14 Nov 2016 19:45:00 +0000 (20:45 +0100)
committerChocobozzz <florian.bigard@gmail.com>
Wed, 16 Nov 2016 19:29:26 +0000 (20:29 +0100)
server/tests/api/check-params.js
server/tests/api/friends-advanced.js
server/tests/api/friends-basic.js
server/tests/api/multiple-pods.js
server/tests/api/single-pod.js
server/tests/utils/pods.js
server/tests/utils/servers.js

index 07f41daab7fbd88c996d3b6b7804826180dee3a3..444c2fc558c80ff0b2dec7f2a3496ed943c4bc4a 100644 (file)
@@ -67,10 +67,10 @@ describe('Test parameters validator', function () {
 
       describe('When making friends', function () {
         const body = {
-          urls: [ 'http://localhost:9002' ]
+          hosts: [ 'localhost:9002' ]
         }
 
-        it('Should fail without urls', function (done) {
+        it('Should fail without hosts', function (done) {
           request(server.url)
             .post(path + '/makefriends')
             .set('Authorization', 'Bearer ' + server.accessToken)
@@ -78,28 +78,37 @@ describe('Test parameters validator', function () {
             .expect(400, done)
         })
 
-        it('Should fail with urls is not an array', function (done) {
+        it('Should fail if hosts is not an array', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: 'http://localhost:9002' })
+            .send({ hosts: 'localhost:9002' })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
         })
 
-        it('Should fail if the array is not composed by urls', function (done) {
+        it('Should fail if the array is not composed by hosts', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: [ 'http://localhost:9002', 'localhost:coucou' ] })
+            .send({ hosts: [ 'localhost:9002', 'localhost:coucou' ] })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
         })
 
-        it('Should fail if urls are not unique', function (done) {
+        it('Should fail if the array is composed with http schemes', function (done) {
           request(server.url)
             .post(path + '/makefriends')
-            .send({ urls: [ 'http://localhost:9002', 'http://localhost:9002' ] })
+            .send({ hosts: [ 'localhost:9002', 'http://localhost:9003' ] })
+            .set('Authorization', 'Bearer ' + server.accessToken)
+            .set('Accept', 'application/json')
+            .expect(400, done)
+        })
+
+        it('Should fail if hosts are not unique', function (done) {
+          request(server.url)
+            .post(path + '/makefriends')
+            .send({ urls: [ 'localhost:9002', 'localhost:9002' ] })
             .set('Authorization', 'Bearer ' + server.accessToken)
             .set('Accept', 'application/json')
             .expect(400, done)
@@ -153,27 +162,27 @@ describe('Test parameters validator', function () {
 
       it('Should fail without public key', function (done) {
         const data = {
-          url: 'http://coucou.com'
+          host: 'coucou.com'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
       })
 
-      it('Should fail without an url', function (done) {
+      it('Should fail without an host', function (done) {
         const data = {
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
       })
 
-      it('Should fail with an incorrect url', function (done) {
+      it('Should fail with an incorrect host', function (done) {
         const data = {
-          url: 'coucou.com',
+          host: 'http://coucou.com',
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
-          data.url = 'http://coucou'
+          data.host = 'http://coucou'
           requestsUtils.makePostBodyRequest(server.url, path, null, data, function () {
-            data.url = 'coucou'
+            data.host = 'coucou'
             requestsUtils.makePostBodyRequest(server.url, path, null, data, done)
           })
         })
@@ -181,7 +190,7 @@ describe('Test parameters validator', function () {
 
       it('Should succeed with the correct parameters', function (done) {
         const data = {
-          url: 'http://coucou.com',
+          host: 'coucou.com',
           publicKey: 'mysuperpublickey'
         }
         requestsUtils.makePostBodyRequest(server.url, path, null, data, done, 200)
index 0d24481ef64c79676fbbbb45307bab08a5544796..0a2d58d82ee47e9ed342b01a9eead089d498dee5 100644 (file)
@@ -203,7 +203,7 @@ describe('Test advanced friends', function () {
           const result = res.body
           expect(result.length).to.equal(3)
           for (const pod of result) {
-            expect(pod.url).not.equal(servers[3].url)
+            expect(pod.host).not.equal(servers[3].host)
           }
 
           done()
index f1393b5ec78dac8d71b4382660e1837a3ce74e58..a871f9838fb5ed911657fbc2310e056a1ad52206 100644 (file)
@@ -22,7 +22,7 @@ describe('Test basic friends', function () {
     const friends = []
     for (let i = 0; i < servers.length; i++) {
       if (servers[i].url === serverToTest.url) continue
-      friends.push(servers[i].url)
+      friends.push(servers[i].host)
     }
 
     podsUtils.getFriendsList(serverToTest.url, function (err, res) {
@@ -32,12 +32,12 @@ describe('Test basic friends', function () {
       expect(result).to.be.an('array')
       expect(result.length).to.equal(2)
 
-      const resultUrls = [ result[0].url, result[1].url ]
-      expect(resultUrls[0]).to.not.equal(resultUrls[1])
+      const resultHosts = [ result[0].host, result[1].host ]
+      expect(resultHosts[0]).to.not.equal(resultHosts[1])
 
-      const errorString = 'Friends url do not correspond for ' + serverToTest.url
-      expect(friends).to.contain(resultUrls[0], errorString)
-      expect(friends).to.contain(resultUrls[1], errorString)
+      const errorString = 'Friends host do not correspond for ' + serverToTest.host
+      expect(friends).to.contain(resultHosts[0], errorString)
+      expect(friends).to.contain(resultHosts[1], errorString)
       callback()
     })
   }
@@ -95,7 +95,7 @@ describe('Test basic friends', function () {
           expect(result.length).to.equal(1)
 
           const pod = result[0]
-          expect(pod.url).to.equal(servers[2].url)
+          expect(pod.host).to.equal(servers[2].host)
           expect(pod.score).to.equal(20)
           expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
 
@@ -112,7 +112,7 @@ describe('Test basic friends', function () {
           expect(result.length).to.equal(1)
 
           const pod = result[0]
-          expect(pod.url).to.equal(servers[1].url)
+          expect(pod.host).to.equal(servers[1].host)
           expect(pod.score).to.equal(20)
           expect(miscsUtils.dateIsValid(pod.createdDate)).to.be.true
 
@@ -170,7 +170,7 @@ describe('Test basic friends', function () {
             const result = res.body
             expect(result).to.be.an('array')
             expect(result.length).to.equal(1)
-            expect(result[0].url).not.to.be.equal(servers[1].url)
+            expect(result[0].host).not.to.be.equal(servers[1].host)
             callback()
           })
         }, next)
index 770cee035f093b6eb105b716c8a8efcad93b6dc7..be278d7c57bfba6d49e61e4254675566efb50de1 100644 (file)
@@ -100,7 +100,7 @@ describe('Test multiple pods', function () {
               const video = videos[0]
               expect(video.name).to.equal('my super name for pod 1')
               expect(video.description).to.equal('my super description for pod 1')
-              expect(video.podUrl).to.equal('localhost:9001')
+              expect(video.podHost).to.equal('localhost:9001')
               expect(video.magnetUri).to.exist
               expect(video.duration).to.equal(10)
               expect(video.tags).to.deep.equal([ 'tag1p1', 'tag2p1' ])
@@ -162,7 +162,7 @@ describe('Test multiple pods', function () {
               const video = videos[1]
               expect(video.name).to.equal('my super name for pod 2')
               expect(video.description).to.equal('my super description for pod 2')
-              expect(video.podUrl).to.equal('localhost:9002')
+              expect(video.podHost).to.equal('localhost:9002')
               expect(video.magnetUri).to.exist
               expect(video.duration).to.equal(5)
               expect(video.tags).to.deep.equal([ 'tag1p2', 'tag2p2', 'tag3p2' ])
@@ -241,7 +241,7 @@ describe('Test multiple pods', function () {
 
               expect(video1.name).to.equal('my super name for pod 3')
               expect(video1.description).to.equal('my super description for pod 3')
-              expect(video1.podUrl).to.equal('localhost:9003')
+              expect(video1.podHost).to.equal('localhost:9003')
               expect(video1.magnetUri).to.exist
               expect(video1.duration).to.equal(5)
               expect(video1.tags).to.deep.equal([ 'tag1p3' ])
@@ -250,7 +250,7 @@ describe('Test multiple pods', function () {
 
               expect(video2.name).to.equal('my super name for pod 3-2')
               expect(video2.description).to.equal('my super description for pod 3-2')
-              expect(video2.podUrl).to.equal('localhost:9003')
+              expect(video2.podHost).to.equal('localhost:9003')
               expect(video2.magnetUri).to.exist
               expect(video2.duration).to.equal(5)
               expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])
index 3125312caf614235910e357df18fd77d464a2414..65d1a7a65187ec64e5521fdc17c2014fad95dd56 100644 (file)
@@ -77,7 +77,7 @@ describe('Test a single pod', function () {
       const video = res.body.data[0]
       expect(video.name).to.equal('my super name')
       expect(video.description).to.equal('my super description')
-      expect(video.podUrl).to.equal('localhost:9001')
+      expect(video.podHost).to.equal('localhost:9001')
       expect(video.magnetUri).to.exist
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
@@ -111,7 +111,7 @@ describe('Test a single pod', function () {
       const video = res.body
       expect(video.name).to.equal('my super name')
       expect(video.description).to.equal('my super description')
-      expect(video.podUrl).to.equal('localhost:9001')
+      expect(video.podHost).to.equal('localhost:9001')
       expect(video.magnetUri).to.exist
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
@@ -138,7 +138,7 @@ describe('Test a single pod', function () {
       const video = res.body.data[0]
       expect(video.name).to.equal('my super name')
       expect(video.description).to.equal('my super description')
-      expect(video.podUrl).to.equal('localhost:9001')
+      expect(video.podHost).to.equal('localhost:9001')
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
@@ -153,8 +153,8 @@ describe('Test a single pod', function () {
     })
   })
 
-  it('Should search the video by podUrl', function (done) {
-    videosUtils.searchVideo(server.url, '9001', 'podUrl', function (err, res) {
+  it('Should search the video by podHost', function (done) {
+    videosUtils.searchVideo(server.url, '9001', 'podHost', function (err, res) {
       if (err) throw err
 
       expect(res.body.total).to.equal(1)
@@ -164,7 +164,7 @@ describe('Test a single pod', function () {
       const video = res.body.data[0]
       expect(video.name).to.equal('my super name')
       expect(video.description).to.equal('my super description')
-      expect(video.podUrl).to.equal('localhost:9001')
+      expect(video.podHost).to.equal('localhost:9001')
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
@@ -190,7 +190,7 @@ describe('Test a single pod', function () {
       const video = res.body.data[0]
       expect(video.name).to.equal('my super name')
       expect(video.description).to.equal('my super description')
-      expect(video.podUrl).to.equal('localhost:9001')
+      expect(video.podHost).to.equal('localhost:9001')
       expect(video.author).to.equal('root')
       expect(video.isLocal).to.be.true
       expect(video.tags).to.deep.equal([ 'tag1', 'tag2', 'tag3' ])
@@ -425,7 +425,7 @@ describe('Test a single pod', function () {
   })
 
   it('Should search all the 9001 port videos', function (done) {
-    videosUtils.searchVideoWithPagination(server.url, '9001', 'podUrl', 0, 15, function (err, res) {
+    videosUtils.searchVideoWithPagination(server.url, '9001', 'podHost', 0, 15, function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
@@ -437,7 +437,7 @@ describe('Test a single pod', function () {
   })
 
   it('Should search all the localhost videos', function (done) {
-    videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podUrl', 0, 15, function (err, res) {
+    videosUtils.searchVideoWithPagination(server.url, 'localhost', 'podHost', 0, 15, function (err, res) {
       if (err) throw err
 
       const videos = res.body.data
index a8551a49dc108358c9b4da3650d3921e81d4f259..25b97edec99685dce89f5996c80cb2147b8aae76 100644 (file)
@@ -30,25 +30,25 @@ function makeFriends (url, accessToken, expectedStatus, end) {
   // Which pod makes friends with which pod
   const friendsMatrix = {
     'http://localhost:9001': [
-      'http://localhost:9002'
+      'localhost:9002'
     ],
     'http://localhost:9002': [
-      'http://localhost:9003'
+      'localhost:9003'
     ],
     'http://localhost:9003': [
-      'http://localhost:9001'
+      'localhost:9001'
     ],
     'http://localhost:9004': [
-      'http://localhost:9002'
+      'localhost:9002'
     ],
     'http://localhost:9005': [
-      'http://localhost:9001',
-      'http://localhost:9004'
+      'localhost:9001',
+      'localhost:9004'
     ],
     'http://localhost:9006': [
-      'http://localhost:9001',
-      'http://localhost:9002',
-      'http://localhost:9003'
+      'localhost:9001',
+      'localhost:9002',
+      'localhost:9003'
     ]
   }
   const path = '/api/v1/pods/makefriends'
@@ -58,7 +58,7 @@ function makeFriends (url, accessToken, expectedStatus, end) {
     .post(path)
     .set('Accept', 'application/json')
     .set('Authorization', 'Bearer ' + accessToken)
-    .send({ 'urls': friendsMatrix[url] })
+    .send({ 'hosts': friendsMatrix[url] })
     .expect(expectedStatus)
     .end(function (err, res) {
       if (err) throw err
index d62838bc71529eb468bb8e54a76530b4a7142b5f..01c9a2f3919be10aca01595228072ad28c8a4f70 100644 (file)
@@ -47,6 +47,7 @@ function runServer (number, callback) {
   const server = {
     app: null,
     url: `http://localhost:${9000 + number}`,
+    host: `localhost:${9000 + number}`,
     client: {
       id: null,
       secret: null