Skip to content

Commit

Permalink
fix (customers): save correctly customer billing configuration upon c…
Browse files Browse the repository at this point in the history
…ustomer creation (#911)

* save correctly customer billing configuration upon customer creation

* refactor customer service spec
  • Loading branch information
lovrocolic authored Mar 9, 2023
1 parent bcdca6d commit 890dd86
Show file tree
Hide file tree
Showing 2 changed files with 24 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/services/customers/create_service.rb
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,7 @@ def handle_api_billing_configuration(customer, params, new_customer)

if new_customer
create_billing_configuration(customer, billing)
customer.save!
return
end

Expand Down
23 changes: 23 additions & 0 deletions spec/services/customers/create_service_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,29 @@
end
end

it 'creates customer with correctly persisted attributes' do
result = customers_service.create_from_api(
organization:,
params: create_args,
)

expect(result).to be_success

customer = Customer.find_by(external_id:)
billing = create_args[:billing_configuration]

expect(customer).to have_attributes(
organization_id: organization.id,
external_id: create_args[:external_id],
name: create_args[:name],
currency: create_args[:currency],
timezone: nil,
vat_rate: billing[:vat_rate],
document_locale: billing[:document_locale],
invoice_grace_period: nil,
)
end

it 'calls SegmentTrackJob' do
customer = customers_service.create_from_api(
organization:,
Expand Down

0 comments on commit 890dd86

Please sign in to comment.