UNPKG

dl

Version:

DreamLab Libs

100 lines (89 loc) 3.47 kB
xdescribe('OpalRequest', function(){ var OpalRequest; var UrlRequest; var testParams; var req; var host; var simpleHost; var secureHost; var application; var method; var gatewayHost; var gatewayPort; it('requirements', function(){ OpalRequest = require('../../lib/opal/OpalRequest.js').OpalRequest; UrlRequest = require('../../lib/http/Request.js').Request; beforeEach(function(){ testParams = { url: 'anubisqi.obmap.onetapi.pl', method: 'search', params: { args: {1: 1}, context: 'onet/szukaj2', limit: 5, offset: 0, query: '1234', views: { 1: 'article/news', 2: 'media' } }, application: 'test.application.pl' }; req = new OpalRequest(testParams); host = 'testowy.host.pl'; simpleHost = 'http://testowy.host.pl'; secureHost = 'https://testowy.host.pl'; application = 'xxx.application.pl'; method = 'testRemoteMethod'; gatewayHost = 'xxx.int.application.pl'; gatewayPort = 666; }); }); it('constructor', function(){ expect(req.getGatewayHost()).toEqual(testParams.url); expect(req.getGatewayPort()).toEqual(80); expect(req.getRemoteMethod()).toEqual(testParams.method); expect(req.getMethod()).toEqual(UrlRequest.POST); expect(req.getApplication()).toEqual(testParams.application); var data = JSON.parse(req.getData()); expect(data.jsonrpc).toEqual('2.0'); expect(data.id.indexOf(req.getRemoteMethod())).toBeGreaterThan(-1); expect(data.method).toEqual(req.getRemoteMethod()); expect(data.params).toEqual(testParams.params); }); it('simpleHost', function(){ testParams.url = simpleHost; req = new OpalRequest(testParams); expect(req.getGatewayPort()).toEqual(80); expect(req.getGatewayHost()).toEqual(testParams.url); expect(req.getHost()).toEqual(testParams.url.replace('http://', '')); }); it('secureHost', function(){ testParams.url = secureHost; req = new OpalRequest(testParams); expect(req.getGatewayPort()).toEqual(443); expect(req.getGatewayHost()).toEqual(testParams.url); expect(req.getHost()).toEqual(testParams.url.replace('https://', '')); }); it('setGetHost', function(){ expect(req.setHost(host)).toBe(req); expect(req.getHost()).toEqual(host); }); it('setGetApplication', function(){ expect(req.setApplication(application)).toBe(req); expect(req.getApplication()).toEqual(application); }); it('setGetRemoteMethod', function(){ expect(req.setRemoteMethod(method)).toBe(req); expect(req.getRemoteMethod()).toEqual(method); }); it('setGetGatewayHost', function(){ expect(req.setGatewayHost(gatewayHost)).toBe(req); expect(req.getGatewayHost()).toEqual(gatewayHost); }); it('setGetGatewayHost', function(){ expect(req.setGatewayPort(gatewayPort)).toBe(req); expect(req.getGatewayPort()).toEqual(gatewayPort); }); });