Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: phone IMEI #829

Merged
merged 7 commits into from
Apr 10, 2022
Merged
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion src/phone.ts
Original file line number Diff line number Diff line change
@@ -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) {
Expand Down Expand Up @@ -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',
'#'
);
}
}
27 changes: 26 additions & 1 deletion test/phone.spec.ts
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
import { beforeEach, describe, expect, it } from 'vitest';
import { faker } from '../src';
import { luhnCheck } from './support/luhnCheck';

const seededRuns = [
{
Expand All @@ -15,6 +16,9 @@ const seededRuns = [
phoneFormats: {
noArgs: '!##.!##.####',
},
imei: {
noArgs: '37-917755-141004-5',
},
},
},
{
Expand All @@ -30,6 +34,9 @@ const seededRuns = [
phoneFormats: {
noArgs: '(!##) !##-####',
},
imei: {
noArgs: '25-122540-325523-6',
},
},
},
{
Expand All @@ -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;

Expand Down Expand Up @@ -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();
});
});
}
});
});