Skip to content

Commit

Permalink
enable throttling for anrok
Browse files Browse the repository at this point in the history
  • Loading branch information
lovrocolic committed Dec 23, 2024
1 parent 95e361f commit 6d7e48a
Show file tree
Hide file tree
Showing 10 changed files with 109 additions and 0 deletions.
1 change: 1 addition & 0 deletions app/graphql/types/invoices/object.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ class Object < Types::BaseObject
field :payment_dispute_lost_at, GraphQL::Types::ISO8601DateTime
field :payment_status, Types::Invoices::PaymentStatusTypeEnum, null: false
field :status, Types::Invoices::StatusTypeEnum, null: false
field :tax_status, Types::Invoices::TaxStatusTypeEnum, null: true
field :voidable, Boolean, null: false, method: :voidable?

field :currency, Types::CurrencyEnum
Expand Down
13 changes: 13 additions & 0 deletions app/graphql/types/invoices/tax_status_type_enum.rb
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
# frozen_string_literal: true

module Types
module Invoices
class TaxStatusTypeEnum < Types::BaseEnum
graphql_name 'InvoiceTaxStatusTypeEnum'

Invoice::TAX_STATUSES.keys.each do |type|
value type
end
end
end
end
4 changes: 4 additions & 0 deletions app/jobs/fees/create_pay_in_advance_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,12 @@

module Fees
class CreatePayInAdvanceJob < ApplicationJob
include ConcurrencyThrottlable

queue_as :default

retry_on BaseService::ThrottlingError, wait: :polynomially_longer, attempts: 25

unique :until_executed, on_conflict: :log

def perform(charge:, event:, billing_at: nil)
Expand Down
3 changes: 3 additions & 0 deletions app/jobs/invoices/create_pay_in_advance_charge_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,8 @@

module Invoices
class CreatePayInAdvanceChargeJob < ApplicationJob
include ConcurrencyThrottlable

queue_as do
if ActiveModel::Type::Boolean.new.cast(ENV['SIDEKIQ_BILLING'])
:billing
Expand All @@ -11,6 +13,7 @@ class CreatePayInAdvanceChargeJob < ApplicationJob
end

retry_on Sequenced::SequenceError
retry_on BaseService::ThrottlingError, wait: :polynomially_longer, attempts: 25

unique :until_executed, on_conflict: :log

Expand Down
4 changes: 4 additions & 0 deletions app/jobs/invoices/provider_taxes/pull_taxes_and_apply_job.rb
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,12 @@
module Invoices
module ProviderTaxes
class PullTaxesAndApplyJob < ApplicationJob
include ConcurrencyThrottlable

queue_as 'integrations'

retry_on BaseService::ThrottlingError, wait: :polynomially_longer, attempts: 25

def perform(invoice:)
Invoices::ProviderTaxes::PullTaxesAndApplyService.call(invoice:)
end
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def call
return result unless integration
return result unless integration.type == 'Integrations::AnrokIntegration'

throttle!(:anrok)

response = http_client.post_with_response(payload, headers)
body = JSON.parse(response.body)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,8 @@ def call
return result unless integration
return result unless integration.type == 'Integrations::AnrokIntegration'

throttle!(:anrok)

response = http_client.post_with_response(payload, headers)
body = JSON.parse(response.body)

Expand Down
7 changes: 7 additions & 0 deletions schema.graphql

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

41 changes: 41 additions & 0 deletions schema.json

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

32 changes: 32 additions & 0 deletions spec/graphql/mutations/invoices/finalize_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
finalizeInvoice(input: $input) {
id
status
taxStatus
}
}
GQL
Expand Down Expand Up @@ -44,4 +45,35 @@
end
end
end

context 'with tax provider' do
let(:integration) { create(:anrok_integration, organization:) }
let(:integration_customer) { create(:anrok_customer, integration:, customer:) }

before do
integration_customer
end

it 'returns pending invoice' do
freeze_time do
result = execute_graphql(
current_user: membership.user,
current_organization: organization,
permissions: required_permission,
query: mutation,
variables: {
input: {id: invoice.id}
}
)

result_data = result['data']['finalizeInvoice']

aggregate_failures do
expect(result_data['id']).to be_present
expect(result_data['status']).to eq('pending')
expect(result_data['taxStatus']).to eq('pending')
end
end
end
end
end

0 comments on commit 6d7e48a

Please sign in to comment.