Skip to content

Commit

Permalink
Merge pull request #21 from lacepool/fix_tests
Browse files Browse the repository at this point in the history
Fix test suite
  • Loading branch information
robinboening authored Jan 5, 2024
2 parents debe8a5 + 38c2589 commit d39c7f3
Show file tree
Hide file tree
Showing 10 changed files with 54 additions and 64 deletions.
2 changes: 1 addition & 1 deletion .env.example
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
BF_IPFS_PROJECT_ID=
BF_MAINNET_PROJECT_ID=
BF_TESTNET_PROJECT_ID=
BF_TESTNET_PROJECT_ID=
2 changes: 1 addition & 1 deletion lib/blockfrostruby/endpoints/cardano/health_endpoints.rb
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ def get_root
#
# @return [Hash] formatted result with status and body keys.
def get_health
Request.get_response("#{@url}/health", @project_id)
Request.get_response("#{@url}/health")
end

# Calls get request on (@url)/health/clock.
Expand Down
2 changes: 1 addition & 1 deletion lib/blockfrostruby/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@ class << self
# @param project_id [String] the project_id to pass to url in headers.
# @param params [Hash] params to add to request, allowed :order, :page, :count, :from, :to.
# @return [Hash] formatted result with status and body keys.
def get_response(url, project_id, params = {})
def get_response(url, project_id = nil, params = {})
params[:from_page] ? get_pages_multi(url, project_id, params) : get_response_from_url(url, project_id, params)
end

Expand Down
36 changes: 18 additions & 18 deletions spec/endpoints/assets_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -45,9 +45,9 @@
end

context 'with invalid asset' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_specific_asset(invalid_asset)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -72,16 +72,16 @@

context 'with invalid asset' do
context 'without params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_asset_history(invalid_asset)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
context 'with params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_asset_history(invalid_asset, { count: 7, page: 3 })
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -107,16 +107,16 @@

context 'with invalid asset' do
context 'without params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_asset_transactions(invalid_asset)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
context 'with params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_asset_transactions(invalid_asset, { count: 7, page: 3 })
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -142,16 +142,16 @@

context 'with invalid asset' do
context 'without params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_asset_addresses(invalid_asset)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
context 'with params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_asset_addresses(invalid_asset, { count: 7, page: 3 })
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -177,16 +177,16 @@

context 'with invalid policy_id' do
context 'without params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_assets_of_policy(invalid_policy_id)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
context 'with params' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_assets_of_policy(invalid_policy_id, { count: 7, page: 3 })
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand Down
26 changes: 12 additions & 14 deletions spec/endpoints/blocks_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -49,9 +49,9 @@
end
end
context 'with invalid hash_or_number' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_block(invalid_hash_or_number)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -65,10 +65,9 @@
end
end
context 'with invalid slot number' do
it 'returns status 404, response body includes error' do
skip 'Returns 500 instead of 404'
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_block_in_slot(invalid_slot_number)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -82,10 +81,9 @@
end
end
context 'with invalid slot and epoch number' do
it 'returns status 404, response body includes error' do
skip 'Returns 500 instead of 404'
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_block_in_slot_in_epoch(invalid_slot_number, invalid_epoch_number)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -109,9 +107,9 @@
end
end
context 'with invalid hash_or_number' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_list_of_next_blocks(invalid_hash_or_number)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -135,9 +133,9 @@
end
end
context 'with invalid hash_or_number' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_list_of_previous_blocks(invalid_hash_or_number)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand All @@ -161,9 +159,9 @@
end
end
context 'with invalid hash_or_number' do
it 'returns status 404, response body includes error' do
it 'returns status 400, response body includes error' do
response = blockfrost_mainnet.get_block_transactions(invalid_hash_or_number)
expect(response[:status]).to eq(404)
expect(response[:status]).to eq(400)
expect(response[:body]).to include(:error)
end
end
Expand Down
18 changes: 9 additions & 9 deletions spec/endpoints/health_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
RSpec.describe HealthEndpoints do
let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) }
let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') }

context 'CardanoMainNet object' do
context 'with valid project_id' do
Expand Down Expand Up @@ -39,16 +39,16 @@

context 'with invalid project_id' do
context 'when calls get_health method' do
it 'returns 403 status and body includes error' do
it 'return status 200 and is_healthy => true' do
response = blockfrost_mainnet_invalid.get_health
expect(response[:status]).to eq(403)
expect(response[:body]).to include(:error)
expect(response[:status]).to eq(200)
expect(response[:body]).to eq({ is_healthy: true })
end
end
end
end

