Skip to content
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

feat (tax-integrations): add support for tax integration generic error webhook #2393

Merged
merged 1 commit into from
Aug 9, 2024
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
1 change: 1 addition & 0 deletions app/jobs/send_webhook_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ class SendWebhookJob < ApplicationJob
retry_on ActiveJob::DeserializationError, wait: :polynomially_longer, attempts: 6

WEBHOOK_SERVICES = {
'integration.tax_provider_error' => Webhooks::Integrations::Taxes::ErrorService,
'invoice.created' => Webhooks::Invoices::CreatedService,
'invoice.one_off_created' => Webhooks::Invoices::OneOffCreatedService,
'invoice.add_on_added' => Webhooks::Invoices::AddOnCreatedService,
Expand Down
16 changes: 16 additions & 0 deletions app/serializers/v1/integrations/taxes/error_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
# frozen_string_literal: true

module V1
module Integrations
module Taxes
class ErrorSerializer < ModelSerializer
def serialize
{
tax_provider_code: model.code,
provider_error: options[:provider_error]
}
end
end
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@ module Taxes
class FeeErrorSerializer < ModelSerializer
def serialize
{
lago_integration_id: model.id,
tax_provider_code: model.code,
lago_charge_id: options[:lago_charge_id],
event_transaction_id: options[:event_transaction_id],
Expand Down
31 changes: 31 additions & 0 deletions app/services/webhooks/integrations/taxes/error_service.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
# frozen_string_literal: true

module Webhooks
module Integrations
module Taxes
class ErrorService < Webhooks::BaseService
private

def current_organization
@current_organization ||= object.organization
end

def object_serializer
::V1::Integrations::Taxes::ErrorSerializer.new(
object,
root_name: object_type,
provider_error: options[:provider_error]
)
end

def webhook_type
'integration.tax_provider_error'
end

def object_type
'tax_provider_error'
end
end
end
end
end
26 changes: 26 additions & 0 deletions spec/serializers/v1/integrations/taxes/error_serializer_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,26 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe ::V1::Integrations::Taxes::ErrorSerializer do
subject(:serializer) { described_class.new(integration, options) }

let(:integration) { create(:anrok_integration) }
let(:options) do
{
'provider_error' => {
'error_message' => 'message',
'error_code' => 'code'
}
}.with_indifferent_access
end

it 'serializes the object' do
result = JSON.parse(serializer.to_json)

aggregate_failures do
expect(result['data']['tax_provider_code']).to eq(integration.code)
expect(result['data']['provider_error']).to eq(options[:provider_error])
end
end
end
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@
result = JSON.parse(serializer.to_json)

aggregate_failures do
expect(result['data']['lago_integration_id']).to eq(integration.id)
expect(result['data']['tax_provider_code']).to eq(integration.code)
expect(result['data']['lago_charge_id']).to eq('456')
expect(result['data']['event_transaction_id']).to eq('123')
Expand Down
19 changes: 19 additions & 0 deletions spec/services/webhooks/integrations/taxes/error_service_spec.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

require 'rails_helper'

RSpec.describe Webhooks::Integrations::Taxes::ErrorService do
subject(:webhook_service) { described_class.new(object: integration, options: webhook_options) }

let(:integration) { create(:anrok_integration, organization:) }
let(:organization) { create(:organization) }
let(:webhook_options) do
{
provider_error: {message: 'message', error_code: 'code'}
}
end

describe '.call' do
it_behaves_like 'creates webhook', 'integration.tax_provider_error', 'tax_provider_error'
end
end