aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Cheng <[email protected]>2022-04-10 12:38:45 -0400
committerGitHub <[email protected]>2022-04-10 18:38:45 +0200
commitc25ecd08ec57fae5967148bee14fec1c4be99472 (patch)
treef417493f2c3a93c43f4ff2e8348496fdb6c2df36
parent301ad541154648bb8e72eb2e3d33ec5ac581e3ef (diff)
downloadfaker-c25ecd08ec57fae5967148bee14fec1c4be99472.tar.xz
faker-c25ecd08ec57fae5967148bee14fec1c4be99472.zip
feat: phone IMEI (#829)
-rw-r--r--src/phone.ts15
-rw-r--r--test/phone.spec.ts34
2 files changed, 47 insertions, 2 deletions
diff --git a/src/phone.ts b/src/phone.ts
index 88b2a038..c922e341 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 data.
*/
export class Phone {
constructor(private readonly faker: Faker) {
@@ -60,4 +60,17 @@ export class Phone {
this.faker.definitions.phone_number.formats
);
}
+
+ /**
+ * Generates IMEI number.
+ *
+ * @example
+ * faker.phone.imei() // '13-850175-913761-7'
+ */
+ imei(): string {
+ return this.faker.helpers.replaceCreditCardSymbols(
+ '##-######-######-L',
+ '#'
+ );
+ }
}
diff --git a/test/phone.spec.ts b/test/phone.spec.ts
index 0f80f038..162de031 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,23 @@ 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 have a length of 18', () => {
+ const imei = faker.phone.imei();
+ expect(imei).toHaveLength(18);
+ });
+
+ it('should be Luhn-valid', () => {
+ const imei = faker.phone.imei();
+ expect(imei).satisfy(luhnCheck);
+ });
+ });
}
});
});