fix: Remove the same account validation for whatsapp channels (#12811)

## Description

Modified the phone number validation in Whatsapp::ChannelCreationService
to check for duplicate phone numbers across ALL accounts, not just
within the current account.

## Type of change

- [ ] Bug fix (non-breaking change which fixes an issue)

## How Has This Been Tested?

- Added test coverage for cross-account phone number validation
- Using actual UI flow 
<img width="1493" height="532" alt="image"
src="https://github.com/user-attachments/assets/67d2bb99-2eb9-4115-8d56-449e4785e0d8"
/>


## Checklist:

- [ ] My code follows the style guidelines of this project
- [ ] I have performed a self-review of my code
- [ ] I have commented on my code, particularly in hard-to-understand
areas
- [ ] I have made corresponding changes to the documentation
- [ ] My changes generate no new warnings
- [ ] I have added tests that prove my fix is effective or that my
feature works
- [ ] New and existing unit tests pass locally with my changes
- [ ] Any dependent changes have been merged and published in downstream
modules
This commit is contained in:
Tanmay Deep Sharma
2025-11-06 21:18:52 +05:30
committed by GitHub
parent ba8df900e3
commit 90352b3a20
3 changed files with 11 additions and 6 deletions

View File

@@ -62,14 +62,19 @@ describe Whatsapp::ChannelCreationService do
end
end
context 'when channel already exists' do
context 'when channel already exists for the phone number' do
let(:different_account) { create(:account) }
before do
create(:channel_whatsapp, account: account, phone_number: '+1234567890',
create(:channel_whatsapp, account: different_account, phone_number: '+1234567890',
provider: 'whatsapp_cloud', sync_templates: false, validate_provider_config: false)
end
it 'raises an error' do
expect { service.perform }.to raise_error(/Channel already exists/)
it 'raises an error even if the channel belongs to a different account' do
expect { service.perform }.to raise_error(
RuntimeError,
I18n.t('errors.whatsapp.phone_number_already_exists', phone_number: '+1234567890')
)
end
end