fix(whatsapp): open correct Meta business account

This commit is contained in:
Muhsin
2026-07-22 11:03:49 +04:00
parent f83bba4cd0
commit a2b7a11b6c
2 changed files with 64 additions and 4 deletions
@@ -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');
@@ -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'
);
});
});