HOTFIX SaySimple redirect #1005
|
@ -1,14 +1,11 @@
|
||||||
export default function (phone, prefix = 34) {
|
export default function (phone, prefix = 34) {
|
||||||
if (phone.startsWith('+')) {
|
if (phone.startsWith('+')) {
|
||||||
console.log('a');
|
|
||||||
return `${phone.slice(1)}`;
|
return `${phone.slice(1)}`;
|
||||||
}
|
}
|
||||||
if (phone.startsWith('00')) {
|
if (phone.startsWith('00')) {
|
||||||
console.log('b');
|
|
||||||
return `${phone.slice(2)}`;
|
return `${phone.slice(2)}`;
|
||||||
}
|
}
|
||||||
if (phone.startsWith(prefix) && phone.length === prefix.length + 9) {
|
if (phone.startsWith(prefix) && phone.length === prefix.length + 9) {
|
||||||
console.log('c');
|
|
||||||
return `${prefix}${phone.slice(prefix.length)}`;
|
return `${prefix}${phone.slice(prefix.length)}`;
|
||||||
}
|
}
|
||||||
return `${prefix}${phone}`;
|
return `${prefix}${phone}`;
|
||||||
|
|
|
@ -0,0 +1,29 @@
|
||||||
|
import { describe, it, expect } from 'vitest';
|
||||||
|
import parsePhone from 'src/filters/parsePhone';
|
||||||
|
|
||||||
|
describe.only('parsePhone filter', () => {
|
||||||
|
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');
|
||||||
|
});
|
||||||
|
|
||||||
|
it.only('replaces incorrect prefix with the correct one', () => {
|
||||||
|
const resultado = parsePhone('+44123456789', '34');
|
||||||
|
expect(resultado).toBe('44123456789');
|
||||||
|
});
|
||||||
|
});
|
Loading…
Reference in New Issue