From 7a28d22abeac94847e7e2df55eb086888b9eeca9 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Romain=20Semp=C3=A9?= Date: Thu, 11 Jul 2024 15:07:21 +0200 Subject: [PATCH] misc: Force using external_subscription_id when estimating fees --- app/controllers/api/v1/events_controller.rb | 19 +--------- .../requests/api/v1/events_controller_spec.rb | 38 ++----------------- 2 files changed, 5 insertions(+), 52 deletions(-) diff --git a/app/controllers/api/v1/events_controller.rb b/app/controllers/api/v1/events_controller.rb index a8821b84272..c46f4ca7ce2 100644 --- a/app/controllers/api/v1/events_controller.rb +++ b/app/controllers/api/v1/events_controller.rb @@ -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? @@ -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( diff --git a/spec/requests/api/v1/events_controller_spec.rb b/spec/requests/api/v1/events_controller_spec.rb index 391307fba63..7c2edd00e8a 100644 --- a/spec/requests/api/v1/events_controller_spec.rb +++ b/spec/requests/api/v1/events_controller_spec.rb @@ -126,7 +126,6 @@ before do charge tax - allow(Deprecation).to receive(:report) end it 'returns a success' do @@ -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' @@ -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 @@ -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 @@ -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