8000 fix: try to disconnect baileys before destroy inbox by CayoPOliveira · Pull Request #29 · fazer-ai/chatwoot · GitHub
[go: up one dir, main page]
More Web Proxy on the site http://driver.im/
Skip to content

fix: try to disconnect baileys before destroy inbox #29

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions app/models/channel/whatsapp.rb
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,8 @@ class Channel::Whatsapp < ApplicationRecord

after_create :sync_templates

before_destroy :disconnect_channel_provider, if: -> { provider == 'baileys' }

def name
'Whatsapp'
end
Expand Down
37 changes: 37 additions & 0 deletions spec/models/channel/whatsapp_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,4 +61,41 @@
expect(channel.provider_config['webhook_verify_token']).to eq '123'
end
end

describe 'callbacks' do
describe '#disconnect_channel_provider' do
context 'when provider is baileys' do
let(:channel) { create(:channel_whatsapp, provider: 'baileys', validate_provider_config: false, sync_templates: false) }
let(:disconnect_url) { "#{channel.provider_config['provider_url']}/connections/#{channel.phone_number}" }

it 'destroys the channel on successful disconnect' do
stub_request(:delete, disconnect_url).to_return(status: 200)

channel.destroy!

expect(channel).to be_destroyed
end

it 'destroys the channel on failure to disconnect' do
stub_request(:delete, disconnect_url).to_return(status: 404, body: 'error message')

channel.destroy!

expect(channel).to be_destroyed
end
end

context 'when provider is not baileys' do
let(:channel) { create(:channel_whatsapp, provider: 'whatsapp_cloud', validate_provider_config: false, sync_templates: false) }

it 'does not invoke callback' do
expect(channel).not_to receive(:disconnect_channel_provider)

channel.destroy!

expect(channel).to be_destroyed
end
end
end
end
end
0