Skip to content

Commit

Permalink
fix(forex): should always convert to same currency
Browse files Browse the repository at this point in the history
  • Loading branch information
richardschneider committed Nov 19, 2016
1 parent 734f36e commit ae73372
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 1 deletion.
3 changes: 2 additions & 1 deletion docs/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ <h1>Welcome</h1>
<li><a href="#">EUR</a></li>
<li><a href="#">USD</a></li>
<li><a href="#">JPY</a></li>
<li><a href="#">INR</a></li>
<li><a href="#">NZD</a></li>
<li><a href="#">XBT</a></li>
</ul>
Expand Down Expand Up @@ -94,7 +95,7 @@ <h4>Resources</h4>

<script>
var locales = [
'jp', 'zh-Hans-CN', 'zh-Hans-CN-u-nu-hanidec', 'th-TH-u-nu-thai',
'jp', 'hi-IN', 'zh-Hans-CN', 'zh-Hans-CN-u-nu-hanidec', 'th-TH-u-nu-thai',
'fr-FR', 'fr-CA', 'de-DE', 'en-US', 'en-GB'
];
$(document).ready(function() {
Expand Down
3 changes: 3 additions & 0 deletions lib/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -174,6 +174,9 @@ Money.prototype.isNegative = function isNegative() {
};

Money.prototype.to = function to(currency) {
if (this.currency === currency) {
return Promise.resolve(this);
}
if (!iso4217.test(currency)) {
return Promise.reject(new Error(`'${currency}' is not a valid ISO-4217 currency code`));
}
Expand Down
5 changes: 5 additions & 0 deletions test/money.js
Original file line number Diff line number Diff line change
Expand Up @@ -372,6 +372,11 @@ describe('Money', () => {
.should.be.rejected();
});

it('should always convert to same currency', () => {
let nzd = new Money('100 NZD');
return nzd.to('NZD').should.finally.equal(nzd);
});

});

});

0 comments on commit ae73372

Please sign in to comment.