fix(whatsapp): open correct Meta business account
This commit is contained in:
+11
-4
@@ -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');
|
||||
|
||||
+53
@@ -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'
|
||||
);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user