aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authorMarak <[email protected]>2014-09-13 20:27:50 +0200
committerMarak <[email protected]>2014-09-13 20:27:50 +0200
commit9f3fa0f8b7a8cc4f06fe545af02aca34e473c521 (patch)
treedc3b59ba68063106907416f9127c8826eea1e007 /test
parentc39e254f2775aa4fcf48b05c9a61b78b74843830 (diff)
parenta5da426f33aab13d0946be2c14ae0dae7c302500 (diff)
downloadfaker-9f3fa0f8b7a8cc4f06fe545af02aca34e473c521.tar.xz
faker-9f3fa0f8b7a8cc4f06fe545af02aca34e473c521.zip
[api] Added basic financial generators Closes #32
Merge https://github.com/josefsalyer/Faker.js
Diffstat (limited to 'test')
-rw-r--r--test/finance.unit.js197
-rw-r--r--test/helpers.unit.js13
2 files changed, 210 insertions, 0 deletions
diff --git a/test/finance.unit.js b/test/finance.unit.js
new file mode 100644
index 00000000..1a8978d6
--- /dev/null
+++ b/test/finance.unit.js
@@ -0,0 +1,197 @@
+if (typeof module !== 'undefined') {
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
+}
+
+
+describe('finance.js', function () {
+ describe('account( length )', function () {
+
+ it('should supply a default length if no length is passed', function () {
+
+ var account = faker.Finance.account();
+
+ var expected = 8;
+ var actual = account.length;
+
+ assert.equal(actual, expected, 'The expected default account length is ' + expected + ' but it was ' + actual);
+
+ });
+
+ it('should supply a length if a length is passed', function () {
+
+ var expected = 9;
+
+ var account = faker.Finance.account(expected);
+
+ var actual = account.length;
+
+ assert.equal(actual, expected, 'The expected default account length is ' + expected + ' but it was ' + actual);
+
+ });
+
+ it('should supply a default length if a zero is passed', function () {
+
+ var expected = 8;
+
+ var account = faker.Finance.account(0);
+
+ var actual = account.length;
+
+ assert.equal(actual, expected, 'The expected default account length is ' + expected + ' but it was ' + actual);
+
+ });
+
+ });
+
+ describe('accountName()', function () {
+
+ it("should return an account name", function () {
+
+ var actual = faker.Finance.accountName();
+
+ assert.ok(actual);
+
+ });
+
+ });
+
+
+ describe('mask( length, parens, elipsis )', function () {
+ it("should set a default length", function () {
+
+ var expected = 4; //default account mask length
+
+ var mask = faker.Finance.mask(null, false, false);
+
+ var actual = mask.length;
+
+ assert.equal(actual, expected, 'The expected default mask length is ' + expected + ' but it was ' + actual);
+
+ });
+
+ it("should set a specified length", function () {
+
+ var expected = faker.random.number(20);
+
+ expected = (expected == 0 || !expected || typeof expected == 'undefined') ? 4 : expected;
+
+ var mask = faker.Finance.mask(expected, false, false);
+
+ var actual = mask.length; //picks 4 if the random number generator picks 0
+
+ assert.equal(actual, expected, 'The expected default mask length is ' + expected + ' but it was ' + actual);
+
+ });
+
+ it("should set a default length of 4 for a zero value", function () {
+
+ var expected = 4;
+
+ var mask = faker.Finance.mask(0, false, false);
+
+ var actual = 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);
+
+ });
+
+
+ it("should by default include parentheses around a partial account number", function () {
+
+ var expected = true;
+
+ var mask = faker.Finance.mask(null, null, false);
+
+ var regexp = new RegExp(/(\(\d{4}?\))/);
+ var actual = regexp.test(mask);
+
+ assert.equal(actual, expected, 'The expected match for parentheses is ' + expected + ' but it was ' + actual);
+
+ });
+
+ it("should by default include an elipsis", function () {
+
+ var expected = true;
+
+ var mask = faker.Finance.mask(null, false, null);
+
+ var regexp = new RegExp(/(\.\.\.\d{4})/);
+ var actual = regexp.test(mask);
+
+ assert.equal(actual, expected, 'The expected match for parentheses is ' + expected + ' but it was ' + actual);
+
+ });
+
+ 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 mask = faker.Finance.mask(length, elipsis, parens);
+ assert.ok(mask);
+
+ });
+
+
+ });
+
+ describe('amount(min, max, dec, symbol)', 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");
+ });
+
+
+ });
+
+ 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 335c6b1a..5a5798aa 100644
--- a/test/helpers.unit.js
+++ b/test/helpers.unit.js
@@ -59,4 +59,17 @@ 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);
+ });
+ });
});