Skip to content

Commit

Permalink
chore: adjust test
Browse files Browse the repository at this point in the history
  • Loading branch information
rabbitz committed Aug 24, 2023
1 parent 25f66d6 commit 553df75
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 12 deletions.
5 changes: 3 additions & 2 deletions app/controllers/api/v2/pending_transactions_controller.rb
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ def index

total_count = pending_transactions.count
pending_transactions = sort_transactions(pending_transactions).
page(@page).per(@page_size).fast_page
page(@page).per(@page_size)

json = {
data: pending_transactions.map do |tx|
Expand All @@ -29,6 +29,7 @@ def index
page_size: @page_size.to_i
}
}

render json: json
end
end
Expand Down Expand Up @@ -60,7 +61,7 @@ def sort_transactions(records)
order = "asc"
end

records.order("#{sort} #{order} NULLS LAST")
records.order("ckb_transactions.#{sort} #{order} NULLS LAST")
end
end
end
Expand Down
26 changes: 16 additions & 10 deletions test/controllers/api/v2/pending_transactions_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest

test "should return 10 records when page and page_size are not set" do
block = create(:block, :with_block_hash)
create_list(:ckb_transaction, 15, tx_status: "pending", block: block)
create_list(:ckb_transaction, 15, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block)

valid_get api_v2_pending_transactions_url

Expand All @@ -21,7 +21,7 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
page = 2
page_size = 5
block = create(:block, :with_block_hash)
create_list(:ckb_transaction, 15, tx_status: "pending", block: block)
create_list(:ckb_transaction, 15, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block)
ckb_transactions = CkbTransaction.tx_pending.order(id: :desc).recent.page(page).per(page_size)

valid_get api_v2_pending_transactions_url, params: { page: page, page_size: page_size }
Expand All @@ -47,7 +47,7 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest

test "should return default order when sort param not set" do
block = create(:block, :with_block_hash)
create_list(:ckb_transaction, 10, tx_status: "pending", block: block)
create_list(:ckb_transaction, 10, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block)

ckb_transactions = CkbTransaction.tx_pending.order(id: :desc)
response_json = {
Expand Down Expand Up @@ -75,7 +75,8 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
block = create(:block, :with_block_hash)
current_time = Time.current
10.times do |i|
create(:ckb_transaction, tx_status: "pending", block: block, created_at: current_time - i.hours)
create(:ckb_transaction, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block,
created_at: current_time - i.hours)
end

ckb_transactions = CkbTransaction.tx_pending.order(created_at: :asc)
Expand Down Expand Up @@ -104,7 +105,8 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
block = create(:block, :with_block_hash)
current_time = Time.current
10.times do |i|
create(:ckb_transaction, tx_status: "pending", block: block, created_at: current_time - i.hours)
create(:ckb_transaction, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block,
created_at: current_time - i.hours)
end

ckb_transactions = CkbTransaction.tx_pending.order(created_at: :asc)
Expand Down Expand Up @@ -133,7 +135,8 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
block = create(:block, :with_block_hash)
current_time = Time.current
10.times do |i|
create(:ckb_transaction, tx_status: "pending", block: block, created_at: current_time - i.hours)
create(:ckb_transaction, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block,
created_at: current_time - i.hours)
end

ckb_transactions = CkbTransaction.tx_pending.order(created_at: :asc)
Expand Down Expand Up @@ -162,7 +165,8 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
block = create(:block, :with_block_hash)
current_time = Time.current
10.times do |i|
create(:ckb_transaction, tx_status: "pending", block: block, created_at: current_time - i.hours)
create(:ckb_transaction, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block,
created_at: current_time - i.hours)
end

ckb_transactions = CkbTransaction.tx_pending.order(created_at: :desc)
Expand Down Expand Up @@ -190,7 +194,8 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
test "should sorted by transaction_fee asc when sort param is fee" do
block = create(:block, :with_block_hash)
10.times do |i|
create(:ckb_transaction, tx_status: "pending", block: block, transaction_fee: i)
create(:ckb_transaction, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block,
transaction_fee: i)
end

ckb_transactions = CkbTransaction.tx_pending.order(transaction_fee: :asc)
Expand Down Expand Up @@ -218,7 +223,8 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
test "should sorted by capacity_involved asc when sort param is capacity" do
block = create(:block, :with_block_hash)
10.times do |i|
create(:ckb_transaction, tx_status: "pending", block: block, capacity_involved: i)
create(:ckb_transaction, :with_multiple_inputs_and_outputs, tx_status: "pending", block: block,
capacity_involved: i)
end

ckb_transactions = CkbTransaction.tx_pending.order(capacity_involved: :asc)
Expand All @@ -244,7 +250,7 @@ class PendingTransactionsControllerTest < ActionDispatch::IntegrationTest
end

test "should get success code when call count" do
create_list(:ckb_transaction, 10, tx_status: "pending")
create_list(:ckb_transaction, 10, :with_multiple_inputs_and_outputs, tx_status: "pending")
get count_api_v2_pending_transactions_url

assert_equal 10, json["data"]
Expand Down

0 comments on commit 553df75

Please sign in to comment.