aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorJosef Salyer <[email protected]>2013-07-28 20:46:38 -0400
committerJosef Salyer <[email protected]>2013-07-28 20:46:38 -0400
commit23d415779e9c20552aee5d66a69bd5f93737f079 (patch)
tree6f2427d0c8aa036e918b440b3bab99e7ce8e0ca7
parentd21bb4156b44b619c8d207714ea42727441e88b4 (diff)
downloadfaker-23d415779e9c20552aee5d66a69bd5f93737f079.tar.xz
faker-23d415779e9c20552aee5d66a69bd5f93737f079.zip
added tests and cleaned up at 100% in istanbul (not constantinople)
-rw-r--r--lib/finance.js15
-rw-r--r--lib/helpers.js2
-rw-r--r--test/finance.unit.js59
-rw-r--r--test/helpers.unit.js17
4 files changed, 73 insertions, 20 deletions
diff --git a/lib/finance.js b/lib/finance.js
index 61262125..daf2cc9e 100644
--- a/lib/finance.js
+++ b/lib/finance.js
@@ -25,10 +25,8 @@ var finance = {
mask: function(length, parens, elipsis){
//set defaults
- length = (length === null) ? 4 : length;
-
+ length = length || 4;
parens = (parens === null) ? true : parens;
-
elipsis = (elipsis === null) ? true : elipsis;
//create a template for length
@@ -56,18 +54,17 @@ var finance = {
amount: function(min, max, dec, symbol){
- if(!min) min = 1;
- if(!max) max = 1000;
- if(!dec) dec = 2;
- if(!symbol) symbol = ''; //default to nothing
-
+ min = min || 1;
+ max = max || 1000;
+ dec = dec || 2;
+ symbol = symbol || '';
return symbol + Math.round((Math.random() * (max - min) + min)*Math.pow(10,dec))/Math.pow(10,dec);
},
transactionType: function(){
- return Helpers.randomize(definitions.transaction_type());
+ return Helpers.randomize(definitions.transaction_type);
}
};
diff --git a/lib/helpers.js b/lib/helpers.js
index bc6f5b62..aef9746a 100644
--- a/lib/helpers.js
+++ b/lib/helpers.js
@@ -121,7 +121,7 @@ exports.createTransaction = function(){
"date" : new Date(2012, 1, 2), //TODO: add a ranged date method
"business": Faker.Company.companyName(),
"name": [Faker.Finance.accountName(), Faker.Finance.mask()].join(' '),
- "type" : exports.randomize(Faker.definitions.transaction_type()),
+ "type" : exports.randomize(Faker.definitions.transaction_type),
"account" : Faker.Finance.account()
};
};
diff --git a/test/finance.unit.js b/test/finance.unit.js
index cd88a6e2..3b33a991 100644
--- a/test/finance.unit.js
+++ b/test/finance.unit.js
@@ -77,7 +77,7 @@ describe('finance.js', function () {
var mask = Faker.Finance.mask(expected, false, false);
- var actual = mask.length;
+ var actual = mask.length || 4; //picks 4 if the random number generator picks 0
assert.equal(actual, expected, 'The expected default mask length is ' + expected + ' but it was ' + actual);
@@ -111,14 +111,12 @@ describe('finance.js', function () {
it("should work when random variables are passed into the arguments", function() {
- // var length = Faker.random.number(20);
-// var elipsis = (length % 2 === 0) ? true : false;
-// var parens = !elipsis;
-//
-// var expectedElipsis = new RegExp(/(\.\.\.)/);
-// var expectedParens = new RegExp(/(\(\d{}?\))/);
-// var expectedRegex = 0;
+ var length = Faker.random.number(20);
+ var elipsis = (length % 2 === 0) ? true : false;
+ var parens = !elipsis;
+ var mask = Faker.Finance.mask(length, elipsis, parens);
+ assert.ok(mask);
});
@@ -127,10 +125,47 @@ describe('finance.js', function () {
describe('amount(min, max, dec, symbol)', function(){
- it("should work when passing in nothing", function() {
+ it("should use the default amounts when not passing arguments", function() {
var amount = Faker.Finance.amount();
assert.ok(amount);
+ assert.equal((amount > 0), true, "the amount should be greater than 0");
+ assert.equal((amount < 1001), true, "the amount should be greater than 0");
+
+ });
+
+ it("should use the defaul decimal location when not passing arguments", function() {
+
+ var amount = Faker.Finance.amount();
+
+ var decimal = '.';
+ var expected = amount.length - 3;
+ var actual = amount.indexOf(decimal);
+
+ assert.equal(actual, expected, 'The expected location of the decimal is ' + expected + ' but it was ' + actual + ' amount ' + amount);
+ });
+
+ //TODO: add support for more currency and decimal options
+ it("should not include a currency symbol by default", function() {
+
+ var amount = Faker.Finance.amount();
+
+ var regexp = new RegExp(/[0-9.]/);
+
+ var expected = true;
+ var actual = regexp.test(amount);
+
+ assert.equal(actual, expected, 'The expected match should not include a currency symbol');
+ });
+
+
+ it("it should handle negative amounts", function() {
+
+ var amount = Faker.Finance.amount(-200, -1);
+
+ assert.ok(amount);
+ assert.equal((amount < 0), true, "the amount should be greater than 0");
+ assert.equal((amount > -201), true, "the amount should be greater than 0");
});
@@ -138,6 +173,10 @@ describe('finance.js', function () {
describe('transactionType()', function(){
-
+ it("should return a random transaction type", function() {
+ var transactionType = Faker.Finance.transactionType();
+
+ assert.ok(transactionType);
+ });
});
}); \ No newline at end of file
diff --git a/test/helpers.unit.js b/test/helpers.unit.js
index 3549099d..65c0f5e1 100644
--- a/test/helpers.unit.js
+++ b/test/helpers.unit.js
@@ -59,4 +59,21 @@ describe("helpers.js", function () {
assert.ok(arr.indexOf(elem) !== -1);
});
});
+
+ describe("createTransaction()", function() {
+ it("should create a random transaction", function() {
+ var transaction = Faker.Helpers.createTransaction();
+
+ assert.ok(transaction);
+ assert.ok(transaction.amount);
+ assert.ok(transaction.date);
+ assert.ok(transaction.business);
+ assert.ok(transaction.name);
+ assert.ok(transaction.type);
+ assert.ok(transaction.account);
+
+
+
+ });
+ });
});