forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
finance.unit.js
205 lines (116 loc) · 5.98 KB
/
finance.unit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
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);
});
});
describe("currencyCode()", function () {
it("returns a random currency code with a format", function () {
var currencyCode = faker.finance.currencyCode();
assert.ok(currencyCode.match(/[A-Z]{3}/));
});
})
});