chore: General fixes and clean up (#1169)

This commit is contained in:
Sojan Jose
2020-08-25 23:04:02 +05:30
committed by GitHub
parent 124e43b477
commit 2193de9853
23 changed files with 111 additions and 121 deletions

View File

@@ -0,0 +1,6 @@
FactoryBot.define do
factory :installation_config do
name { 'xyc' }
value { 1.5 }
end
end

View 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

View File

@@ -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