Skip to content

Commit

Permalink
bugfix on 0 amount inside object
Browse files Browse the repository at this point in the history
  • Loading branch information
davidkalosi committed Aug 29, 2015
1 parent f398fe6 commit e333f29
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 3 deletions.
4 changes: 2 additions & 2 deletions lib/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -210,7 +210,7 @@ module.exports = Money;

module.exports.fromInteger = function (amount, currency) {
if (_.isObject(amount)) {
if (!amount.amount || !amount.currency)
if (amount.amount === undefined || amount.currency === undefined)
throw new TypeError('Missing required parameters amount,currency');

currency = amount.currency;
Expand All @@ -227,7 +227,7 @@ module.exports.fromDecimal = function(amount, currency) {
var multipliers = [0, 10, 100, 1000];

if (_.isObject(amount)) {
if (!amount.amount || !amount.currency)
if (amount.amount === undefined || amount.currency === undefined)
throw new TypeError('Missing required parameters amount,currency');

currency = amount.currency;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"name": "js-money",
"description": "JavaScript implementation of the Money value object.",
"version": "0.3.1",
"version": "0.4.0",
"main": "./lib",
"author": {
"name": "David Kalosi",
Expand Down
7 changes: 7 additions & 0 deletions test/money.test.js
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,13 @@ describe('Money', function () {
expect(money.currency).to.equal('EUR');
});

it('should create a new instance from zero integer', function () {
var money = Money.fromInteger(0,Money.EUR);

expect(money.amount).to.equal(0);
expect(money.currency).to.equal('EUR');
});

it('should create a new instance with correct decimals from object', function () {
var money = Money.fromDecimal({amount: 11.5, currency: 'EUR'});

Expand Down

0 comments on commit e333f29

Please sign in to comment.