chore: fix issues with specs and provider disconnect (#67)
* chore: fix issues with specs and provider disconnect * test: add expects
This commit is contained in:
parent
b7a316fafa
commit
3cd273d2d0
@ -84,6 +84,8 @@ class Api::V1::Accounts::InboxesController < Api::V1::Accounts::BaseController
|
||||
|
||||
channel.disconnect_channel_provider
|
||||
head :ok
|
||||
ensure
|
||||
channel.update_provider_connection!(connection: 'close') if channel.respond_to?(:update_provider_connection!)
|
||||
end
|
||||
|
||||
def destroy
|
||||
|
||||
@ -109,8 +109,6 @@ class Channel::Whatsapp < ApplicationRecord
|
||||
|
||||
def disconnect_channel_provider
|
||||
provider_service.disconnect_channel_provider
|
||||
ensure
|
||||
update_provider_connection!(connection: 'close')
|
||||
end
|
||||
|
||||
delegate :setup_channel_provider, to: :provider_service
|
||||
|
||||
@ -18,7 +18,7 @@ class Whatsapp::Providers::WhatsappBaileysService < Whatsapp::Providers::BaseSer
|
||||
webhookVerifyToken: whatsapp_channel.provider_config['webhook_verify_token'],
|
||||
# TODO: Remove on Baileys v2, default will be false
|
||||
includeMedia: false
|
||||
}.compact_blank.to_json
|
||||
}.compact.to_json
|
||||
)
|
||||
|
||||
process_response(response)
|
||||
|
||||
@ -979,6 +979,23 @@ RSpec.describe 'Inboxes API', type: :request do
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:ok)
|
||||
expect(channel.reload.provider_connection).to eq('connection' => 'close')
|
||||
end
|
||||
|
||||
it 'ensures provider connection is updated to close' do
|
||||
channel.update_provider_connection!(connection: 'open')
|
||||
service_double = instance_double(Whatsapp::Providers::WhatsappBaileysService, disconnect_channel_provider: true)
|
||||
allow(service_double).to receive(:disconnect_channel_provider).and_raise(StandardError)
|
||||
allow(Whatsapp::Providers::WhatsappBaileysService).to receive(:new)
|
||||
.with(whatsapp_channel: channel)
|
||||
.and_return(service_double)
|
||||
|
||||
post "/api/v1/accounts/#{account.id}/inboxes/#{inbox.id}/disconnect_channel_provider",
|
||||
headers: admin.create_new_auth_token,
|
||||
as: :json
|
||||
|
||||
expect(response).to have_http_status(:internal_server_error)
|
||||
expect(channel.reload.provider_connection).to eq('connection' => 'close')
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Loading…
Reference in New Issue
Block a user