aboutsummaryrefslogtreecommitdiff
path: root/test
diff options
context:
space:
mode:
authoralexpts <[email protected]>2017-02-11 09:28:15 +0300
committeralexpts <[email protected]>2017-02-11 09:28:15 +0300
commit53520a79ba4623199b2e059708806aae01f482db (patch)
tree8bed503bdee9f201a0f083d3adf63e064a60e50a /test
parent434b3174b1cd3cf568c06aefbc2e8d000b397adf (diff)
parentfe2c0fd5cbdb49ec97b51b040a357ec4d6318571 (diff)
downloadfaker-53520a79ba4623199b2e059708806aae01f482db.tar.xz
faker-53520a79ba4623199b2e059708806aae01f482db.zip
Merge branch 'master' into patch-1
# Conflicts: # lib/finance.js
Diffstat (limited to 'test')
-rw-r--r--test/all.functional.js4
-rw-r--r--test/browser.unit.html1
-rw-r--r--test/database.unit.js47
-rw-r--r--test/finance.unit.js30
-rw-r--r--test/lorem.unit.js30
-rw-r--r--test/system.unit.js27
6 files changed, 133 insertions, 6 deletions
diff --git a/test/all.functional.js b/test/all.functional.js
index 605aad2a..4ea196b6 100644
--- a/test/all.functional.js
+++ b/test/all.functional.js
@@ -14,9 +14,11 @@ var modules = {
company: ['companyName', 'companySuffix', 'catchPhrase', 'bs'],
+ database: ['column', 'collation', 'engine', 'type'],
+
internet: ['email', 'userName', 'domainName', 'domainWord', 'ip'],
- lorem: ['words', 'sentence', 'sentences', 'paragraph', 'paragraphs'],
+ lorem: ['words', 'sentence', 'slug', 'sentences', 'paragraph', 'paragraphs'],
name: ['firstName', 'lastName', 'findName', 'jobTitle'],
diff --git a/test/browser.unit.html b/test/browser.unit.html
index 7812cf70..467f35ce 100644
--- a/test/browser.unit.html
+++ b/test/browser.unit.html
@@ -17,6 +17,7 @@
<script src="company.unit.js"></script>
<script src="helpers.unit.js"></script>
<script src="internet.unit.js"></script>
+ <script src="database.unit.js"></script>
<script src="lorem.unit.js"></script>
<script src="name.unit.js"></script>
<script src="phone_number.unit.js"></script>
diff --git a/test/database.unit.js b/test/database.unit.js
new file mode 100644
index 00000000..bb0cd2a5
--- /dev/null
+++ b/test/database.unit.js
@@ -0,0 +1,47 @@
+if (typeof module !== 'undefined') {
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
+}
+
+describe("database.js", function () {
+ describe("column()", function () {
+ it("returns a column name", function () {
+ sinon.stub(faker.database, 'column').returns('title');
+ var column = faker.database.column();
+
+ assert.equal(column, 'title');
+ faker.database.column.restore();
+ });
+ });
+
+ describe("collation()", function () {
+ it("returns a collation", function () {
+ sinon.stub(faker.database, 'collation').returns('utf8_bin');
+ var collation = faker.database.collation();
+
+ assert.equal(collation, 'utf8_bin');
+ faker.database.collation.restore();
+ });
+ });
+
+ describe("engine()", function () {
+ it("returns an engine", function () {
+ sinon.stub(faker.database, 'engine').returns('InnoDB');
+ var engine = faker.database.engine();
+
+ assert.equal(engine, 'InnoDB');
+ faker.database.engine.restore();
+ });
+ });
+
+ describe("type()", function () {
+ it("returns a column type", function () {
+ sinon.stub(faker.database, 'type').returns('int');
+ var type = faker.database.type();
+
+ assert.equal(type, 'int');
+ faker.database.type.restore();
+ });
+ });
+});
diff --git a/test/finance.unit.js b/test/finance.unit.js
index 22461f22..3593ce72 100644
--- a/test/finance.unit.js
+++ b/test/finance.unit.js
@@ -58,7 +58,7 @@ describe('finance.js', function () {
});
- describe('mask( length, parens, elipsis )', function () {
+ describe('mask( length, parens, ellipsis )', function () {
it("should set a default length", function () {
var expected = 4; //default account mask length
@@ -111,7 +111,7 @@ describe('finance.js', function () {
});
- it("should by default include an elipsis", function () {
+ it("should by default include an ellipsis", function () {
var expected = true;
@@ -127,10 +127,10 @@ 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 ellipsis = (length % 2 === 0) ? true : false;
+ var parens = !ellipsis;
- var mask = faker.finance.mask(length, elipsis, parens);
+ var mask = faker.finance.mask(length, ellipsis, parens);
assert.ok(mask);
});
@@ -226,4 +226,24 @@ describe('finance.js', function () {
assert.ok(bitcoinAddress.match(/^[A-Z0-9.]{27,34}$/));
});
});
+
+ describe("iban()", function () {
+ var ibanLib = require('../lib/iban');
+ it("returns a random yet formally correct IBAN number", function () {
+ var iban = faker.finance.iban();
+ var bban = iban.substring(4) + iban.substring(0, 4);
+
+ assert.equal(ibanLib.mod97(ibanLib.toDigitString(bban)), 1, "the result should be equal to 1");
+ });
+ });
+
+ describe("bic()", function () {
+ var ibanLib = require('../lib/iban');
+ it("returns a random yet formally correct BIC number", function () {
+ var bic = faker.finance.bic();
+ var expr = new RegExp("^[A-Z]{4}(" + ibanLib.iso3166.join("|") + ")[A-Z2-9][A-NP-Z0-9]([A-Z0-9]{3})?$", "i");
+
+ assert.ok(bic.match(expr));
+ });
+ });
}); \ No newline at end of file
diff --git a/test/lorem.unit.js b/test/lorem.unit.js
index fbf09497..300786b8 100644
--- a/test/lorem.unit.js
+++ b/test/lorem.unit.js
@@ -34,6 +34,36 @@ describe("lorem.js", function () {
});
});
+ describe("slug()", function () {
+ beforeEach(function () {
+ sinon.spy(faker.helpers, 'shuffle');
+ });
+
+ afterEach(function () {
+ faker.helpers.shuffle.restore();
+ });
+
+ var validateSlug = function (wordCount, str) {
+ assert.equal(1, str.match(/^[a-z][a-z-]*[a-z]$/).length);
+ assert.equal(wordCount - 1, str.match(/-/g).length);
+ };
+
+ context("when no 'wordCount' param passed in", function () {
+ it("returns a slug with three words", function () {
+ var str = faker.lorem.slug();
+ validateSlug(3, str);
+ });
+ });
+
+ context("when 'wordCount' param passed in", function () {
+ it("returns a slug with requested number of words", function () {
+ var str = faker.lorem.slug(7);
+ validateSlug(7, str);
+ });
+ });
+
+ });
+
/*
describe("sentence()", function () {
context("when no 'wordCount' or 'range' param passed in", function () {
diff --git a/test/system.unit.js b/test/system.unit.js
new file mode 100644
index 00000000..1edcb8be
--- /dev/null
+++ b/test/system.unit.js
@@ -0,0 +1,27 @@
+if (typeof module !== 'undefined') {
+ var assert = require('assert');
+ var sinon = require('sinon');
+ var faker = require('../index');
+}
+
+describe("system.js", function () {
+ describe("fileName()", function () {
+ it("returns filenames without system path seperators", function () {
+ sinon.stub(faker.random, 'words').returns('24/7');
+ var fileName = faker.system.fileName();
+ assert.equal(fileName.indexOf('/'), -1, 'generated fileNames should not have path seperators');
+
+ faker.random.words.restore();
+ });
+ });
+
+ describe("commonFileName()", function () {
+ it("returns filenames without system path seperators", function () {
+ sinon.stub(faker.random, 'words').returns('24/7');
+ var fileName = faker.system.commonFileName();
+ assert.equal(fileName.indexOf('/'), -1, 'generated commonFileNames should not have path seperators');
+
+ faker.random.words.restore();
+ });
+ });
+});