diff options
| author | Marak <[email protected]> | 2015-06-11 14:38:07 +0200 |
|---|---|---|
| committer | Marak <[email protected]> | 2015-06-11 14:38:07 +0200 |
| commit | caa9083b1ddb8bafaa07bf0064f39bf1626c061f (patch) | |
| tree | 1e2c3993b180cb5262870faa06a62eca7dbbd88a | |
| parent | 685b641fd5b4370c4fbae06cfb0fb0987bbb5343 (diff) | |
| parent | 291464fdd87593246b51979a1ba41a03a3592683 (diff) | |
| download | faker-caa9083b1ddb8bafaa07bf0064f39bf1626c061f.tar.xz faker-caa9083b1ddb8bafaa07bf0064f39bf1626c061f.zip | |
Merge pull request #164 from dmamills/master
[api] Add internet.url()
| -rw-r--r-- | lib/internet.js | 9 | ||||
| -rw-r--r-- | test/internet.unit.js | 38 |
2 files changed, 47 insertions, 0 deletions
diff --git a/lib/internet.js b/lib/internet.js index 14d92846..16434ebb 100644 --- a/lib/internet.js +++ b/lib/internet.js @@ -33,6 +33,15 @@ var internet = { return result; }, + protocol: function () { + var protocols = ['http','https']; + return faker.random.array_element(protocols); + }, + + url: function () { + return faker.internet.protocol() + '://' + faker.internet.domainName(); + }, + domainName: function () { return faker.internet.domainWord() + "." + faker.internet.domainSuffix(); }, diff --git a/test/internet.unit.js b/test/internet.unit.js index 2fc0db10..1f8893a3 100644 --- a/test/internet.unit.js +++ b/test/internet.unit.js @@ -73,6 +73,44 @@ describe("internet.js", function () { }); }); + describe('protocol()', function () { + it('returns a valid protocol', function () { + var protocol = faker.internet.protocol(); + assert.ok(protocol); + }); + + it('should occasionally return http', function () { + sinon.stub(faker.random, 'number').returns(0); + var protocol = faker.internet.protocol(); + assert.ok(protocol); + assert.strictEqual(protocol, 'http'); + + faker.random.number.restore(); + }); + + it('should occasionally return https', function () { + sinon.stub(faker.random, 'number').returns(1); + var protocol = faker.internet.protocol(); + assert.ok(protocol); + assert.strictEqual(protocol, 'https'); + + faker.random.number.restore(); + }); + }); + + describe('url()', function () { + it('returns a valid url', function () { + sinon.stub(faker.internet,'protocol').returns('http'); + sinon.stub(faker.internet, 'domainWord').returns('bar'); + sinon.stub(faker.internet, 'domainSuffix').returns('net'); + + var url = faker.internet.url(); + + assert.ok(url); + assert.strictEqual(url,'http://bar.net'); + }); + }); + describe("ip()", function () { it("returns a random IP address with four parts", function () { var ip = faker.internet.ip(); |
