diff --git a/app/queries/fees_query.rb b/app/queries/fees_query.rb index 1a7cbade1e5..0d5be28c26f 100644 --- a/app/queries/fees_query.rb +++ b/app/queries/fees_query.rb @@ -3,7 +3,7 @@ class FeesQuery < BaseQuery def call fees = paginate(Fee.from_organization(organization)) - fees = fees.order(created_at: :asc) + fees = fees.order(created_at: :asc, id: :asc) fees = with_external_subscription(fees) if filters.external_subscription_id fees = with_external_customer(fees) if filters.external_customer_id diff --git a/spec/queries/fees_query_spec.rb b/spec/queries/fees_query_spec.rb index 8e453ab69e5..82dede81f40 100644 --- a/spec/queries/fees_query_spec.rb +++ b/spec/queries/fees_query_spec.rb @@ -26,6 +26,25 @@ end end + context 'with multiple fees' do + let(:fee2) { create(:fee, subscription:, invoice: nil, created_at: fee.created_at) } + + before do + fee2 + fee2.update! id: '00000000-0000-0000-0000-000000000000' + end + + it 'returns a consistent list when 2 fees have the same created_at' do + result = fees_query.call + + aggregate_failures do + expect(result).to be_success + expect(result.fees.count).to eq(2) + expect(result.fees).to eq([fee2, fee]) + end + end + end + context 'with pagination' do let(:pagination) { {page: 2, limit: 10} }