Comparing version 0.1.3-beta8 to 0.1.3-beta9
@@ -55,3 +55,4 @@ /* | ||
"type" : "UbivarError" | ||
, "populate": function(raw){ | ||
/* Populate a raw error */ | ||
, "populate": function(raw){ | ||
this.type = this.type | ||
@@ -70,3 +71,3 @@ this.stack = (new Error(raw.message)).stack | ||
* Helper factory that returns an instance of UbivarError | ||
* @rawUbivarError [Error] | ||
* @rawUbivarError [Error] a raw error | ||
*/ | ||
@@ -73,0 +74,0 @@ UbivarError.generate = function(rawUbivarError){ |
@@ -5,2 +5,13 @@ var path = require("path") | ||
, _ = require("lodash") | ||
, RESOURCES = [ | ||
"accounts" | ||
, "transactions" | ||
, "orders" | ||
, "login" | ||
, "logout" | ||
, "items" | ||
, "labels" | ||
, "fx" | ||
, "me" | ||
] | ||
@@ -19,3 +30,2 @@ /* | ||
, theName = "Ubivar/v1 NodeBindings/" + theVersion | ||
, theResources = ["accounts","transactions","orders","login","logout","items","labels","me"] | ||
, theRevokedCerts = fs.readFileSync(path.join(__dirname, pathFingerprints) | ||
@@ -27,3 +37,3 @@ , 'utf8').replace(/^\s+|\s+$/g, '').split('\n') | ||
, "timeout" : theTimeout | ||
, "resources" : theResources | ||
, "resources" : RESOURCES | ||
, "revokedCerts" : theRevokedCerts | ||
@@ -30,0 +40,0 @@ , "headers" : { |
{ | ||
"name": "ubivar", | ||
"version": "0.1.3-beta8", | ||
"version": "0.1.3-beta9", | ||
"description": "API wrapper to Ubivar", | ||
@@ -5,0 +5,0 @@ "main": "lib/index.js", |
@@ -6,2 +6,3 @@ "use strict" | ||
, ubivar = require("../ubivar") | ||
, token = process.env.UBIVAR_TEST_TOKEN | ||
@@ -12,3 +13,3 @@ describe("Resources", function() { | ||
, methods = ["create", "retrieve", "update", "del", "list"] | ||
, resources = _.difference(ubivar.get("resources"), ["me"]) | ||
, resources = _.difference(ubivar.get("resources"), ["me","fx"]) | ||
@@ -74,6 +75,6 @@ describe("Properties", function(){ | ||
testIt("unauthToken", false) | ||
testIt(process.env.UBIVAR_TEST_TOKEN, true) | ||
testIt(token, true) | ||
it("Should update me", function(done){ | ||
var ubivar = require("../../lib")(process.env.UBIVAR_TEST_TOKEN, "latest") | ||
var ubivar = require("../../lib")(token, "latest") | ||
ubivar.me.retrieve(function(err, res){ | ||
@@ -97,3 +98,3 @@ var me = res.data[0] | ||
it("Should fail to delete me", function(done){ | ||
var ubivar = require("../../lib")(process.env.UBIVAR_TEST_TOKEN, "latest") | ||
var ubivar = require("../../lib")(token, "latest") | ||
ubivar.me.del(function(err, res){ | ||
@@ -109,3 +110,3 @@ if(err){ | ||
it("Should list a single me", function(done){ | ||
var ubivar = require("../../lib")(process.env.UBIVAR_TEST_TOKEN, "latest") | ||
var ubivar = require("../../lib")(token, "latest") | ||
ubivar.me.list(function(err, res){ | ||
@@ -123,2 +124,76 @@ if(!err && res.status === 200 && res.data.length === 1){ | ||
describe("FX", function(){ | ||
it("Should retrieve FX", function(done){ | ||
ubivar.fx.retrieve(function(err, res){ | ||
if(err){ | ||
done(err) | ||
} else if(!(res.status === 200 && res.data.length === 1)){ | ||
done(new Error("Did not return FX of the day ")) | ||
} else{ | ||
var fx = res.data[0] | ||
if(fx.cur_from !== "EUR"){ | ||
done(new Error("Returned 'cur_from' does not default to EUR")) | ||
} else if(fx.cur_to !== "USD"){ | ||
done(new Error("Returned 'cur_to' does not default to USD")) | ||
} else if((new Date()-new Date(fx.date))/(1000*60*60*24) > 1){ | ||
done(new Error("Latest FX should be less than one day old")) | ||
} else if(!_.isNumber(fx.rate)) { | ||
done(new Error("Did not return a number")) | ||
} else { | ||
done() | ||
} | ||
} | ||
}) | ||
}) | ||
it("Should return exchange rate between non-default 'cur'", function(done){ | ||
var cur_from = "CAD" | ||
, cur_to = "GBP" | ||
ubivar.fx.list({"cur_from":cur_from, "cur_to":cur_to}, function(err, res){ | ||
if(err){ | ||
done(err) | ||
} else if(!(res.status === 200 && res.data.length === 1)){ | ||
done(new Error("Did not return FX of the day for two custom currencies")) | ||
} else { | ||
var fx = res.data[0] | ||
if(fx.cur_from !== cur_from){ | ||
done(new Error("Did not return the custom 'cur_from'")) | ||
} else if(fx.cur_to !== cur_to){ | ||
done(new Error("Did not return the custom 'cur_to'")) | ||
} else if(!_.isNumber(fx.rate)) { | ||
done(new Error("Did not return a number")) | ||
} else { | ||
done() | ||
} | ||
} | ||
}) | ||
}) | ||
it("Should return fx rate for a specific date", function(done){ | ||
var date = "2015-01-01" | ||
ubivar.fx.list({"date":date}, function(err, res){ | ||
if(err){ | ||
done(err) | ||
} else if(!(res.status === 200 && res.data.length === 1)){ | ||
done(new Error("Did not return FX of the day for two custom currencies")) | ||
} else { | ||
var fx = res.data[0] | ||
if((new Date(date)-new Date(fx.date))/(1000*60*60*24) > 1){ | ||
done(new Error("Did not return the custom 'date'")) | ||
} else if(!_.isNumber(fx.rate)) { | ||
done(new Error("Did not return a number")) | ||
} else if(fx.rate !== 1.2141) { | ||
console.log(res) | ||
done(new Error("Did not return the correct EUR/USD FX rate")) | ||
} else { | ||
done() | ||
} | ||
} | ||
}) | ||
}) | ||
}) | ||
_.each(resources, function(resource){ | ||
@@ -130,4 +205,2 @@ describe(resource[0].toUpperCase() + resource.slice(1) | ||
it("Should create and return a resource", function(done){ | ||
@@ -134,0 +207,0 @@ ubivar[resource].create(example[0], function(err, res){ |
Sorry, the diff of this file is not supported yet
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
41034
29
931
7