Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat(events): Track event sent without external_subscription_id for /estimate_fees #2271

Merged
merged 1 commit into from
Jul 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 4 additions & 0 deletions app/controllers/api/v1/events_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,10 @@ 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: create_params
Expand Down
28 changes: 27 additions & 1 deletion spec/requests/api/v1/events_controller_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -127,6 +127,7 @@
before do
charge
tax
allow(Deprecation).to receive(:report)
end

it 'returns a success' do
Expand All @@ -148,6 +149,8 @@

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 All @@ -171,19 +174,41 @@
'/api/v1/events/estimate_fees',
event: {
code: metric.code,
external_customer_id: nil,
external_subscription_id: nil,
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(: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
end
end

context 'when metric code does not match an pay_in_advance charge' do
let(:charge) { create(:standard_charge, plan:, billable_metric: metric) }

Expand All @@ -201,6 +226,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(:unprocessable_entity)
end
end
Expand Down