Initial commit
This commit is contained in:
commit
4b5f7906d7
33 files changed
+933
No files matched your search
@@ -0,0 +1,54 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::API::Account::Balances do
|
||||
subject { StrikeMe::API::Account.new.balances }
|
||||
context 'good response' do
|
||||
let(:server_response) do
|
||||
[
|
||||
{
|
||||
'currency' => 'BTC',
|
||||
'current' => '0.003169',
|
||||
'pending' => '0',
|
||||
'outgoing' => '0',
|
||||
'reserved' => '0',
|
||||
'available' => '0.003169',
|
||||
'total' => '0.00316976'
|
||||
},
|
||||
{
|
||||
'currency' => 'USDT',
|
||||
'current' => '50.73',
|
||||
'pending' => '0.00',
|
||||
'outgoing' => '0.00',
|
||||
'reserved' => '0.00',
|
||||
'available' => '50.73',
|
||||
'total' => '50.73'
|
||||
}
|
||||
]
|
||||
end
|
||||
before { allow_any_instance_of(StrikeMe::API::Client).to receive(:get).and_return double(success?: true, body: server_response) }
|
||||
|
||||
it '#to_a returns a simple object representation, where number string inputs are real numbers' do
|
||||
expected = [
|
||||
{
|
||||
'currency' => 'BTC',
|
||||
'current' => 0.003169,
|
||||
'pending' => 0.0,
|
||||
'outgoing' => 0.0,
|
||||
'reserved' => 0.0,
|
||||
'available' => 0.003169,
|
||||
'total' => 0.00316976
|
||||
},
|
||||
{
|
||||
'currency' => 'USDT',
|
||||
'current' => 50.73,
|
||||
'pending' => 0.0,
|
||||
'outgoing' => 0.0,
|
||||
'reserved' => 0.0,
|
||||
'available' => 50.73,
|
||||
'total' => 50.73
|
||||
}
|
||||
]
|
||||
expect(subject.to_a).to eq expected
|
||||
end
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,19 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::API::Account::Profile do
|
||||
context 'good response' do
|
||||
let(:server_response) do
|
||||
{
|
||||
'id' => '02ad532c-2bd0-4b4b-8c06-a2b2dd3f2b0c',
|
||||
'handle' => 'strikerrr3',
|
||||
'canReceive' => true,
|
||||
'currencies' => [
|
||||
{ 'currency' => 'USDT', 'isDefaultCurrency' => false, 'isAvailable' => true, 'isInvoiceable' => true },
|
||||
{ 'currency' => 'BTC', 'isDefaultCurrency' => true, 'isAvailable' => true, 'isInvoiceable' => true }
|
||||
]
|
||||
}
|
||||
end
|
||||
before { allow_any_instance_of(StrikeMe::API::Client).to receive(:get).and_return double(success?: true, body: server_response) }
|
||||
end
|
||||
subject { described_class.new }
|
||||
end
|
||||
@@ -0,0 +1,34 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::API::Account do
|
||||
subject { described_class.new }
|
||||
|
||||
describe 'profile' do
|
||||
subject { described_class.new.profile }
|
||||
|
||||
it 'works with STRIKE_ACCOUNT_ID' do
|
||||
allow(ENV).to receive(:[])
|
||||
expect(ENV).to receive(:[]).with('STRIKE_ACCOUNT_ID').and_return 'abc'
|
||||
stub_request(:get, %r{https://api.strike.me/v1/accounts/abc/profile})
|
||||
.to_return(status: 200, body: '{"id":"abc44"}')
|
||||
expect(subject.id).to eq 'abc44'
|
||||
end
|
||||
|
||||
it 'works with STRIKE_ACCOUNT_HANDLE without account id' do
|
||||
allow(ENV).to receive(:[])
|
||||
allow(ENV).to receive(:fetch)
|
||||
expect(ENV).to receive(:fetch).with('STRIKE_ACCOUNT_HANDLE').and_return 'abcd'
|
||||
stub_request(:get, %r{https://api.strike.me/v1/accounts/handles/abcd/profile})
|
||||
.to_return(status: 200, body: '{"id":"abc44"}')
|
||||
expect(subject.id).to eq 'abc44'
|
||||
end
|
||||
end
|
||||
|
||||
describe 'balances' do
|
||||
subject { described_class.new.balances }
|
||||
|
||||
before { stub_request(:get, 'https://api.strike.me/v1/balances').to_return(status: 200, body: []) }
|
||||
|
||||
it { is_expected.to be_an_instance_of StrikeMe::API::Account::Balances }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,9 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::API::Client do
|
||||
subject { described_class.new }
|
||||
|
||||
it 'does things', pending: 'await more structure' do
|
||||
expect(2).to eq 3
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,20 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::API::InvoiceResponse do
|
||||
let(:valid_attributes) { { ok: true, checking_id: 'abc1', payment_request: 'abc2', error_message: 'abc3' } }
|
||||
let(:invalid_attributes) { valid_attributes.merge(ok: false) }
|
||||
|
||||
context 'valid response' do
|
||||
subject { described_class.new(valid_attributes) }
|
||||
|
||||
it { is_expected.to be_a StrikeMe::API::BaseModel }
|
||||
it { is_expected.to be_valid }
|
||||
it { is_expected.to have_attributes checking_id: 'abc1', payment_request: 'abc2', error_message: 'abc3' }
|
||||
end
|
||||
|
||||
context 'invalid response' do
|
||||
subject { described_class.new(invalid_attributes) }
|
||||
|
||||
it { is_expected.to_not be_valid }
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,7 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::API do
|
||||
it 'has a version number' do
|
||||
expect(StrikeMe::API::VERSION).not_to be nil
|
||||
end
|
||||
end
|
||||
@@ -0,0 +1,108 @@
|
||||
# frozen_string_literal: true
|
||||
|
||||
RSpec.describe StrikeMe::BTC do
|
||||
context 'create from integer' do
|
||||
it 'creates using #btc' do
|
||||
btc = 314.btc
|
||||
|
||||
expect(btc).to be_a described_class
|
||||
expect(btc.sats).to eq 314 * 100_000_000
|
||||
end
|
||||
|
||||
it 'creates using #sats' do
|
||||
btc = 314.sats
|
||||
|
||||
expect(btc).to be_a described_class
|
||||
expect(btc.sats).to eq 314
|
||||
end
|
||||
end
|
||||
|
||||
context 'create from float' do
|
||||
it 'creates using #btc' do
|
||||
btc = 314.85.btc
|
||||
|
||||
expect(btc).to be_a described_class
|
||||
expect(btc.sats).to eq 31_485_000_000
|
||||
end
|
||||
|
||||
it 'creates using #sats' do
|
||||
btc = 314.85.sats
|
||||
|
||||
expect(btc).to be_a described_class
|
||||
expect(btc.sats).to eq 315
|
||||
end
|
||||
end
|
||||
|
||||
it 'properly formats to string' do
|
||||
expect(described_class.new(234_522).to_s).to eq '0.00234522'
|
||||
end
|
||||
|
||||
it 'formats properly in json structures' do
|
||||
btc = described_class.new(234_522)
|
||||
expect({ amount: btc }.to_json).to eq '{"amount":"0.00234522"}'
|
||||
end
|
||||
|
||||
context 'arithmetic' do
|
||||
it 'supports multiplication with numbers' do
|
||||
btc1 = described_class.new(234_529)
|
||||
btc2 = btc1 * 3
|
||||
btc3 = btc2 * 2.9
|
||||
|
||||
expect(btc2).to be_a described_class
|
||||
expect(btc3).to be_a described_class
|
||||
|
||||
expect(btc2).not_to eq btc1
|
||||
expect(btc2).not_to eq btc3
|
||||
|
||||
expect(btc1.sats).to eq 234_529
|
||||
expect(btc1).to eq 234_529
|
||||
expect(btc2).to eq 703_587
|
||||
expect(btc3).to eq 2_040_402
|
||||
end
|
||||
|
||||
it 'supports division with numbers' do
|
||||
btc1 = described_class.new(34_529)
|
||||
btc2 = btc1 / 3
|
||||
btc3 = btc2 / 2.9
|
||||
|
||||
expect(btc2).to be_a described_class
|
||||
expect(btc3).to be_a described_class
|
||||
|
||||
expect(btc2).not_to eq btc1
|
||||
expect(btc2).not_to eq btc3
|
||||
|
||||
expect(btc1.sats).to eq 34_529
|
||||
expect(btc1).to eq 34_529
|
||||
expect(btc2).to eq 11_509
|
||||
expect(btc3).to eq 3_968
|
||||
end
|
||||
|
||||
it 'supports addition with other BTC objects' do
|
||||
btc1 = described_class.new(34_529)
|
||||
btc2 = described_class.new(2_556)
|
||||
btc3 = btc1 + btc2
|
||||
|
||||
expect { btc1 + 23 }.to raise_error StrikeMe::BTC::Error
|
||||
|
||||
expect(btc3).to be_a described_class
|
||||
expect(btc3).to eq 37_085
|
||||
end
|
||||
|
||||
it 'supports subtraction with other BTC objects' do
|
||||
btc1 = described_class.new(34_529)
|
||||
btc2 = described_class.new(2_556)
|
||||
btc3 = btc1 - btc2
|
||||
|
||||
expect { btc1 - 23 }.to raise_error StrikeMe::BTC::Error
|
||||
|
||||
expect(btc3).to be_a described_class
|
||||
expect(btc3).to eq 31_973
|
||||
end
|
||||
end
|
||||
|
||||
it 'is consistent for small values' do
|
||||
string = 3.sats.to_s
|
||||
expect(string).to eq '0.00000003'
|
||||
expect(string.to_f.btc.sats).to eq 3
|
||||
end
|
||||
end
|
||||
Reference in new issue
Block a user