Skip to content

Commit

Permalink
Add download API test cases
Browse files Browse the repository at this point in the history
  • Loading branch information
tungleduyxyz committed Dec 26, 2024
1 parent 1548640 commit 41ae94e
Show file tree
Hide file tree
Showing 4 changed files with 56 additions and 0 deletions.
16 changes: 16 additions & 0 deletions test/functional/kaui/accounts_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -294,6 +294,22 @@ class AccountsControllerTest < Kaui::FunctionalTestHelper
assert_equal 'text/plain', @response.header['Content-Type']
end

test 'should download accounts data' do
start_date = Date.today.strftime('%Y-%m-%d')
end_date = Date.today.strftime('%Y-%m-%d')
columns = %w[account_id name email bcd cba]
account = create_account(@tenant)

get :download, params: { startDate: start_date, endDate: end_date, allFieldsChecked: 'false', columnsString: columns.join(',') }
assert_response :success
assert_equal 'text/csv', @response.header['Content-Type']
assert_includes @response.header['Content-Disposition'], "filename=\"accounts-#{Date.today}.csv\""
assert_includes @response.body, account.account_id

csv = CSV.parse(@response.body, headers: true)
assert_equal %w[account_id name email bill_cycle_day_local account_cba], csv.headers
end

private

def redirected_account_id
Expand Down
9 changes: 9 additions & 0 deletions test/functional/kaui/audit_logs_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,15 @@ class AuditLogsControllerTest < Kaui::FunctionalTestHelper
end
end

test 'should download audit logs data' do
get :download, params: { account_id: @account.account_id }
assert_response :success
assert_equal 'text/csv', @response.header['Content-Type']
assert_includes @response.header['Content-Disposition'], "filename=\"audit-logs-#{Date.today}.csv\""
assert_includes @response.body, @payment.payment_id
assert_includes @response.body, @account.account_id
end

private

def add_a_note(account)
Expand Down
16 changes: 16 additions & 0 deletions test/functional/kaui/invoices_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -92,5 +92,21 @@ class InvoicesControllerTest < Kaui::FunctionalTestHelper
assert_redirected_to account_invoice_path(@account.account_id, invoice_id)
assert_equal 'Invoice successfully committed', flash[:notice]
end

test 'should download invoices data' do
start_date = Date.today.strftime('%Y-%m-%d')
end_date = Date.today.strftime('%Y-%m-%d')
columns = %w[invoice_id currency status]
invoice = create_charge(@account, @tenant)

get :download, params: { startDate: start_date, endDate: end_date, allFieldsChecked: 'false', columnsString: columns.join(',') }
assert_response :success
assert_equal 'text/csv', @response.header['Content-Type']
assert_includes @response.header['Content-Disposition'], "filename=\"invoices-#{Date.today}.csv\""
assert_includes @response.body, invoice.invoice_id

csv = CSV.parse(@response.body, headers: true)
assert_equal columns, csv.headers
end
end
end
15 changes: 15 additions & 0 deletions test/functional/kaui/payments_controller_test.rb
Original file line number Diff line number Diff line change
Expand Up @@ -60,5 +60,20 @@ class PaymentsControllerTest < Kaui::FunctionalTestHelper
expected_response_path = "/accounts/#{@payment.account_id}/payments/#{@payment.payment_id}"
assert response_path.include?(expected_response_path), "#{response_path} is expected to contain #{expected_response_path}"
end

test 'should download payments data' do
start_date = Date.today.strftime('%Y-%m-%d')
end_date = Date.today.strftime('%Y-%m-%d')
columns = %w[payment_id auth currency capture purchase refund credit]

get :download, params: { startDate: start_date, endDate: end_date, allFieldsChecked: 'false', columnsString: columns.join(',') }
assert_response :success
assert_equal 'text/csv', @response.header['Content-Type']
assert_includes @response.header['Content-Disposition'], "filename=\"payments-#{Date.today}.csv\""
assert_includes @response.body, @payment.payment_id

csv = CSV.parse(@response.body, headers: true)
assert_equal %w[payment_id auth_amount currency captured_amount purchased_amount refunded_amount credited_amount], csv.headers
end
end
end

0 comments on commit 41ae94e

Please sign in to comment.