Skip to content

Commit

Permalink
fix (integrations-customers): scope integration customer under correc…
Browse files Browse the repository at this point in the history
…t organization (#2223)

## Context

Lago is actively adding new integrations

## Description

When creating integration customer, we should assign valid
`integration_id` to it. If multiple organizations use the same `code`
for certain `integration` object, there is a chance that wrong
`integration` would be assign to the integration customer.
  • Loading branch information
lovrocolic authored Jun 27, 2024
1 parent 01299d5 commit 854cffe
Show file tree
Hide file tree
Showing 2 changed files with 9 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ def integration

code = integration_customer_params[:integration_code]

@integration = Integrations::BaseIntegration.find_by(type:, code:)
@integration = Integrations::BaseIntegration.find_by(type:, code:, organization: customer.organization)
end

def integration_customer
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -152,8 +152,15 @@
let(:external_customer_id) { nil }
let(:new_customer) { true }

let(:integration_two) { create(:netsuite_integration, organization: organization_two, code: integration.code) }
let(:organization_two) { create(:organization) }

before { integration_two }

it 'calls create job' do
expect { service_call }.to have_enqueued_job(IntegrationCustomers::CreateJob)
expect do
service_call
end.to have_enqueued_job(IntegrationCustomers::CreateJob).with(hash_including(integration:))
end

context 'when updating existing customer without integration customer' do
Expand Down

0 comments on commit 854cffe

Please sign in to comment.