Skip to content

Commit

Permalink
test: format phone number
Browse files Browse the repository at this point in the history
  • Loading branch information
fterra-encora committed Jan 10, 2025
1 parent 1ccfdf1 commit a3ac242
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions frontend/tests/unittests/services/ForestClientService.spec.ts
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import {
toTitleCase,
getTagColorByClientStatus,
goodStanding,
formatPhoneNumber,
} from "@/services/ForestClientService";
import type { Contact, Address } from "@/dto/ApplyClientNumberDto";

Expand Down Expand Up @@ -169,4 +170,26 @@ describe("ForestClientService.ts", () => {
});
});
});

describe("formatPhoneNumber", () => {
it("formats 10-digit phone numbers properly", () => {
const result = formatPhoneNumber("1234567890");
expect(result).toEqual("(123) 456-7890");
});

it("doesn't crash when phone numbers has more than 10 digits", () => {
const result = formatPhoneNumber("1234567890123");
expect(result).toEqual("(123) 456-7890123");
});

it("doesn't crash when phone numbers has less than 10 digits", () => {
const result = formatPhoneNumber("12345678");
expect(result).toEqual("(123) 456-78");
});

it("returns an empty string if phone number is undefined", () => {
const result = formatPhoneNumber(undefined);
expect(result).toEqual("");
});
});
});

0 comments on commit a3ac242

Please sign in to comment.