From 25b8535f192cfc5bb0dad7ecb1e0bb034df6eefc Mon Sep 17 00:00:00 2001 From: jorgep Date: Wed, 27 Nov 2024 12:54:11 +0100 Subject: [PATCH 1/5] refactor: refs #6818 check prefix --- src/components/ui/VnLinkPhone.vue | 16 ++++++++--- src/filters/parsePhone.js | 18 ++++++------- src/pages/Customer/Card/CustomerSummary.vue | 1 + .../components/common/VnLinkPhone.spec.js | 27 +++++++++++-------- 4 files changed, 37 insertions(+), 25 deletions(-) diff --git a/src/components/ui/VnLinkPhone.vue b/src/components/ui/VnLinkPhone.vue index 4068498cd..6fefd1914 100644 --- a/src/components/ui/VnLinkPhone.vue +++ b/src/components/ui/VnLinkPhone.vue @@ -1,10 +1,10 @@ diff --git a/test/vitest/__tests__/components/common/VnLinkPhone.spec.js b/test/vitest/__tests__/components/common/VnLinkPhone.spec.js index e460ab2fc..a14e509ae 100644 --- a/test/vitest/__tests__/components/common/VnLinkPhone.spec.js +++ b/test/vitest/__tests__/components/common/VnLinkPhone.spec.js @@ -1,29 +1,34 @@ -import { describe, it, expect } from 'vitest'; +import { describe, it, expect, beforeAll, vi } from 'vitest'; +import { axios } from 'app/test/vitest/helper'; import parsePhone from 'src/filters/parsePhone'; describe('parsePhone filter', () => { - it("adds prefix +34 if it doesn't have one", () => { - const resultado = parsePhone('123456789', '34'); + beforeAll(async () => { + vi.spyOn(axios, 'get').mockReturnValue({ data: { prefix: '34' } }); + }); + + it("adds prefix +34 if it doesn't have one", async () => { + const resultado = await parsePhone('123456789', '34'); expect(resultado).toBe('34123456789'); }); - it('maintains prefix +34 if it is already correct', () => { - const resultado = parsePhone('+34123456789', '34'); + it('maintains prefix +34 if it is already correct', async () => { + const resultado = await parsePhone('+34123456789', '34'); expect(resultado).toBe('34123456789'); }); - it('converts prefix 0034 to +34', () => { - const resultado = parsePhone('0034123456789', '34'); + it('converts prefix 0034 to +34', async () => { + const resultado = await parsePhone('0034123456789', '34'); expect(resultado).toBe('34123456789'); }); - it('converts prefix 34 without symbol to +34', () => { - const resultado = parsePhone('34123456789', '34'); + it('converts prefix 34 without symbol to +34', async () => { + const resultado = await parsePhone('34123456789', '34'); expect(resultado).toBe('34123456789'); }); - it('replaces incorrect prefix with the correct one', () => { - const resultado = parsePhone('+44123456789', '34'); + it('replaces incorrect prefix with the correct one', async () => { + const resultado = await parsePhone('+44123456789', '34'); expect(resultado).toBe('44123456789'); }); }); From d4028da92e976b68dae1032b95ae33d5002fd68b Mon Sep 17 00:00:00 2001 From: jorgep Date: Thu, 28 Nov 2024 10:25:50 +0100 Subject: [PATCH 2/5] fix: refs #6818 refactor phone parsing and improve error handling --- src/components/ui/VnLinkPhone.vue | 22 +++++++++------------- src/filters/parsePhone.js | 13 +++++++++---- 2 files changed, 18 insertions(+), 17 deletions(-) diff --git a/src/components/ui/VnLinkPhone.vue b/src/components/ui/VnLinkPhone.vue index 6fefd1914..c5023f69e 100644 --- a/src/components/ui/VnLinkPhone.vue +++ b/src/components/ui/VnLinkPhone.vue @@ -1,12 +1,15 @@