2024-11-27 11:54:11 +00:00
|
|
|
import { describe, it, expect, beforeAll, vi } from 'vitest';
|
|
|
|
import { axios } from 'app/test/vitest/helper';
|
2024-11-26 21:58:36 +00:00
|
|
|
import parsePhone from 'src/filters/parsePhone';
|
|
|
|
|
2024-11-27 00:30:42 +00:00
|
|
|
describe('parsePhone filter', () => {
|
2024-11-27 11:54:11 +00:00
|
|
|
beforeAll(async () => {
|
|
|
|
vi.spyOn(axios, 'get').mockReturnValue({ data: { prefix: '34' } });
|
|
|
|
});
|
|
|
|
|
2024-12-02 09:36:30 +00:00
|
|
|
it('no phone', async () => {
|
|
|
|
const phone = await parsePhone(null, '34');
|
2024-12-02 09:36:18 +00:00
|
|
|
expect(phone).toBe(undefined);
|
|
|
|
});
|
|
|
|
|
2024-11-27 11:54:11 +00:00
|
|
|
it("adds prefix +34 if it doesn't have one", async () => {
|
2024-12-02 09:36:18 +00:00
|
|
|
const phone = await parsePhone('123456789', '34');
|
|
|
|
expect(phone).toBe('34123456789');
|
2024-11-26 21:58:36 +00:00
|
|
|
});
|
|
|
|
|
2024-11-27 11:54:11 +00:00
|
|
|
it('maintains prefix +34 if it is already correct', async () => {
|
2024-12-02 09:36:18 +00:00
|
|
|
const phone = await parsePhone('+34123456789', '34');
|
|
|
|
expect(phone).toBe('34123456789');
|
2024-11-26 21:58:36 +00:00
|
|
|
});
|
|
|
|
|
2024-11-27 11:54:11 +00:00
|
|
|
it('converts prefix 0034 to +34', async () => {
|
2024-12-02 09:36:18 +00:00
|
|
|
const phone = await parsePhone('0034123456789', '34');
|
|
|
|
expect(phone).toBe('34123456789');
|
2024-11-26 21:58:36 +00:00
|
|
|
});
|
|
|
|
|
2024-11-27 11:54:11 +00:00
|
|
|
it('converts prefix 34 without symbol to +34', async () => {
|
2024-12-02 09:36:18 +00:00
|
|
|
const phone = await parsePhone('34123456789', '34');
|
|
|
|
expect(phone).toBe('34123456789');
|
2024-11-26 21:58:36 +00:00
|
|
|
});
|
|
|
|
|
2024-11-27 11:54:11 +00:00
|
|
|
it('replaces incorrect prefix with the correct one', async () => {
|
2024-12-02 09:36:18 +00:00
|
|
|
const phone = await parsePhone('+44123456789', '34');
|
|
|
|
expect(phone).toBe('44123456789');
|
2024-11-26 21:58:36 +00:00
|
|
|
});
|
|
|
|
});
|