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

Fix test suite #21

Merged
merged 4 commits into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from 3 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
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 = {})
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

making project_id optional as /health doesn't need to provide the secret

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