Skip to content

Commit

Permalink
feat(autofill): random phone number can not have "0" as second digit (#1
Browse files Browse the repository at this point in the history
)

* feat(autofill): random phone number can not have "0" as second digit
---------

Co-authored-by: Mauro Magnacavallo <mmagnacavallo@vitesicure.it>
  • Loading branch information
NeverBreakSpaghetti and NeverBreakSpaghetti authored Jan 24, 2024
1 parent 1b4c009 commit 379e4df
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 1 deletion.
8 changes: 8 additions & 0 deletions src/lib/services/fakeDataService.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,14 @@ describe("FakeDataService tests", () => {
expect(phone).not.toEqual(FakeDataService.phone());
});

it('phone should return a random phone number without "0" as second phone digit', () => {
for(let i = 0; i < 1000; i++) {
const phone = FakeDataService.phone();
expect(phone).toMatch(/^(\+39)?\d{10}$/);
expect(phone[1]).not.toEqual("0");
}
});

it("street should return a random street name", () => {
const street = FakeDataService.street();
expect(street).toBeTypeOf("string");
Expand Down
2 changes: 1 addition & 1 deletion src/lib/services/fakeDataService.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class FakeDataService {
}

public static phone() {
return "3" + faker.string.numeric({ length: 9 });
return "3" + faker.string.numeric({ length: 1, exclude: "0" }) + faker.string.numeric({ length: 8 });
}

public static street() {
Expand Down

0 comments on commit 379e4df

Please sign in to comment.