fix: parsePhone fn when no phone

This commit is contained in:
Javier Segarra 2024-12-01 19:18:55 +01:00
parent d9d6819390
commit e2304396d8
2 changed files with 11 additions and 0 deletions

View File

@ -1,4 +1,7 @@
export default function (phone, prefix = 34) {
if (!phone) {
return;
}
if (phone.startsWith('+')) {
return `${phone.slice(1)}`;
}

View File

@ -2,6 +2,14 @@ import { describe, it, expect } from 'vitest';
import parsePhone from 'src/filters/parsePhone';
describe('parsePhone filter', () => {
it('no phone', () => {
const resultado = parsePhone(null, '34');
expect(resultado).toBe(undefined);
});
it('no phone and no prefix', () => {
const resultado = parsePhone(null, null);
expect(resultado).toBe(undefined);
});
it("adds prefix +34 if it doesn't have one", () => {
const resultado = parsePhone('123456789', '34');
expect(resultado).toBe('34123456789');