diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/AccountHealth.vue b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/AccountHealth.vue index 77607c106..f902d45d9 100644 --- a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/AccountHealth.vue +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/AccountHealth.vue @@ -314,11 +314,18 @@ const errorState = computed(() => { }); const handleGoToSettings = () => { - const { business_portfolio_id: businessPortfolioId } = props.healthData || {}; + const { + business_account_id: businessAccountId, + business_portfolio_id: businessPortfolioId, + } = props.healthData || {}; - if (businessPortfolioId) { - const whatsappBusinessUrl = `https://business.facebook.com/latest/whatsapp_manager/phone_numbers/?business_id=${businessPortfolioId}&tab=phone-numbers`; - window.open(whatsappBusinessUrl, '_blank'); + if (businessPortfolioId && businessAccountId) { + const whatsappBusinessUrl = new URL( + 'https://business.facebook.com/latest/whatsapp_manager/phone_numbers/' + ); + whatsappBusinessUrl.searchParams.set('business_id', businessPortfolioId); + whatsappBusinessUrl.searchParams.set('asset_id', businessAccountId); + window.open(whatsappBusinessUrl.toString(), '_blank'); } else { const fallbackUrl = 'https://business.facebook.com/'; window.open(fallbackUrl, '_blank'); diff --git a/app/javascript/dashboard/routes/dashboard/settings/inbox/components/specs/AccountHealth.spec.js b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/specs/AccountHealth.spec.js new file mode 100644 index 000000000..2258b6654 --- /dev/null +++ b/app/javascript/dashboard/routes/dashboard/settings/inbox/components/specs/AccountHealth.spec.js @@ -0,0 +1,53 @@ +import { shallowMount } from '@vue/test-utils'; +import ButtonV4 from 'next/button/Button.vue'; +import AccountHealth from '../AccountHealth.vue'; + +vi.mock('vue-i18n', () => ({ + useI18n: () => ({ + t: key => key, + te: () => false, + locale: { value: 'en' }, + }), +})); + +describe('AccountHealth', () => { + const mountComponent = healthData => + shallowMount(AccountHealth, { + props: { healthData }, + }); + + beforeEach(() => { + vi.spyOn(window, 'open').mockImplementation(() => {}); + }); + + afterEach(() => { + vi.restoreAllMocks(); + }); + + it('opens the phone numbers page for the correct WhatsApp Business Account', async () => { + const wrapper = mountComponent({ + business_account_id: 'waba-456', + business_portfolio_id: 'business-123', + }); + + await wrapper.findComponent(ButtonV4).trigger('click'); + + expect(window.open).toHaveBeenCalledWith( + 'https://business.facebook.com/latest/whatsapp_manager/phone_numbers/?business_id=business-123&asset_id=waba-456', + '_blank' + ); + }); + + it('opens Meta Business Manager when the WhatsApp Business Account ID is unavailable', async () => { + const wrapper = mountComponent({ + business_portfolio_id: 'business-123', + }); + + await wrapper.findComponent(ButtonV4).trigger('click'); + + expect(window.open).toHaveBeenCalledWith( + 'https://business.facebook.com/', + '_blank' + ); + }); +});