Skip to content

Commit

Permalink
feat(hubspot): Fix integration aggregator services and specs
Browse files Browse the repository at this point in the history
  • Loading branch information
ivannovosad committed Oct 14, 2024
1 parent 15ac1aa commit 5be47d3
Show file tree
Hide file tree
Showing 11 changed files with 55 additions and 15 deletions.
4 changes: 2 additions & 2 deletions app/services/integrations/aggregator/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ def headers

def deliver_error_webhook(customer:, code:, message:)
SendWebhookJob.perform_later(
webhook_code,
error_webhook_code,
customer,
provider:,
provider_code: integration.code,
Expand Down Expand Up @@ -108,7 +108,7 @@ def secret_key
ENV['NANGO_SECRET_KEY']
end

def webhook_code
def error_webhook_code
case provider
when 'hubspot'
'customer.crm_provider_error'
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -25,7 +25,7 @@ def call

return result unless result.contact_id

deliver_success_webhook(customer:, webhook_code: 'customer.crm_provider_created')
deliver_success_webhook(customer:, webhook_code:)

result
rescue LagoHttpClient::HttpError => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,8 +24,6 @@ def call

return result unless result.contact_id

deliver_success_webhook(customer:, webhook_code: 'customer.crm_provider_created')

result
rescue LagoHttpClient::HttpError => e
raise RequestLimitError(e) if request_limit_error?(e)
Expand Down
9 changes: 9 additions & 0 deletions app/services/integrations/aggregator/contacts/base_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,15 @@ def process_hash_result(body)
def process_string_result(body)
result.contact_id = body
end

def webhook_code
case provider
when 'hubspot'
'customer.crm_provider_created'
else
'customer.accounting_provider_created'
end
end
end
end
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ def call

return result unless result.contact_id

deliver_success_webhook(customer:, webhook_code: 'customer.accounting_provider_created')
deliver_success_webhook(customer:, webhook_code:)

result
rescue LagoHttpClient::HttpError => e
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,10 +20,6 @@ def call
process_string_result(body)
end

return result unless result.contact_id

deliver_success_webhook(customer:, webhook_code: 'customer.accounting_provider_created')

result
rescue LagoHttpClient::HttpError => e
raise RequestLimitError(e) if request_limit_error?(e)
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
{
"succeededCompanies": [],
"failedCompanies": [
{
"id": "2e50c200-9a54-4a66-b241-1e75fb87373f",
"name": "Test",
"email": "s@",
"city": "z",
"zip": "73993",
"country": "US",
"state": "NYC",
"phone": "+33818282828",
"validation_errors": [
{
"Message": "Email address must be valid."
}
]
}
]
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
{
"succeededCompanies": [
{
"id": "2e50c200-9a54-4a66-b241-1e75fb87373f",
"name": "Test",
"email": "[email protected]",
"lago_billing_email": "[email protected]",
"city": "NYC",
"zip": "73993",
"country": "US",
"state": "NYC",
"phone": "+33818282828"
}
],
"failedCompanies": []
}
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
"1"
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@
end

let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/contacts/success_hash_response.json')
path = Rails.root.join('spec/fixtures/integration_aggregator/companies/success_hash_response.json')
File.read(path)
end

Expand Down Expand Up @@ -129,7 +129,7 @@

context 'when contact is succesfully created' do
let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/contacts/success_hash_response.json')
path = Rails.root.join('spec/fixtures/integration_aggregator/companies/success_hash_response.json')
File.read(path)
end

Expand All @@ -153,7 +153,7 @@

context 'when contact is not created' do
let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/contacts/failure_hash_response.json')
path = Rails.root.join('spec/fixtures/integration_aggregator/companies/failure_hash_response.json')
File.read(path)
end

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,7 @@
end

let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/contacts/success_string_response.json')
path = Rails.root.join('spec/fixtures/integration_aggregator/companies/success_string_response.json')
File.read(path)
end

Expand Down Expand Up @@ -118,7 +118,7 @@
end

let(:body) do
path = Rails.root.join('spec/fixtures/integration_aggregator/contacts/success_hash_response.json')
path = Rails.root.join('spec/fixtures/integration_aggregator/companies/success_hash_response.json')
File.read(path)
end

Expand Down

0 comments on commit 5be47d3

Please sign in to comment.