Skip to content

Commit

Permalink
misc: Force using external_subscription_id when estimating fees
Browse files Browse the repository at this point in the history
  • Loading branch information
rsempe committed Jul 11, 2024
1 parent f4966af commit 7a28d22
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 52 deletions.
19 changes: 1 addition & 18 deletions app/controllers/api/v1/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,13 +61,9 @@ def show
end

def estimate_fees
if create_params[:external_subscription_id].blank?
Deprecation.report('estimate_fees_missing_external_subscription_id', current_organization.id)
end

result = Fees::EstimatePayInAdvanceService.call(
organization: current_organization,
params: estimate_fees_params
params: create_params
)

if result.success?
Expand Down Expand Up @@ -98,19 +94,6 @@ def create_params
)
end

def estimate_fees_params
params
.require(:event)
.permit(
:transaction_id,
:code,
:timestamp,
:external_customer_id,
:external_subscription_id,
properties: {}
)
end

def batch_params
params
.permit(
Expand Down
38 changes: 4 additions & 34 deletions spec/requests/api/v1/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -126,7 +126,6 @@
before do
charge
tax
allow(Deprecation).to receive(:report)
end

it 'returns a success' do
Expand All @@ -135,7 +134,7 @@
'/api/v1/events/estimate_fees',
event: {
code: metric.code,
external_customer_id: customer.external_id,
external_subscription_id: subscription.external_id,
transaction_id: SecureRandom.uuid,
properties: {
foo: 'bar'
Expand All @@ -148,8 +147,6 @@

expect(json[:fees].count).to eq(1)

expect(Deprecation).to have_received(:report).with('estimate_fees_missing_external_subscription_id', organization.id)

fee = json[:fees].first
expect(fee[:lago_id]).to be_nil
expect(fee[:lago_group_id]).to be_nil
Expand Down Expand Up @@ -180,31 +177,7 @@
}
)

aggregate_failures do
expect(Deprecation).to have_received(:report).with('estimate_fees_missing_external_subscription_id', organization.id)
expect(response).to have_http_status(:not_found)
end
end
end

context 'with external_subscription_id' do
it 'returns a success' do
post_with_token(
organization,
'/api/v1/events/estimate_fees',
event: {
code: metric.code,
external_subscription_id: subscription.external_id,
properties: {
foo: 'bar'
}
}
)

aggregate_failures do
expect(Deprecation).not_to have_received(:report)
expect(response).to have_http_status(:success)
end
expect(response).to have_http_status(:not_found)
end
end

Expand All @@ -217,17 +190,14 @@
'/api/v1/events/estimate_fees',
event: {
code: metric.code,
external_customer_id: customer.external_id,
external_subscription_id: subscription.external_id,
properties: {
foo: 'bar'
}
}
)

aggregate_failures do
expect(Deprecation).to have_received(:report).with('estimate_fees_missing_external_subscription_id', organization.id)
expect(response).to have_http_status(:unprocessable_entity)
end
expect(response).to have_http_status(:unprocessable_entity)
end
end
end
Expand Down

0 comments on commit 7a28d22

Please sign in to comment.