From 0f594594a2eae513abe632a9bdbd1913bf8be94d Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 10 Apr 2022 11:01:11 -0400 Subject: [PATCH 1/6] feat: random imei number --- src/phone.ts | 15 ++++++++++++++- 1 file changed, 14 insertions(+), 1 deletion(-) diff --git a/src/phone.ts b/src/phone.ts index 88b2a038ad0..d1b289151dc 100644 --- a/src/phone.ts +++ b/src/phone.ts @@ -1,7 +1,7 @@ import type { Faker } from '.'; /** - * Module to generate phone numbers. + * Module to generate phone-related numbers. */ export class Phone { constructor(private readonly faker: Faker) { @@ -60,4 +60,17 @@ export class Phone { this.faker.definitions.phone_number.formats ); } + + /** + * Returns a random IMEI number. + * + * @example + * faker.phone.imei() // '13-850175-913761-7' + */ + imei(): string { + return this.faker.helpers.replaceCreditCardSymbols( + '##-######-######-L', + '#' + ); + } } From c83f7edd67337ce8244f0bc4f79be14aabc7d9e7 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 10 Apr 2022 11:02:49 -0400 Subject: [PATCH 2/6] test: for imei() --- test/phone.spec.ts | 27 ++++++++++++++++++++++++++- 1 file changed, 26 insertions(+), 1 deletion(-) diff --git a/test/phone.spec.ts b/test/phone.spec.ts index 0f80f038dfa..092ff6aa574 100644 --- a/test/phone.spec.ts +++ b/test/phone.spec.ts @@ -1,5 +1,6 @@ import { beforeEach, describe, expect, it } from 'vitest'; import { faker } from '../src'; +import { luhnCheck } from './support/luhnCheck'; const seededRuns = [ { @@ -15,6 +16,9 @@ const seededRuns = [ phoneFormats: { noArgs: '!##.!##.####', }, + imei: { + noArgs: '37-917755-141004-5', + }, }, }, { @@ -30,6 +34,9 @@ const seededRuns = [ phoneFormats: { noArgs: '(!##) !##-####', }, + imei: { + noArgs: '25-122540-325523-6', + }, }, }, { @@ -45,11 +52,19 @@ const seededRuns = [ phoneFormats: { noArgs: '1-!##-!##-#### x#####', }, + imei: { + noArgs: '94-872190-616274-6', + }, }, }, ]; -const functionNames = ['phoneNumber', 'phoneNumberFormat', 'phoneFormats']; +const functionNames = [ + 'phoneNumber', + 'phoneNumberFormat', + 'phoneFormats', + 'imei', +]; const NON_SEEDED_BASED_RUN = 25; @@ -125,6 +140,16 @@ describe('phone', () => { expect(faker.definitions.phone_number.formats).contain(phoneFormat); }); }); + + describe('imei()', () => { + it('should return a string', () => { + const imei = faker.phone.imei(); + expect(imei).toBeTypeOf('string'); + }); + it('should be Luhn-valid', () => { + expect(luhnCheck(faker.phone.imei())).toBeTruthy(); + }); + }); } }); }); From 42126df3d35000d7e65916d514d1b844c5bf8d8c Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 10 Apr 2022 11:18:56 -0400 Subject: [PATCH 3/6] Apply suggestions from @pkuczynski's review Co-authored-by: Piotr Kuczynski --- src/phone.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/phone.ts b/src/phone.ts index d1b289151dc..c922e341e14 100644 --- a/src/phone.ts +++ b/src/phone.ts @@ -1,7 +1,7 @@ import type { Faker } from '.'; /** - * Module to generate phone-related numbers. + * Module to generate phone-related data. */ export class Phone { constructor(private readonly faker: Faker) { @@ -62,7 +62,7 @@ export class Phone { } /** - * Returns a random IMEI number. + * Generates IMEI number. * * @example * faker.phone.imei() // '13-850175-913761-7' From 7070dccec8a8d3d04ebf5c847e263c30586acdc6 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 10 Apr 2022 11:20:27 -0400 Subject: [PATCH 4/6] Apply suggestion from @Shinigami92's review Co-authored-by: Shinigami --- test/phone.spec.ts | 1 + 1 file changed, 1 insertion(+) diff --git a/test/phone.spec.ts b/test/phone.spec.ts index 092ff6aa574..62936267335 100644 --- a/test/phone.spec.ts +++ b/test/phone.spec.ts @@ -146,6 +146,7 @@ describe('phone', () => { const imei = faker.phone.imei(); expect(imei).toBeTypeOf('string'); }); + it('should be Luhn-valid', () => { expect(luhnCheck(faker.phone.imei())).toBeTruthy(); }); From 5f052ca37a2d8615de3c431caa0189b3d966a9c0 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 10 Apr 2022 11:34:17 -0400 Subject: [PATCH 5/6] fix: apply @ST-DDT's length test suggestion --- test/phone.spec.ts | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/test/phone.spec.ts b/test/phone.spec.ts index 62936267335..62481dd1f63 100644 --- a/test/phone.spec.ts +++ b/test/phone.spec.ts @@ -147,6 +147,11 @@ describe('phone', () => { expect(imei).toBeTypeOf('string'); }); + it('should have a length of 18', () => { + const imei = faker.phone.imei(); + expect(imei).toHaveLength(18); + }); + it('should be Luhn-valid', () => { expect(luhnCheck(faker.phone.imei())).toBeTruthy(); }); From 9e67bfb418939d7ac57fcc9d0095e3fae862bf51 Mon Sep 17 00:00:00 2001 From: Eric Cheng Date: Sun, 10 Apr 2022 11:48:13 -0400 Subject: [PATCH 6/6] refactor: apply @ST-DDT and @Shinigami92's suggestion from review --- test/phone.spec.ts | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/test/phone.spec.ts b/test/phone.spec.ts index 62481dd1f63..162de0311c6 100644 --- a/test/phone.spec.ts +++ b/test/phone.spec.ts @@ -153,7 +153,8 @@ describe('phone', () => { }); it('should be Luhn-valid', () => { - expect(luhnCheck(faker.phone.imei())).toBeTruthy(); + const imei = faker.phone.imei(); + expect(imei).satisfy(luhnCheck); }); }); }