Skip to content

Commit

Permalink
fix(tax-integrations): update anrok error webhook attributes (#2497)
Browse files Browse the repository at this point in the history
## Context

Integration with tax provider Anrok is being implemented

## Description

This PR fixes error webhook that is being dispatched
  • Loading branch information
lovrocolic authored Aug 28, 2024
1 parent b4d4987 commit a5db8cf
Show file tree
Hide file tree
Showing 3 changed files with 52 additions and 1 deletion.
19 changes: 19 additions & 0 deletions app/serializers/v1/integrations/taxes/customer_error_serializer.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,19 @@
# frozen_string_literal: true

module V1
module Integrations
module Taxes
class CustomerErrorSerializer < ModelSerializer
def serialize
{
lago_customer_id: model.id,
external_customer_id: model.external_id,
tax_provider: options[:provider],
tax_provider_code: options[:provider_code],
provider_error: options[:provider_error]
}
end
end
end
end
end
2 changes: 1 addition & 1 deletion app/services/webhooks/integrations/taxes/error_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ def current_organization
end

def object_serializer
::V1::Integrations::CustomerErrorSerializer.new(
::V1::Integrations::Taxes::CustomerErrorSerializer.new(
object,
root_name: object_type,
provider_error: options[:provider_error],
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# frozen_string_literal: true

require 'rails_helper'

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

let(:integration_customer) { create(:netsuite_customer) }
let(:customer) { integration_customer.customer }
let(:options) do
{
'provider_error' => {
'error_message' => 'message',
'error_code' => 'code'
},
'provider' => 'netsuite',
'provider_code' => integration_customer.integration.code
}.with_indifferent_access
end

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

aggregate_failures do
expect(result['data']['lago_customer_id']).to eq(customer.id)
expect(result['data']['external_customer_id']).to eq(customer.external_id)
expect(result['data']['tax_provider']).to eq(options[:provider])
expect(result['data']['tax_provider_code']).to eq(integration_customer.integration.code)
expect(result['data']['provider_error']).to eq(options[:provider_error])
end
end
end

0 comments on commit a5db8cf

Please sign in to comment.