forked from zuriby/Faker.js
-
Notifications
You must be signed in to change notification settings - Fork 0
/
internet.unit.js
143 lines (117 loc) · 4.79 KB
/
internet.unit.js
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
if (typeof module !== 'undefined') {
var assert = require('assert');
var sinon = require('sinon');
var faker = require('../index');
}
describe("internet.js", function () {
describe("email()", function () {
it("returns an email", function () {
sinon.stub(faker.internet, 'userName').returns('Aiden.Harann55');
var email = faker.internet.email("Aiden.Harann55");
var res = email.split("@");
res = res[0];
assert.equal(res, 'Aiden.Harann55');
faker.internet.userName.restore();
});
});
describe("userName()", function () {
it("occasionally returns a single firstName", function () {
sinon.stub(faker.random, 'number').returns(0);
sinon.spy(faker.name, 'firstName');
var username = faker.internet.userName();
assert.ok(username);
assert.ok(faker.name.firstName.called);
faker.random.number.restore();
faker.name.firstName.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.name, 'firstName');
sinon.spy(faker.name, 'lastName');
sinon.spy(faker.random, 'arrayElement');
var username = faker.internet.userName();
assert.ok(username);
assert.ok(faker.name.firstName.called);
assert.ok(faker.name.lastName.called);
assert.ok(faker.random.arrayElement.calledWith(['.', '_']));
faker.random.number.restore();
faker.name.firstName.restore();
faker.name.lastName.restore();
faker.random.arrayElement.restore();
});
});
describe("domainName()", function () {
it("returns a domainWord plus a random suffix", function () {
sinon.stub(faker.internet, 'domainWord').returns('bar');
sinon.stub(faker.internet, 'domainSuffix').returns('net');
var domain_name = faker.internet.domainName();
assert.equal(domain_name, 'bar.net');
faker.internet.domainWord.restore();
faker.internet.domainSuffix.restore();
});
});
describe("domainWord()", function () {
it("returns a lower-case firstName", function () {
sinon.stub(faker.name, 'firstName').returns('FOO');
var domain_word = faker.internet.domainWord();
assert.ok(domain_word);
assert.strictEqual(domain_word, 'foo');
faker.name.firstName.restore();
});
});
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();
var parts = ip.split('.');
assert.equal(parts.length, 4);
});
});
describe("userAgent()", function () {
it("returns a valid user-agent", function () {
var ua = faker.internet.userAgent();
assert.ok(ua);
});
});
describe("color()", function () {
it("returns a valid hex value (like #ffffff)", function () {
var color = faker.internet.color(100, 100, 100);
assert.ok(color.match(/^#[a-f0-9]{6}$/));
});
});
describe("mac()", function () {
it("returns a random MAC address with 6 hexadecimal digits", function () {
var mac = faker.internet.mac();
assert.ok(mac.match(/^([a-f0-9]{2}:){5}[a-f0-9]{2}$/));
});
});
});