From 291464fdd87593246b51979a1ba41a03a3592683 Mon Sep 17 00:00:00 2001 From: Daniel Mills Date: Sun, 25 Jan 2015 15:35:36 -0500 Subject: added protocol() and url() --- lib/internet.js | 9 +++++++++ test/internet.unit.js | 38 ++++++++++++++++++++++++++++++++++++++ 2 files changed, 47 insertions(+) diff --git a/lib/internet.js b/lib/internet.js index c0d92ec5..a15b0dd5 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(); -- cgit v1.2.3