forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
d3299b4
commit 0c84125
Showing
7 changed files
with
161 additions
and
43 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,36 +1,39 @@ | ||
var Helpers = require('./helpers'); | ||
var definitions = require('./definitions'); | ||
var Faker = require('../index'); | ||
|
||
exports.email = function () { | ||
return this.userName() + "@" + this.domainName(); | ||
}; | ||
var internet = { | ||
email: function () { | ||
return this.userName() + "@" + this.domainName(); | ||
}, | ||
|
||
exports.userName = function () { | ||
switch (Helpers.randomNumber(2)) { | ||
case 0: | ||
return Helpers.randomize(definitions.first_name()); | ||
case 1: | ||
return Helpers.randomize(definitions.first_name()) + Helpers.randomize([".", "_"]) + Helpers.randomize(definitions.last_name()); | ||
} | ||
}; | ||
userName: function () { | ||
switch (Faker.random.number(2)) { | ||
case 0: | ||
return Faker.random.first_name(); | ||
case 1: | ||
return Faker.random.first_name() + Faker.random.array_rand([".", "_"]) + Faker.random.last_name(); | ||
} | ||
}, | ||
|
||
exports.domainName = function () { | ||
return this.domainWord() + "." + Helpers.randomize(definitions.domain_suffix()); | ||
}; | ||
domainName: function () { | ||
return this.domainWord() + "." + Faker.random.domain_suffix(); | ||
}, | ||
|
||
exports.domainWord = function () { | ||
return Helpers.randomize(definitions.first_name()).toLowerCase(); | ||
}; | ||
domainWord: function () { | ||
return Faker.random.first_name().toLowerCase(); | ||
}, | ||
|
||
exports.ip = function () { | ||
var randNum = function () { | ||
return (Math.random() * 254 + 1).toFixed(0); | ||
}; | ||
ip: function () { | ||
var randNum = function () { | ||
return (Math.random() * 254 + 1).toFixed(0); | ||
}; | ||
|
||
var result = []; | ||
for (var i = 0; i < 4; i++) { | ||
result[i] = randNum(); | ||
} | ||
var result = []; | ||
for (var i = 0; i < 4; i++) { | ||
result[i] = randNum(); | ||
} | ||
|
||
return result.join("."); | ||
return result.join("."); | ||
} | ||
}; | ||
|
||
module.exports = internet; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,35 @@ | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var Faker = require('../index'); | ||
|
||
describe("helpers.js", function() { | ||
describe("replaceSymbolWithNumber()", function() { | ||
context("when no symbol passed in", function() { | ||
it("uses '#' by default", function() { | ||
var num = Faker.Helpers.replaceSymbolWithNumber('#AB'); | ||
assert.ok(num.match(/\dAB/)); | ||
}); | ||
}); | ||
|
||
context("when symbol passed in", function() { | ||
it("replaces that symbol with integers", function() { | ||
var num = Faker.Helpers.replaceSymbolWithNumber('#AB', 'A'); | ||
assert.ok(num.match(/#\dB/)); | ||
}); | ||
}); | ||
}); | ||
|
||
describe("createCard()", function() { | ||
it("returns an object", function() { | ||
var card = Faker.Helpers.createCard(); | ||
assert.ok(typeof card === 'object'); | ||
}); | ||
}); | ||
|
||
describe("userCard()", function() { | ||
it("returns an object", function() { | ||
var card = Faker.Helpers.userCard(); | ||
assert.ok(typeof card === 'object'); | ||
}); | ||
}); | ||
}); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,83 @@ | ||
var assert = require('assert'); | ||
var sinon = require('sinon'); | ||
var Faker = require('../index'); | ||
|
||
describe("internet.js", function () { | ||
describe("email()", function () { | ||
it("returns a userName@domainName", function () { | ||
sinon.stub(Faker.Internet, 'userName').returns('foo'); | ||
sinon.stub(Faker.Internet, 'domainName').returns('bar.com'); | ||
var email = Faker.Internet.email(); | ||
|
||
assert.equal(email, '[email protected]'); | ||
|
||
Faker.Internet.userName.restore(); | ||
Faker.Internet.domainName.restore(); | ||
}); | ||
}); | ||
|
||
describe("userName()", function () { | ||
it("occasionally returns a single firstName", function () { | ||
sinon.stub(Faker.random, 'number').returns(0); | ||
sinon.spy(Faker.random, 'first_name'); | ||
var username = Faker.Internet.userName(); | ||
|
||
assert.ok(username); | ||
assert.ok(Faker.random.first_name.called); | ||
|
||
Faker.random.number.restore(); | ||
Faker.random.first_name.restore(); | ||
}); | ||
|
||
it("occasionally returns a firstName with a period or hyphen and a lastName", function () { | ||
sinon.stub(Faker.random, 'number').returns(1); | ||
sinon.spy(Faker.random, 'first_name'); | ||
sinon.spy(Faker.random, 'last_name'); | ||
sinon.spy(Faker.random, 'array_rand'); | ||
var username = Faker.Internet.userName(); | ||
|
||
assert.ok(username); | ||
assert.ok(Faker.random.first_name.called); | ||
assert.ok(Faker.random.last_name.called); | ||
assert.ok(Faker.random.array_rand.calledWith(['.', '_'])); | ||
|
||
Faker.random.number.restore(); | ||
Faker.random.first_name.restore(); | ||
Faker.random.last_name.restore(); | ||
}); | ||
}); | ||
|
||
describe("domainName()", function() { | ||
it("returns a domainWord plus a random suffix", function() { | ||
sinon.stub(Faker.Internet, 'domainWord').returns('bar'); | ||
sinon.stub(Faker.random, 'domain_suffix').returns('net'); | ||
|
||
var domain_name = Faker.Internet.domainName(); | ||
|
||
assert.equal(domain_name, 'bar.net'); | ||
|
||
Faker.Internet.domainWord.restore(); | ||
Faker.random.domain_suffix.restore(); | ||
}); | ||
}); | ||
|
||
describe("domainWord()", function() { | ||
it("returns a lower-case firstName", function() { | ||
sinon.stub(Faker.random, 'first_name').returns('FOO'); | ||
var domain_word = Faker.Internet.domainWord(); | ||
|
||
assert.ok(domain_word); | ||
assert.strictEqual(domain_word, 'foo'); | ||
|
||
Faker.random.first_name.restore(); | ||
}); | ||
}); | ||
|
||
describe("ip()", function() { | ||
it("returns a random IP address with four parts", function() { | ||
var ip = Faker.Internet.ip(); | ||
var parts = ip.split('.'); | ||
assert.equal(parts.length, 4); | ||
}); | ||
}); | ||
}); |