aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMarak <[email protected]>2021-03-01 22:33:56 -0500
committerGitHub <[email protected]>2021-03-01 22:33:56 -0500
commit6f5d84b299876fb81bd1a87c5039ba34c05331af (patch)
tree1776cc36a51a1dd1973596018e55a11d8be3b1e5
parentf5f186c70d6c57d41aa34ab82aae554d70ef7c7f (diff)
parent81c67e0dded7177c80e208050091d8345be1ff90 (diff)
downloadfaker-6f5d84b299876fb81bd1a87c5039ba34c05331af.tar.xz
faker-6f5d84b299876fb81bd1a87c5039ba34c05331af.zip
Merge pull request #1121 from ognjenjevremovic/perf/finance-transaction-description
[Improvement] Call `createTransaction` method once from within `finance.transactionDescription`
-rw-r--r--lib/finance.js11
-rw-r--r--test/finance.unit.js21
2 files changed, 21 insertions, 11 deletions
diff --git a/lib/finance.js b/lib/finance.js
index bbe2b17f..43fe6710 100644
--- a/lib/finance.js
+++ b/lib/finance.js
@@ -338,14 +338,15 @@ self.litecoinAddress = function () {
* @method faker.finance.transactionDescription
*/
self.transactionDescription = function() {
- var account = Helpers.createTransaction().account
+ var transaction = Helpers.createTransaction();
+ var account = transaction.account;
+ var amount = transaction.amount;
+ var transactionType = transaction.type;
+ var company = transaction.business;
var card = faker.finance.mask();
var currency = faker.finance.currencyCode();
- var amount = Helpers.createTransaction().amount
- var transactionType = Helpers.createTransaction().type
- var company = Helpers.createTransaction().business
return transactionType + " transaction at " + company + " using card ending with ***" + card + " for " + currency + " " + amount + " in account ***" + account
- }
+ };
};
diff --git a/test/finance.unit.js b/test/finance.unit.js
index ea474f59..47c457c9 100644
--- a/test/finance.unit.js
+++ b/test/finance.unit.js
@@ -172,7 +172,7 @@ describe('finance.js', function () {
assert.ok(amount);
assert.strictEqual(amount , '100.0', "the amount should be equal 100.0");
});
-
+
//TODO: add support for more currency and decimal options
it("should not include a currency symbol by default", function () {
@@ -395,10 +395,19 @@ describe('finance.js', function () {
});
describe("transactionDescription()", function() {
- it("returns a random transaction description", function() {
- var transactionDescription = faker.finance.transactionDescription();
+ beforeEach(function () {
+ sinon.spy(faker.helpers, 'createTransaction');
+ });
+
+ afterEach(function () {
+ faker.helpers.createTransaction.restore();
+ });
- assert.ok(transactionDescription);
- })
- })
+ it("returns a random transaction description", function() {
+ var transactionDescription = faker.finance.transactionDescription();
+
+ assert.ok(transactionDescription);
+ assert.ok(faker.helpers.createTransaction.calledOnce);
+ });
+ });
});