feat: validate sender before creating campaign (#10934)

This commit is contained in:
Shivam Mishra
2025-02-20 16:15:03 +05:30
committed by GitHub
parent 9631b0b929
commit 7fcb0d6880
2 changed files with 32 additions and 0 deletions

View File

@@ -114,4 +114,26 @@ RSpec.describe Campaign do
end
end
end
context 'when validating sender' do
let(:account) { create(:account) }
let(:user) { create(:user, account: account) }
let(:web_widget) { create(:channel_widget, account: account) }
let(:inbox) { create(:inbox, channel: web_widget, account: account) }
it 'allows sender from the same account' do
campaign = build(:campaign, inbox: inbox, account: account, sender: user)
expect(campaign).to be_valid
end
it 'does not allow sender from different account' do
other_account = create(:account)
other_user = create(:user, account: other_account)
campaign = build(:campaign, inbox: inbox, account: account, sender: other_user)
expect(campaign).not_to be_valid
expect(campaign.errors[:sender_id]).to include(
'must belong to the same account as the campaign'
)
end
end
end