UNPKG

dl

Version:

DreamLab Libs

70 lines (52 loc) 2.48 kB
describe('GetFunctionListMethod', function () { it('require', function () { var GetFunctionListMethod = null; expect(function () { GetFunctionListMethod = require('../../lib/jsonrpc/GetFunctionListMethod.js').GetFunctionListMethod; }).not.toThrow(); expect(GetFunctionListMethod).toBeDefined(); }); it('creation', function () { var getFunctionListMethod = null; var GetFunctionListMethod = require('../../lib/jsonrpc/GetFunctionListMethod.js').GetFunctionListMethod; expect(function () { getFunctionListMethod = new GetFunctionListMethod(); }).not.toThrow(); expect(getFunctionListMethod instanceof GetFunctionListMethod).toBeTruthy(); }); it('execute', function () { var GetFunctionListMethod = require('../../lib/jsonrpc/GetFunctionListMethod.js').GetFunctionListMethod; var JsonRpcMethod = require('core').jsonrpc.JsonRpcMethod; var Request = require('core').http.Request; var Response = require('core').http.Response; var OpalServer = require('../../lib/opal/OpalServer.js').OpalServer; var YAML = require('core').yaml.YAML; var event = null; var res = new Response(); var req = new Request(); req.setHeader('host', 'public.test.onetapi.pl'); spyOn(YAML, 'parseFileSync').andReturn([{interfaces:{'public':{},'admin':{}}}]); OpalServer.prototype._addMethods = function () { this._methods['public:test'] = {}; this._methods['public:test2'] = {}; }; var opalServer = new OpalServer(); opalServer.stopEventLoopMeasure(); var getFunctionListMethod = new GetFunctionListMethod(req, res, opalServer); getFunctionListMethod.addEventListener(JsonRpcMethod.Event.OK, function (e) { event = e; }); getFunctionListMethod.execute(); waitsFor(function () { return event; }, "GetFunctionListMethod never emitted JsonRpcMethod.Event.OK", 1000); runs(function () { expect(event).toBeTruthy(); expect(event.type).toBe(JsonRpcMethod.Event.OK); expect(event.data).toEqual({ list: [ { funcname: 'test', description: 'public:test' }, { funcname: 'test2', description: 'public:test2' } ]}); }); }); });