aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authoralexpts <[email protected]>2017-02-11 09:24:12 +0300
committeralexpts <[email protected]>2017-02-11 09:24:12 +0300
commit434b3174b1cd3cf568c06aefbc2e8d000b397adf (patch)
treec64b1370e709bbf8a1442f981366b4209e209232
parent1df4877133afd18c65d187475872c2c52e508803 (diff)
downloadfaker-434b3174b1cd3cf568c06aefbc2e8d000b397adf.tar.xz
faker-434b3174b1cd3cf568c06aefbc2e8d000b397adf.zip
Fix aomount and price argument dec for case = 0. Add unit tests. Minor codestyle fix.
-rw-r--r--lib/commerce.js8
-rw-r--r--lib/finance.js26
-rw-r--r--test/commerce.unit.js17
-rw-r--r--test/finance.unit.js18
4 files changed, 51 insertions, 18 deletions
diff --git a/lib/commerce.js b/lib/commerce.js
index 306cf337..56e63dba 100644
--- a/lib/commerce.js
+++ b/lib/commerce.js
@@ -42,14 +42,16 @@ var Commerce = function (faker) {
* @param {number} max
* @param {number} dec
* @param {string} symbol
+ *
+ * @return {string}
*/
self.price = function(min, max, dec, symbol) {
min = min || 0;
max = max || 1000;
- dec = dec || 2;
+ dec = dec === undefined ? 2 : dec;
symbol = symbol || '';
- if(min < 0 || max < 0) {
+ if (min < 0 || max < 0) {
return symbol + 0.00;
}
@@ -109,7 +111,7 @@ var Commerce = function (faker) {
*/
self.product = function() {
return faker.random.arrayElement(faker.definitions.commerce.product_name.product);
- }
+ };
return self;
};
diff --git a/lib/finance.js b/lib/finance.js
index c7a0e881..56b74e8a 100644
--- a/lib/finance.js
+++ b/lib/finance.js
@@ -1,5 +1,4 @@
/**
- *
* @namespace faker.finance
*/
var Finance = function (faker) {
@@ -23,7 +22,7 @@ var Finance = function (faker) {
}
length = null;
return Helpers.replaceSymbolWithNumber(template);
- }
+ };
/**
* accountName
@@ -33,7 +32,7 @@ var Finance = function (faker) {
self.accountName = function () {
return [Helpers.randomize(faker.definitions.finance.account_type), 'Account'].join(' ');
- }
+ };
/**
* mask
@@ -45,7 +44,6 @@ var Finance = function (faker) {
*/
self.mask = function (length, parens, elipsis) {
-
//set defaults
length = (length == 0 || !length || typeof length == 'undefined') ? 4 : length;
parens = (parens === null) ? true : parens;
@@ -67,8 +65,7 @@ var Finance = function (faker) {
template = Helpers.replaceSymbolWithNumber(template);
return template;
-
- }
+ };
//min and max take in minimum and maximum amounts, dec is the decimal place you want rounded to, symbol is $, €, £, etc
//NOTE: this returns a string representation of the value, if you want a number use parseFloat and no symbol
@@ -81,6 +78,8 @@ var Finance = function (faker) {
* @param {number} max
* @param {number} dec
* @param {string} symbol
+ *
+ * @return {string}
*/
self.amount = function (min, max, dec, symbol) {
@@ -91,8 +90,7 @@ var Finance = function (faker) {
var randValue = faker.random.number({ max: max, min: min, precision: Math.pow(10, -dec) });
return symbol + randValue.toFixed(dec);
-
- }
+ };
/**
* transactionType
@@ -101,7 +99,7 @@ var Finance = function (faker) {
*/
self.transactionType = function () {
return Helpers.randomize(faker.definitions.finance.transaction_type);
- }
+ };
/**
* currencyCode
@@ -110,7 +108,7 @@ var Finance = function (faker) {
*/
self.currencyCode = function () {
return faker.random.objectElement(faker.definitions.finance.currency)['code'];
- }
+ };
/**
* currencyName
@@ -119,7 +117,7 @@ var Finance = function (faker) {
*/
self.currencyName = function () {
return faker.random.objectElement(faker.definitions.finance.currency, 'key');
- }
+ };
/**
* currencySymbol
@@ -133,7 +131,7 @@ var Finance = function (faker) {
symbol = faker.random.objectElement(faker.definitions.finance.currency)['symbol'];
}
return symbol;
- }
+ };
/**
* bitcoinAddress
@@ -149,7 +147,7 @@ var Finance = function (faker) {
address += faker.random.alphaNumeric().toUpperCase();
return address;
- }
-}
+ };
+};
module['exports'] = Finance;
diff --git a/test/commerce.unit.js b/test/commerce.unit.js
index 06445e34..12b06887 100644
--- a/test/commerce.unit.js
+++ b/test/commerce.unit.js
@@ -110,6 +110,23 @@ describe("commerce.js", function() {
assert.ok(amount);
assert.equal((amount == 0.00), true, "the amount should equal 0");
});
+
+ it("it should handle argument dec", function () {
+
+ var price = faker.commerce.price(100, 100, 1);
+
+ assert.ok(price);
+ assert.strictEqual(price , '100.0', "the price should be equal 100.0");
+ });
+
+ it("it should handle argument dec = 0", function () {
+
+ var price = faker.commerce.price(100, 100, 0);
+
+ assert.ok(price);
+ assert.strictEqual(price , '100', "the price should be equal 100");
+ });
+
});
}); \ No newline at end of file
diff --git a/test/finance.unit.js b/test/finance.unit.js
index 6bbb51c6..22461f22 100644
--- a/test/finance.unit.js
+++ b/test/finance.unit.js
@@ -184,6 +184,22 @@ describe('finance.js', function () {
});
+ it("it should handle argument dec", function () {
+
+ var amount = faker.finance.amount(100, 100, 1);
+
+ assert.ok(amount);
+ assert.strictEqual(amount , '100.0', "the amount should be equal 100.0");
+ });
+
+ it("it should handle argument dec = 0", function () {
+
+ var amount = faker.finance.amount(100, 100, 0);
+
+ assert.ok(amount);
+ assert.strictEqual(amount , '100', "the amount should be equal 100");
+ });
+
});
describe('transactionType()', function () {
@@ -201,7 +217,7 @@ describe('finance.js', function () {
assert.ok(currencyCode.match(/[A-Z]{3}/));
});
- })
+ });
describe("bitcoinAddress()", function(){
it("returns a random bitcoin address", function(){