Initial commit
This commit is contained in:
15
spec/api/v2/management/entities/balance_spec.rb
Normal file
15
spec/api/v2/management/entities/balance_spec.rb
Normal file
@@ -0,0 +1,15 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe API::V2::Management::Entities::Balance do
|
||||
let(:member) { create(:member, :barong) }
|
||||
let(:record) { member.get_account(:usd) }
|
||||
before { record.update!(balance: 1000.85, locked: 330.55) }
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Balance.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.uid).to eq record.member.uid
|
||||
expect(subject.balance).to eq '1000.85'
|
||||
expect(subject.locked).to eq '330.55'
|
||||
end
|
||||
end
|
||||
42
spec/api/v2/management/entities/deposit_spec.rb
Normal file
42
spec/api/v2/management/entities/deposit_spec.rb
Normal file
@@ -0,0 +1,42 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe API::V2::Management::Entities::Deposit do
|
||||
context 'fiat' do
|
||||
let(:record) { create(:deposit_usd, member: create(:member, :barong)) }
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Deposit.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.tid).to eq record.tid
|
||||
expect(subject.currency).to eq 'usd'
|
||||
expect(subject.uid).to eq record.member.uid
|
||||
expect(subject.type).to eq 'fiat'
|
||||
expect(subject.amount).to eq record.amount.to_s
|
||||
expect(subject.state).to eq record.aasm_state
|
||||
expect(subject.created_at).to eq record.created_at.iso8601
|
||||
expect(subject.completed_at).to eq record.completed_at&.iso8601
|
||||
expect(subject.respond_to?(:blockchain_txid)).to be_falsey
|
||||
expect(subject.respond_to?(:confirmations)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context 'coin' do
|
||||
let(:record) { create(:deposit_btc, member: create(:member, :barong)) }
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Deposit.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.tid).to eq record.tid
|
||||
expect(subject.currency).to eq 'btc'
|
||||
expect(subject.uid).to eq record.member.uid
|
||||
expect(subject.type).to eq 'coin'
|
||||
expect(subject.amount).to eq record.amount.to_s
|
||||
expect(subject.state).to eq record.aasm_state
|
||||
expect(subject.created_at).to eq record.created_at.iso8601
|
||||
expect(subject.completed_at).to eq record.completed_at&.iso8601
|
||||
expect(subject.blockchain_txid).to eq record.txid
|
||||
expect(subject.blockchain_confirmations).to eq record.confirmations
|
||||
end
|
||||
end
|
||||
end
|
||||
64
spec/api/v2/management/entities/operation_spec.rb
Normal file
64
spec/api/v2/management/entities/operation_spec.rb
Normal file
@@ -0,0 +1,64 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe API::V2::Management::Entities::Operation do
|
||||
Operations::Account::PLATFORM_TYPES.each do |op_type|
|
||||
context op_type do
|
||||
let(:record) { create(op_type) }
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Operation.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.code).to eq record.code
|
||||
expect(subject.currency).to eq record.currency_id
|
||||
expect(subject.created_at).to eq record.created_at.iso8601
|
||||
end
|
||||
|
||||
context 'credit' do
|
||||
it do
|
||||
expect(subject.credit).to eq record.credit
|
||||
expect(subject.respond_to?(:debit)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context 'debit' do
|
||||
let(:record) { create(:asset, :debit) }
|
||||
it do
|
||||
expect(subject.debit).to eq record.debit
|
||||
expect(subject.respond_to?(:credit)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
Operations::Account::MEMBER_TYPES.each do |op_type|
|
||||
context op_type do
|
||||
let(:record) { create(op_type, :with_member) }
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Operation.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.code).to eq record.code
|
||||
expect(subject.currency).to eq record.currency_id
|
||||
expect(subject.uid).to eq record.member.uid
|
||||
expect(subject.created_at).to eq record.created_at.iso8601
|
||||
end
|
||||
|
||||
context 'credit' do
|
||||
it do
|
||||
expect(subject.credit).to eq record.credit
|
||||
expect(subject.respond_to?(:debit)).to be_falsey
|
||||
end
|
||||
end
|
||||
|
||||
context 'debit' do
|
||||
let(:record) { create(:asset, :debit) }
|
||||
|
||||
it do
|
||||
expect(subject.debit).to eq record.debit
|
||||
expect(subject.respond_to?(:credit)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
43
spec/api/v2/management/entities/trade_spec.rb
Normal file
43
spec/api/v2/management/entities/trade_spec.rb
Normal file
@@ -0,0 +1,43 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe API::V2::Management::Entities::Trade do
|
||||
let(:trade) do
|
||||
create :trade, :btcusd, maker_order: create(:order_ask, :btcusd), taker_order: create(:order_bid, :btcusd)
|
||||
end
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Trade.represent(trade, side: 'sell').serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.id).to eq trade.id
|
||||
expect(subject.order_id).to be_nil
|
||||
expect(subject.price).to eq trade.price
|
||||
expect(subject.amount).to eq trade.amount
|
||||
expect(subject.total).to eq trade.total
|
||||
expect(subject.market).to eq trade.market_id
|
||||
expect(subject.side).to eq 'sell'
|
||||
expect(subject.created_at).to eq trade.created_at.iso8601
|
||||
expect(subject.maker_order_id).to eq trade.maker_order_id
|
||||
expect(subject.maker_order_id).to eq trade.maker_order_id
|
||||
expect(subject.maker_member_uid).to eq trade.maker.uid
|
||||
expect(subject.taker_member_uid).to eq trade.taker.uid
|
||||
end
|
||||
|
||||
|
||||
context 'sell order maker' do
|
||||
it { expect(subject.taker_type).to eq 'buy' }
|
||||
end
|
||||
|
||||
context 'buy order maker' do
|
||||
let(:trade) do
|
||||
create :trade, :btcusd, maker_order: create(:order_bid, :btcusd), taker_order: create(:order_ask, :btcusd)
|
||||
end
|
||||
|
||||
it { expect(subject.taker_type).to eq 'sell' }
|
||||
end
|
||||
|
||||
context 'empty side' do
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Trade.represent(trade).serializable_hash }
|
||||
it { expect(subject.respond_to?(:side)).to be_falsey }
|
||||
end
|
||||
end
|
||||
69
spec/api/v2/management/entities/transfer_spec.rb
Normal file
69
spec/api/v2/management/entities/transfer_spec.rb
Normal file
@@ -0,0 +1,69 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe API::V2::Management::Entities::Transfer do
|
||||
let(:record) { create(:transfer) }
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Transfer.represent(record.reload).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.key).to eq record.key
|
||||
expect(subject.category).to eq record.category
|
||||
expect(subject.description).to eq record.description
|
||||
end
|
||||
|
||||
context 'with operations' do
|
||||
let(:record) { create(:transfer_with_operations) }
|
||||
it do
|
||||
::Operations::Account::TYPES.map(&:pluralize).each do |op_t|
|
||||
expect(subject.respond_to?(op_t)).to be_truthy
|
||||
end
|
||||
end
|
||||
|
||||
it do
|
||||
record_assets = API::V2::Management::Entities::Operation
|
||||
.represent(record.reload.assets)
|
||||
expect(subject.assets.to_json).to eq record_assets.to_json
|
||||
end
|
||||
|
||||
it do
|
||||
record_expenses = API::V2::Management::Entities::Operation
|
||||
.represent(record.reload.expenses)
|
||||
expect(subject.expenses.to_json).to eq record_expenses.to_json
|
||||
end
|
||||
|
||||
it do
|
||||
record_liabilities = API::V2::Management::Entities::Operation
|
||||
.represent(record.reload.liabilities)
|
||||
expect(subject.liabilities.to_json).to eq record_liabilities.to_json
|
||||
end
|
||||
|
||||
it do
|
||||
record_revenues = API::V2::Management::Entities::Operation
|
||||
.represent(record.reload.revenues)
|
||||
expect(subject.revenues.to_json).to eq record_revenues.to_json
|
||||
end
|
||||
end
|
||||
|
||||
context 'with single operation type' do
|
||||
let(:record) { create(:transfer, :with_liabilities) }
|
||||
|
||||
it do
|
||||
expect(subject.respond_to?(:liabilities)).to be_truthy
|
||||
end
|
||||
|
||||
it do
|
||||
# TYPES - 'liabilities' = PLATFORM_TYPES
|
||||
::Operations::Account::PLATFORM_TYPES.map(&:pluralize).each do |op_t|
|
||||
expect(subject.respond_to?(op_t.to_sym)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
|
||||
context 'without operations' do
|
||||
it do
|
||||
::Operations::Account::TYPES.map(&:pluralize).each do |op_t|
|
||||
expect(subject.respond_to?(op_t)).to be_falsey
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
48
spec/api/v2/management/entities/withdraw_spec.rb
Normal file
48
spec/api/v2/management/entities/withdraw_spec.rb
Normal file
@@ -0,0 +1,48 @@
|
||||
# encoding: UTF-8
|
||||
# frozen_string_literal: true
|
||||
|
||||
describe API::V2::Management::Entities::Withdraw do
|
||||
context 'fiat' do
|
||||
let(:rid) { Faker::Bank.iban }
|
||||
let(:member) { create(:member, :barong) }
|
||||
let(:record) { create(:usd_withdraw, :with_deposit_liability, member: member, rid: rid) }
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Withdraw.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.tid).to eq record.tid
|
||||
expect(subject.rid).to eq rid
|
||||
expect(subject.currency).to eq 'usd'
|
||||
expect(subject.uid).to eq record.member.uid
|
||||
expect(subject.type).to eq 'fiat'
|
||||
expect(subject.amount).to eq record.amount.to_s
|
||||
expect(subject.note).to eq record.note
|
||||
expect(subject.fee).to eq record.fee.to_s
|
||||
expect(subject.respond_to?(:txid)).to be_falsey
|
||||
expect(subject.state).to eq record.aasm_state
|
||||
expect(subject.created_at).to eq record.created_at.iso8601
|
||||
end
|
||||
end
|
||||
|
||||
context 'coin' do
|
||||
let(:rid) { Faker::Blockchain::Bitcoin.address }
|
||||
let(:member) { create(:member, :barong) }
|
||||
let(:record) { create(:btc_withdraw, :with_deposit_liability, member: member, rid: rid) }
|
||||
|
||||
subject { OpenStruct.new API::V2::Management::Entities::Withdraw.represent(record).serializable_hash }
|
||||
|
||||
it do
|
||||
expect(subject.tid).to eq record.tid
|
||||
expect(subject.rid).to eq rid
|
||||
expect(subject.currency).to eq 'btc'
|
||||
expect(subject.uid).to eq record.member.uid
|
||||
expect(subject.type).to eq 'coin'
|
||||
expect(subject.amount).to eq record.amount.to_s
|
||||
expect(subject.note).to eq record.note
|
||||
expect(subject.fee).to eq record.fee.to_s
|
||||
expect(subject.blockchain_txid).to eq record.txid
|
||||
expect(subject.state).to eq record.aasm_state
|
||||
expect(subject.created_at).to eq record.created_at.iso8601
|
||||
end
|
||||
end
|
||||
end
|
||||
Reference in New Issue
Block a user