chore: General fixes and clean up (#1169)
This commit is contained in:
6
spec/factories/installation_config.rb
Normal file
6
spec/factories/installation_config.rb
Normal file
@@ -0,0 +1,6 @@
|
||||
FactoryBot.define do
|
||||
factory :installation_config do
|
||||
name { 'xyc' }
|
||||
value { 1.5 }
|
||||
end
|
||||
end
|
||||
44
spec/listeners/installation_webhook_listener_spec.rb
Normal file
44
spec/listeners/installation_webhook_listener_spec.rb
Normal file
@@ -0,0 +1,44 @@
|
||||
require 'rails_helper'
|
||||
describe InstallationWebhookListener do
|
||||
let(:listener) { described_class.instance }
|
||||
let!(:account) { create(:account) }
|
||||
let!(:event) { Events::Base.new(event_name, Time.zone.now, account: account) }
|
||||
|
||||
describe '#account_created' do
|
||||
let(:event_name) { :'account.created' }
|
||||
|
||||
context 'when installation config is not configured' do
|
||||
it 'does not trigger webhook' do
|
||||
expect(WebhookJob).to receive(:perform_later).exactly(0).times
|
||||
listener.account_created(event)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when installation config is configured' do
|
||||
it 'triggers webhook' do
|
||||
create(:installation_config, name: 'INSTALLATION_EVENTS_WEBHOOK_URL', value: 'https://test.com')
|
||||
expect(WebhookJob).to receive(:perform_later).with('https://test.com', account.webhook_data.merge(event: 'account_created')).once
|
||||
listener.account_created(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
describe '#account_destroyed' do
|
||||
let(:event_name) { :'account.destroyed' }
|
||||
|
||||
context 'when installation config is not configured' do
|
||||
it 'does not trigger webhook' do
|
||||
expect(WebhookJob).to receive(:perform_later).exactly(0).times
|
||||
listener.account_destroyed(event)
|
||||
end
|
||||
end
|
||||
|
||||
context 'when installation config is configured' do
|
||||
it 'triggers webhook' do
|
||||
create(:installation_config, name: 'INSTALLATION_EVENTS_WEBHOOK_URL', value: 'https://test.com')
|
||||
expect(WebhookJob).to receive(:perform_later).with('https://test.com', account.webhook_data.merge(event: 'account_destroyed')).once
|
||||
listener.account_destroyed(event)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -17,7 +17,7 @@ describe WebhookListener do
|
||||
|
||||
context 'when webhook is not configured' do
|
||||
it 'does not trigger webhook' do
|
||||
expect(RestClient).to receive(:post).exactly(0).times
|
||||
expect(WebhookJob).to receive(:perform_later).exactly(0).times
|
||||
listener.message_created(event)
|
||||
end
|
||||
end
|
||||
|
||||
Reference in New Issue
Block a user