Sha256: 44ee420242a2235c988b2f83d9c7b02c13bca55e0f064251b94f18c93f17d068

Contents?: true

Size: 1.75 KB

Versions: 2

Compression:

Stored size: 1.75 KB

Contents

# frozen_string_literal: true

require_relative './request_examples'

RSpec.shared_examples 'CoinsPaid API withdrawal' do
  let(:endpoint) { 'https://app.coinspaid.com/api/v2/withdrawal/crypto' }

  include_context 'CoinsPaid API request'

  let(:response_data) do
    {
      'data' => {
        'id' => 1,
        'foreign_id' => 'user-id:2048',
        'type' => 'withdrawal',
        'status' => 'processing',
        'amount' => '10.00000000',
        'sender_amount' => '10.00000000',
        'sender_currency' => 'EUR',
        'receiver_amount' => '0.00100000',
        'receiver_currency' => 'BTC'
      }
    }
  end
  let(:expected_withdrawal_attributes) do
    {
      external_id: 1,
      receiver_amount: 0.001
    }
  end
  subject(:withdraw) { described_class.withdraw(request_data) }

  context 'when response is successful' do
    before do
      stub_request(:post, endpoint)
        .with(body: request_data, headers: request_signature_headers)
        .to_return(status: 201, body: response_data.to_json)
    end

    it 'returns valid response' do
      expect(withdraw).to be_struct_with_params(CoinsPaid::API::Withdrawal::Response, expected_withdrawal_attributes)
    end
  end
end

describe CoinsPaid::API, '.withdraw' do
  let(:base_request_data) do
    {
      foreign_id: 'user-id:2048',
      amount: '0.01',
      currency: 'EUR',
      convert_to: 'BTC',
      address: 'abc123'
    }
  end
  let(:request_body) { request_data.to_json }

  context 'request includes tag parameter' do
    let(:request_data) { base_request_data.merge(tag: 'thetag') }
    it_behaves_like 'CoinsPaid API withdrawal'
  end

  context 'request does not include tag parameter' do
    let(:request_data) { base_request_data }
    it_behaves_like 'CoinsPaid API withdrawal'
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
coins_paid_api-1.2.0 spec/withdrawal_spec.rb
coins_paid_api-1.1.0 spec/withdrawal_spec.rb