context 'CardanoTestNet object' do
context 'CardanoPreview object' do
context 'with valid project_id' do
context 'when calls get_health method' do
it 'return status 200 and is_healthy => true' do
Expand Down Expand Up @@ -77,10 +77,10 @@

context 'with invalid project_id' do
context 'when calls get_health method' do
it 'returns 403 status and body includes error' do
it 'return status 200 and is_healthy => true' do
response = blockfrost_testnet_invalid.get_health
expect(response[:status]).to eq(403)
expect(response[:body]).to include(:error)
expect(response[:status]).to eq(200)
expect(response[:body]).to eq({ is_healthy: true })
end
end
end
Expand Down
6 changes: 3 additions & 3 deletions spec/endpoints/ledger_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
RSpec.describe LedgerEndpoints do
let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) }
let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') }

context 'CardanoMainNet object' do
context 'with valid project_id' do
Expand All @@ -32,7 +32,7 @@
end
end

context 'CardanoTestNet object' do
context 'CardanoPreview object' do
context 'with valid project_id' do
context 'when calls get_genesis method' do
it 'return status 200 and response body includes active_slots_coefficient' do
Expand Down
6 changes: 3 additions & 3 deletions spec/endpoints/metrics_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
RSpec.describe MetricsEndpoints do
let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) }
let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') }

context 'CardanoMainNet object' do
context 'with valid project_id' do
Expand Down Expand Up @@ -38,7 +38,7 @@
end
end

context 'CardanoTestNet object' do
context 'CardanoPreview object' do
context 'with valid project_id' do
context 'when calls get_metrics method' do
it 'return status 200' do
Expand Down
4 changes: 2 additions & 2 deletions spec/endpoints/network_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
RSpec.describe NetworkEndpoints do
let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) }
let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoTestNet.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoTestNet.new('invalid project_id') }
let(:blockfrost_testnet) { Blockfrostruby::CardanoPreview.new(ENV['BF_TESTNET_PROJECT_ID']) }
let(:blockfrost_testnet_invalid) { Blockfrostruby::CardanoPreview.new('invalid project_id') }

context 'CardanoMainNet object' do
context 'with valid project_id' do
Expand Down
16 changes: 4 additions & 12 deletions spec/endpoints/nutlink_endpoints_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -6,19 +6,17 @@

RSpec.describe NutlinkEndpoints do
let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) }
let(:blockfrost_mainnet_invalid) { Blockfrostruby::CardanoMainNet.new('invalid project_id') }

let(:valid_address) { 'addr1qxqs59lphg8g6qndelq8xwqn60ag3aeyfcp33c2kdp46a09re5df3pzwwmyq946axfcejy5n4x0y99wqpgtp2gd0k09qsgy6pz' }
let(:invalid_address) { 'invalid_number' }
let(:valid_ticker) { 'valid_ticker' }
let(:invalid_ticker) { 'invalid_number' }
let(:valid_address) { 'addr1q85yx2w7ragn5sx6umgmtjpc3865s9sg59sz4rrh6f90kgwfwlzu3w8ttacqg89mkdgwshwnplj5c5n9f8dhp0h55q2q7qm63t' }
let(:invalid_address) { 'invalid' }
let(:valid_ticker) { 'ADABTC' }
let(:invalid_ticker) { 'invalid' }

context 'CardanoMainNet object' do
context 'with valid project_id' do
context 'when calls get_address_metadata_list method' do
context 'with valid address' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_address_metadata_list(valid_address)
expect(response[:status]).to eq(200)
end
Expand All @@ -36,14 +34,12 @@
context 'with valid address' do
context 'without params' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_address_metadata_tickers_list(valid_address)
expect(response[:status]).to eq(200)
end
end
context 'with params { count: 5 }' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_address_metadata_tickers_list(valid_address, { count: 5 })
expect(response[:status]).to eq(200)
end
Expand All @@ -62,14 +58,12 @@
context 'with valid address and ticker' do
context 'without params' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_ticker_records_by_address(valid_address, valid_ticker)
expect(response[:status]).to eq(200)
end
end
context 'with params { count: 5 }' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_ticker_records_by_address(valid_address, valid_ticker, { count: 5 })
expect(response[:status]).to eq(200)
end
Expand All @@ -88,14 +82,12 @@
context 'with valid address and ticker' do
context 'without params' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_ticker_records(valid_ticker)
expect(response[:status]).to eq(200)
end
end
context 'with params { count: 5 }' do
it 'returns status 200' do
skip 'Return 404 now'
response = blockfrost_mainnet.get_ticker_records(valid_ticker, { count: 5 })
expect(response[:status]).to eq(200)
end
Expand Down

0 comments on commit d39c7f3

Please sign in to comment.