Skip to content

Instantly share code, notes, and snippets.

@jxm262
Last active August 29, 2015 14:11
Show Gist options
  • Save jxm262/e94c087796ff3ca00409 to your computer and use it in GitHub Desktop.
Save jxm262/e94c087796ff3ca00409 to your computer and use it in GitHub Desktop.
/**
* Todo: have no idea if this is the best way to organize this, please pm for
* suggestions
*/
var xchange = require('../xchange.js')
,assert = require("assert")
,chai = require('chai')
,sinon = require('sinon')
,expect = chai.expect;
describe('xchange library', function() {
it('should have a bistamp object', function() {
assert.equal(typeof xchange.bitstamp, 'object');
});
});
describe('bitstamp object', function() {
var bitstamp = xchange.bitstamp;
before(function(done) {
sinon.stub(request).yields(null, null, JSON.stringify({ //error here , request is not defined. Although, it will work if I use xchange.request, but then breaks in the test below
name : 'justin'
}));
done();
});
it('should have a getTicker function', function() {
assert.equal(typeof bitstamp.getTicker, 'function');
});
it('getTicker function should call bitstamp ticker', function(done) {
bitstamp.getTicker(function(error, result){
request.get.called.should.be.equal(true); //error request not defined. even if i use xchange.request
done();
});
});
});
'use strict';
var request = require('request');
function Bitstamp() {
};
Bitstamp.prototype.getTicker = function(callback) {
request('https://www.bitstamp.net/api/ticker/', function(error, response, body) {
if (error) {
callback(error);
} else {
callback(null, response, body);
}
});
};
exports.bitstamp = new Bitstamp();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment