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(fee): Allow filtering fees on event transaction id #2709

Merged
merged 1 commit into from
Oct 18, 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
1 change: 1 addition & 0 deletions app/controllers/api/v1/fees_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ def index_filters
:external_customer_id,
:billable_metric_code,
:currency,
:event_transaction_id,
:created_at_from,
:created_at_to,
:failed_at_from,
Expand Down
2 changes: 2 additions & 0 deletions app/queries/fees_query.rb
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,8 @@ def call
fees = with_fee_type(fees) if filters.fee_type
fees = with_payment_status(fees) if filters.payment_status

fees = fees.where(pay_in_advance_event_transaction_id: filters.event_transaction_id) if filters.event_transaction_id

fees = with_created_date_range(fees) if filters.created_at_from || filters.created_at_to
fees = with_succeeded_date_range(fees) if filters.succeeded_at_from || filters.succeeded_at_to
fees = with_failed_date_range(fees) if filters.failed_at_from || filters.failed_at_to
Expand Down
17 changes: 17 additions & 0 deletions spec/queries/fees_query_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,23 @@
end
end

context 'with event_transaction_id filter' do
let(:fee) do
create(:fee, subscription:, invoice: nil, pay_in_advance_event_transaction_id: 'transaction-id')
end

let(:filters) { {event_transaction_id: 'transaction-id'} }

it 'applies the filter' do
result = fees_query.call

aggregate_failures do
expect(result).to be_success
expect(result.fees.count).to eq(1)
end
end
end

context 'with created_at filters' do
let(:filters) do
{
Expand Down