ActivityPub-federated video streaming platform using P2P directly in your web browser
Server: adapt tests to host
Chocobozzza4254ea1738d
diff --git a/server/tests/api/check-params.js b/server/tests/api/check-params.jsindex 07f41daab7..444c2fc558 100644--- a/server/tests/api/check-params.js+++ b/server/tests/api/check-params.js@@ -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)diff --git a/server/tests/api/friends-advanced.js b/server/tests/api/friends-advanced.jsindex 0d24481ef6..0a2d58d82e 100644--- a/server/tests/api/friends-advanced.js+++ b/server/tests/api/friends-advanced.js@@ -203,7 +203,7 @@ describe('Test advanced friends', function () {const result = res.bodyexpect(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()diff --git a/server/tests/api/friends-basic.js b/server/tests/api/friends-basic.jsindex f1393b5ec7..a871f9838f 100644--- a/server/tests/api/friends-basic.js+++ b/server/tests/api/friends-basic.js@@ -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.bodyexpect(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)diff --git a/server/tests/api/multiple-pods.js b/server/tests/api/multiple-pods.jsindex 770cee035f..be278d7c57 100644--- a/server/tests/api/multiple-pods.js+++ b/server/tests/api/multiple-pods.js@@ -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.existexpect(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.existexpect(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.existexpect(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.existexpect(video2.duration).to.equal(5)expect(video2.tags).to.deep.equal([ 'tag2p3', 'tag3p3', 'tag4p3' ])diff --git a/server/tests/api/single-pod.js b/server/tests/api/single-pod.jsindex 3125312caf..65d1a7a651 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 () {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.existexpect(video.author).to.equal('root')expect(video.isLocal).to.be.true@@ -111,7 +111,7 @@ describe('Test a single pod', function () {const video = res.bodyexpect(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.existexpect(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.trueexpect(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 errexpect(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.trueexpect(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.trueexpect(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 errconst 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 errconst videos = res.body.datadiff --git a/server/tests/utils/pods.js b/server/tests/utils/pods.jsindex a8551a49dc..25b97edec9 100644--- a/server/tests/utils/pods.js+++ b/server/tests/utils/pods.js@@ -30,25 +30,25 @@ function makeFriends (url, accessToken, expectedStatus, end) {// Which pod makes friends with which podconst 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 errdiff --git a/server/tests/utils/servers.js b/server/tests/utils/servers.jsindex d62838bc71..01c9a2f391 100644--- a/server/tests/utils/servers.js+++ b/server/tests/utils/servers.js@@ -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