2024-11-26 21:58:36 +00:00
|
|
|
import { describe, it, expect } from 'vitest';
|
|
|
|
import parsePhone from 'src/filters/parsePhone';
|
|
|
|
|
2024-11-27 00:30:42 +00:00
|
|
|
describe('parsePhone filter', () => {
|
2024-11-26 21:58:36 +00:00
|
|
|
it("adds prefix +34 if it doesn't have one", () => {
|
|
|
|
const resultado = parsePhone('123456789', '34');
|
|
|
|
expect(resultado).toBe('34123456789');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('maintains prefix +34 if it is already correct', () => {
|
|
|
|
const resultado = parsePhone('+34123456789', '34');
|
|
|
|
expect(resultado).toBe('34123456789');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts prefix 0034 to +34', () => {
|
|
|
|
const resultado = parsePhone('0034123456789', '34');
|
|
|
|
expect(resultado).toBe('34123456789');
|
|
|
|
});
|
|
|
|
|
|
|
|
it('converts prefix 34 without symbol to +34', () => {
|
|
|
|
const resultado = parsePhone('34123456789', '34');
|
|
|
|
expect(resultado).toBe('34123456789');
|
|
|
|
});
|
|
|
|
|
2024-11-27 00:30:42 +00:00
|
|
|
it('replaces incorrect prefix with the correct one', () => {
|
2024-11-26 21:58:36 +00:00
|
|
|
const resultado = parsePhone('+44123456789', '34');
|
|
|
|
expect(resultado).toBe('44123456789');
|
|
|
|
});
|
|
|
|
});
|