Skip to content

Commit

Permalink
Add ipfs_endpoints specs
Browse files Browse the repository at this point in the history
  • Loading branch information
18bitmood committed Sep 23, 2021
1 parent 24d6eec commit 2f5721f
Show file tree
Hide file tree
Showing 2 changed files with 77 additions and 1 deletion.
76 changes: 76 additions & 0 deletions spec/endpoints/ipfs_endpoints_spec.rb
@@ -0,0 +1,76 @@
# frozen_string_literal: true

require_relative '../../lib/blockfrost-ruby'
require_relative '../../lib/blockfrostruby/constants'
require_relative '../../lib/blockfrostruby/endpoints/ipfs/ipfs_endpoints'

RSpec.describe IPFSEndpoints do
let(:blockfrost_ipfs) { Blockfrostruby::IPFS.new(ENV['BF_IPFS_PROJECT_ID']) }
let(:blockfrost_ipfs_invalid) { Blockfrostruby::IPFS.new('invalid project_id') }

let(:valid_hash) { 'f6780212de5df00d10d929d0ca33dc2ff60cc57f38bd2b3cb3b2dea36f0c20b6' }
let(:invalid_hash) { 'invalid_number' }

context 'IPFS object' do
context 'with valid project_id' do
context 'when calls get_localstorage_pinned_objects_list method' do
context 'without params' do
it 'returns status 200' do
response = blockfrost_ipfs.get_localstorage_pinned_objects_list
expect(response[:status]).to eq(200)
end
end
context 'with params { count: 2 }' do
it 'returns status 200' do
response = blockfrost_ipfs.get_localstorage_pinned_objects_list({ count: 2 })
expect(response[:status]).to eq(200)
end
end
end

# ORDER MATTERS
# RUN ONLY WHOLE CONTEXT

context 'when calls add, pin, get and remove object step-by-step' do
ipfs_path = ''
context 'when calls add_a_file method' do
it 'returns status 200' do
response = blockfrost_ipfs.add_a_file('./README.md')
expect(response[:status]).to eq(200)
ipfs_path = response[:body][:ipfs_hash]
end
end
context 'when calls pin_an_object method' do
it 'returns status 200' do
response = blockfrost_ipfs.pin_an_object(ipfs_path)
expect(response[:status]).to eq(200)
end
end
context 'when calls get_localstorage_pinned_object method' do
it 'returns status 200 and response body ipfs hash is eq path from add_a_file' do
sleep 3 # To make sure that pin_object method finished work
response = blockfrost_ipfs.get_localstorage_pinned_object(ipfs_path)
expect(response[:status]).to eq(200)
expect(response[:body][:ipfs_hash]).to eq(ipfs_path)
end
end
context 'when calls remove pinned_object method' do
it 'returns status 200 and response body ipfs hash is eq path from add_a_file' do
response = blockfrost_ipfs.remove_pinned_object(ipfs_path)
expect(response[:status]).to eq(200)
expect(response[:body][:ipfs_hash]).to eq(ipfs_path)
end
end
context 'when calls get_localstorage_pinned_objects_list method' do
it 'returns status 200 and response body doesn\'t include hash from add a file' do
sleep 1 # To make sure that remove_pinned_object method finished work
response = blockfrost_ipfs.get_localstorage_pinned_objects_list
expect(response[:status]).to eq(200)
pinned_hashes = response[:body].map { |el| el[:ipfs_hash] }
expect(pinned_hashes).not_to include(ipfs_path)
end
end
end
end
end
end
2 changes: 1 addition & 1 deletion spec/endpoints/transactions_endpoints_spec.rb
Expand Up @@ -2,7 +2,7 @@

require_relative '../../lib/blockfrost-ruby'
require_relative '../../lib/blockfrostruby/constants'
require_relative '../../lib/blockfrostruby/endpoints/cardano/pools_endpoints'
require_relative '../../lib/blockfrostruby/endpoints/cardano/transactions_endpoints'

RSpec.describe TransactionsEndpoints do
let(:blockfrost_mainnet) { Blockfrostruby::CardanoMainNet.new(ENV['BF_MAINNET_PROJECT_ID']) }
Expand Down

0 comments on commit 2f5721f

Please sign in to comment.