From f2562e7869a2dc670e3976e553b49e914c837aa2 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 11 Jun 2022 14:05:38 +0200 Subject: [PATCH 1/7] refactor(internet.ip): return v4 or v6 --- src/modules/internet/index.ts | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index 2da5b59f7e1..d12f2a30435 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -290,8 +290,7 @@ export class InternetModule { * @since 2.0.1 */ ip(): string { - // TODO @Shinigami92 2022-03-21: We may want to return a IPv4 or IPv6 address here in a later major release - return this.ipv4(); + return this.faker.datatype.boolean() ? this.ipv4() : this.ipv6(); } /** From 1dee418f13cc5653b694b260269412d41bc14753 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 11 Jun 2022 14:14:38 +0200 Subject: [PATCH 2/7] docs(internet.ip): update with v6 --- src/modules/internet/index.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/src/modules/internet/index.ts b/src/modules/internet/index.ts index d12f2a30435..3c4eedee1d4 100644 --- a/src/modules/internet/index.ts +++ b/src/modules/internet/index.ts @@ -282,10 +282,11 @@ export class InternetModule { } /** - * Generates a random IPv4 address. + * Generates a random IPv4 or IPv6 address. * * @example * faker.internet.ip() // '245.108.222.0' + * faker.internet.ip() // '4e5:f9c5:4337:abfd:9caf:1135:41ad:d8d3' * * @since 2.0.1 */ From 0ce286dedb08e9cd2998262a85f997b606472f3a Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 11 Jun 2022 14:16:48 +0200 Subject: [PATCH 3/7] test(internet): add ipv4 to seeded runs --- test/__snapshots__/internet.spec.ts.snap | 6 +++--- test/internet.spec.ts | 12 +++++++++++- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/test/__snapshots__/internet.spec.ts.snap b/test/__snapshots__/internet.spec.ts.snap index 697bc6131d9..d2c4391163f 100644 --- a/test/__snapshots__/internet.spec.ts.snap +++ b/test/__snapshots__/internet.spec.ts.snap @@ -34,7 +34,7 @@ exports[`internet > 42 > httpStatusCode > noArgs 1`] = `207`; exports[`internet > 42 > httpStatusCode > with options 1`] = `410`; -exports[`internet > 42 > ip 1`] = `"95.203.243.46"`; +exports[`internet > 42 > ip 1`] = `"cf2b:c992:7210:7d59:2ba0:0fbd:f302:f294"`; exports[`internet > 42 > ipv4 1`] = `"95.203.243.46"`; @@ -94,7 +94,7 @@ exports[`internet > 1211 > httpStatusCode > noArgs 1`] = `505`; exports[`internet > 1211 > httpStatusCode > with options 1`] = `429`; -exports[`internet > 1211 > ip 1`] = `"237.117.228.199"`; +exports[`internet > 1211 > ip 1`] = `"117.228.199.57"`; exports[`internet > 1211 > ipv4 1`] = `"237.117.228.199"`; @@ -154,7 +154,7 @@ exports[`internet > 1337 > httpStatusCode > noArgs 1`] = `205`; exports[`internet > 1337 > httpStatusCode > with options 1`] = `407`; -exports[`internet > 1337 > ip 1`] = `"67.143.40.54"`; +exports[`internet > 1337 > ip 1`] = `"8234:8705:3894:5f4b:41c6:1a52:bf27:dccc"`; exports[`internet > 1337 > ipv4 1`] = `"67.143.40.54"`; diff --git a/test/internet.spec.ts b/test/internet.spec.ts index 1dbccc23c09..674104a8205 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -368,9 +368,19 @@ describe('internet', () => { }); describe('ip()', () => { - it('should return a random IPv4 address with four parts', () => { + it('should return a random IPv4 or IPv6 address with four parts', () => { const ip = faker.internet.ip(); + expect(ip).toBeTruthy(); + expect(ip).toBeTypeOf('string'); + expect(ip).toSatisfy((value: string) => validator.isIP(value)); + }); + }); + + describe('ipv4()', () => { + it('should return a random IPv4 with four parts', () => { + const ip = faker.internet.ipv4(); + expect(ip).toBeTruthy(); expect(ip).toBeTypeOf('string'); expect(ip).toSatisfy((value: string) => validator.isIP(value, 4)); From ab2972f45d4cd4b8d9608d84fdf372232d2a2823 Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 11 Jun 2022 14:17:51 +0200 Subject: [PATCH 4/7] test(internet): fix object is possibly 'undefined' warnings --- test/internet.spec.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/internet.spec.ts b/test/internet.spec.ts index 674104a8205..03b244af7df 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -87,7 +87,7 @@ describe('internet', () => { expect(email).toSatisfy(validator.isEmail); const [, suffix] = email.split('@'); - expect(faker.definitions.internet.free_email).toContain(suffix); + expect(faker.definitions.internet?.free_email).toContain(suffix); }); it('should return an email with given firstName', () => { @@ -132,7 +132,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(prefix).toMatch(/^思源_唐3/); - expect(faker.definitions.internet.free_email).toContain(suffix); + expect(faker.definitions.internet?.free_email).toContain(suffix); }); it('should return an email with special characters', () => { @@ -164,7 +164,7 @@ describe('internet', () => { const suffix = email.split('@')[1]; expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet.example_email).toContain(suffix); + expect(faker.definitions.internet?.example_email).toContain(suffix); }); it('should return an email with the example suffix and given firstName', () => { @@ -177,7 +177,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet.example_email).toContain(suffix); + expect(faker.definitions.internet?.example_email).toContain(suffix); expect(prefix).toMatch(/^Aiden.Harann55/); }); @@ -191,7 +191,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet.example_email).toContain(suffix); + expect(faker.definitions.internet?.example_email).toContain(suffix); expect(prefix).toMatch(/^Aiden([._]Harann)?\d*/); }); @@ -205,7 +205,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet.example_email).toContain(suffix); + expect(faker.definitions.internet?.example_email).toContain(suffix); expect(prefix).toMatch(/^思源_唐3/); }); @@ -221,7 +221,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet.example_email).toContain(suffix); + expect(faker.definitions.internet?.example_email).toContain(suffix); expect(prefix).toMatch(/^Mike([.!#$%&'*+-/=?^_`{|}~]Smith)?\d*/); }); }); @@ -338,7 +338,7 @@ describe('internet', () => { const [prefix, suffix] = domainName.split('.'); expect(prefix).toSatisfy(validator.isSlug); - expect(faker.definitions.internet.domain_suffix).toContain(suffix); + expect(faker.definitions.internet?.domain_suffix).toContain(suffix); }); }); @@ -348,7 +348,7 @@ describe('internet', () => { expect(domainSuffix).toBeTruthy(); expect(domainSuffix).toBeTypeOf('string'); - expect(faker.definitions.internet.domain_suffix).toContain( + expect(faker.definitions.internet?.domain_suffix).toContain( domainSuffix ); }); From f2160364d8d5a5b1ee8273af735a763f38a5fcaa Mon Sep 17 00:00:00 2001 From: xDivisionByZerox Date: Sat, 11 Jun 2022 14:36:17 +0200 Subject: [PATCH 5/7] test(internet): add ip() test --- test/internet.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/internet.spec.ts b/test/internet.spec.ts index 03b244af7df..52c6376e5bb 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -368,7 +368,7 @@ describe('internet', () => { }); describe('ip()', () => { - it('should return a random IPv4 or IPv6 address with four parts', () => { + it('should return a random IPv4 or IPv6 address', () => { const ip = faker.internet.ip(); expect(ip).toBeTruthy(); From 6d2067e73cabcf9edfed4a30c4475e9f0ee64c88 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sat, 11 Jun 2022 16:35:48 +0200 Subject: [PATCH 6/7] revert: test(internet): fix object is possibly 'undefined' warnings This reverts commit a3439a265962192f3c14e2c638cf9a1a73998bab. --- test/internet.spec.ts | 18 +++++++++--------- 1 file changed, 9 insertions(+), 9 deletions(-) diff --git a/test/internet.spec.ts b/test/internet.spec.ts index 52c6376e5bb..e80985cdc20 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -87,7 +87,7 @@ describe('internet', () => { expect(email).toSatisfy(validator.isEmail); const [, suffix] = email.split('@'); - expect(faker.definitions.internet?.free_email).toContain(suffix); + expect(faker.definitions.internet.free_email).toContain(suffix); }); it('should return an email with given firstName', () => { @@ -132,7 +132,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(prefix).toMatch(/^思源_唐3/); - expect(faker.definitions.internet?.free_email).toContain(suffix); + expect(faker.definitions.internet.free_email).toContain(suffix); }); it('should return an email with special characters', () => { @@ -164,7 +164,7 @@ describe('internet', () => { const suffix = email.split('@')[1]; expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet?.example_email).toContain(suffix); + expect(faker.definitions.internet.example_email).toContain(suffix); }); it('should return an email with the example suffix and given firstName', () => { @@ -177,7 +177,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet?.example_email).toContain(suffix); + expect(faker.definitions.internet.example_email).toContain(suffix); expect(prefix).toMatch(/^Aiden.Harann55/); }); @@ -191,7 +191,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet?.example_email).toContain(suffix); + expect(faker.definitions.internet.example_email).toContain(suffix); expect(prefix).toMatch(/^Aiden([._]Harann)?\d*/); }); @@ -205,7 +205,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet?.example_email).toContain(suffix); + expect(faker.definitions.internet.example_email).toContain(suffix); expect(prefix).toMatch(/^思源_唐3/); }); @@ -221,7 +221,7 @@ describe('internet', () => { const [prefix, suffix] = email.split('@'); expect(suffix).toMatch(/^example\.(com|net|org)$/); - expect(faker.definitions.internet?.example_email).toContain(suffix); + expect(faker.definitions.internet.example_email).toContain(suffix); expect(prefix).toMatch(/^Mike([.!#$%&'*+-/=?^_`{|}~]Smith)?\d*/); }); }); @@ -338,7 +338,7 @@ describe('internet', () => { const [prefix, suffix] = domainName.split('.'); expect(prefix).toSatisfy(validator.isSlug); - expect(faker.definitions.internet?.domain_suffix).toContain(suffix); + expect(faker.definitions.internet.domain_suffix).toContain(suffix); }); }); @@ -348,7 +348,7 @@ describe('internet', () => { expect(domainSuffix).toBeTruthy(); expect(domainSuffix).toBeTypeOf('string'); - expect(faker.definitions.internet?.domain_suffix).toContain( + expect(faker.definitions.internet.domain_suffix).toContain( domainSuffix ); }); From 5d515a9dfabbf8edd4f53ac35e27e3abe73c2a5b Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Leyla=20J=C3=A4hnig?= Date: Sun, 3 Jul 2022 18:34:34 +0200 Subject: [PATCH 7/7] test(internet.ip): shorten expectation expression Co-authored-by: ST-DDT --- test/internet.spec.ts | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/test/internet.spec.ts b/test/internet.spec.ts index e80985cdc20..cbbf2745ddd 100644 --- a/test/internet.spec.ts +++ b/test/internet.spec.ts @@ -373,7 +373,7 @@ describe('internet', () => { expect(ip).toBeTruthy(); expect(ip).toBeTypeOf('string'); - expect(ip).toSatisfy((value: string) => validator.isIP(value)); + expect(ip).toSatisfy(validator.isIP); }); });