2015-03-22 07:37:12 +00:00
|
|
|
var chai = require('chai');
|
|
|
|
var assert = chai.assert;
|
|
|
|
var RequestManager = require('../lib/web3/requestmanager');
|
2015-03-23 14:57:36 +00:00
|
|
|
var FakeHttpProvider = require('./helpers/FakeHttpProvider');
|
2015-03-22 08:20:24 +00:00
|
|
|
|
|
|
|
// TODO: handling errors!
|
2015-03-22 08:43:07 +00:00
|
|
|
// TODO: validation of params!
|
2015-03-22 07:37:12 +00:00
|
|
|
|
2015-03-25 22:50:39 +00:00
|
|
|
describe('lib/web3/requestmanager', function () {
|
2015-03-22 08:20:24 +00:00
|
|
|
describe('send', function () {
|
|
|
|
it('should return expected result synchronously', function () {
|
|
|
|
var provider = new FakeHttpProvider();
|
2015-10-08 02:45:15 +00:00
|
|
|
var manager = new RequestManager(provider);
|
2015-03-22 08:20:24 +00:00
|
|
|
var expected = 'hello_world';
|
|
|
|
provider.injectResult(expected);
|
|
|
|
|
|
|
|
var result = manager.send({
|
|
|
|
method: 'test',
|
|
|
|
params: [1,2,3]
|
|
|
|
});
|
|
|
|
|
|
|
|
assert.equal(expected, result);
|
|
|
|
});
|
|
|
|
|
|
|
|
it('should return expected result asynchronously', function (done) {
|
|
|
|
var provider = new FakeHttpProvider();
|
2015-10-08 02:45:15 +00:00
|
|
|
var manager = new RequestManager(provider);
|
2015-03-22 08:20:24 +00:00
|
|
|
var expected = 'hello_world';
|
|
|
|
provider.injectResult(expected);
|
|
|
|
|
|
|
|
manager.sendAsync({
|
|
|
|
method: 'test',
|
|
|
|
params: [1,2,3]
|
|
|
|
}, function (error, result) {
|
|
|
|
assert.equal(error, null);
|
|
|
|
assert.equal(expected, result);
|
|
|
|
done();
|
|
|
|
});
|
|
|
|
});
|
|
|
|
});
|
2015-03-22 07:37:12 +00:00
|
|
|
});
|
|
|
|
|