aboutsummaryrefslogtreecommitdiff
path: root/test/helpers.unit.js
diff options
context:
space:
mode:
authorMarak <[email protected]>2017-09-08 12:52:43 -0400
committerMarak <[email protected]>2017-09-08 12:52:43 -0400
commitb652617fa5f78279cae3a5f64e7930a19369dd38 (patch)
treeb029cbd80f86be3db39c3b72e7f7514a6624b179 /test/helpers.unit.js
parentf4236a85b904394c729c3efb383c09fa5d137c54 (diff)
parent52d8cc1471080fe67c8abd8115240b6aa933f85f (diff)
downloadfaker-b652617fa5f78279cae3a5f64e7930a19369dd38.tar.xz
faker-b652617fa5f78279cae3a5f64e7930a19369dd38.zip
Merge branch 'creditCard' of https://github.com/zpiman/faker.js
Diffstat (limited to 'test/helpers.unit.js')
-rw-r--r--test/helpers.unit.js51
1 files changed, 51 insertions, 0 deletions
diff --git a/test/helpers.unit.js b/test/helpers.unit.js
index 707575ff..b440f33e 100644
--- a/test/helpers.unit.js
+++ b/test/helpers.unit.js
@@ -67,6 +67,57 @@ describe("helpers.js", function () {
});
});
+ describe("replaceCreditCardSymbols()", function () {
+ var luhnCheck = require("./support/luhnCheck.js");
+ it("returns a credit card number given a schema", function () {
+ var number = faker.helpers.replaceCreditCardSymbols("6453-####-####-####-###L");
+ assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ });
+ it("supports different symbols", function () {
+ var number = faker.helpers.replaceCreditCardSymbols("6453-****-****-****-***L","*");
+ assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ });
+ it("handles regexp style input", function () {
+ var number = faker.helpers.replaceCreditCardSymbols("6453-*{4}-*{4}-*{4}-*{3}L","*");
+ assert.ok(number.match(/^6453\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ number = faker.helpers.replaceCreditCardSymbols("645[5-9]-#{4,6}-#{1,2}-#{4,6}-#{3}L");
+ assert.ok(number.match(/^645[5-9]\-([0-9]){4,6}\-([0-9]){1,2}\-([0-9]){4,6}\-([0-9]){4}$/));
+ assert.ok(luhnCheck(number));
+ });
+ });
+
+ describe("regexpStyleStringParse()", function () {
+ it("returns an empty string when called without param", function () {
+ assert.ok(faker.helpers.regexpStyleStringParse() === "");
+ });
+ it("deals with range repeat", function () {
+ var string = faker.helpers.regexpStyleStringParse("#{5,10}");
+ assert.ok(string.length <= 10 && string.length >= 5);
+ assert.ok(string.match(/^\#{5,10}$/));
+ });
+ it("flips the range when min > max", function () {
+ var string = faker.helpers.regexpStyleStringParse("#{10,5}");
+ assert.ok(string.length <= 10 && string.length >= 5);
+ assert.ok(string.match(/^\#{5,10}$/));
+ });
+ it("repeats string {n} number of times", function () {
+ assert.ok(faker.helpers.regexpStyleStringParse("%{10}") === faker.helpers.repeatString("%",10));
+ assert.ok(faker.helpers.regexpStyleStringParse("%{30}") === faker.helpers.repeatString("%",30));
+ assert.ok(faker.helpers.regexpStyleStringParse("%{5}") === faker.helpers.repeatString("%",5));
+ });
+ it("creates a numerical range", function () {
+ var string = faker.helpers.regexpStyleStringParse("Hello[0-9]");
+ assert.ok(string.match(/^Hello[0-9]$/));
+ });
+ it("deals with multiple tokens in one string", function () {
+ var string = faker.helpers.regexpStyleStringParse("Test#{5}%{2,5}Testing**[1-5]**{10}END");
+ assert.ok(string.match(/^Test\#{5}%{2,5}Testing\*\*[1-5]\*\*{10}END$/));
+ });
+ });
+
describe("createTransaction()", function() {
it("should create a random transaction", function() {
var transaction = faker.helpers.createTransaction();