Sha256: ec2f8f3ca2124956b9d315eadcc5b07b1999e2ceeaa3923115fd860a1653fbd5

Contents?: true

Size: 1.97 KB

Versions: 6

Compression:

Stored size: 1.97 KB

Contents

# frozen_string_literal: true

require_relative './request_examples'

describe CoinsPaid::API, '.take_address' do
  let(:endpoint) { 'https://app.coinspaid.com/api/v2/addresses/take' }

  let(:foreign_id) { 'user-id:2048' }
  let(:currency) { 'BTC' }

  let(:request_data) do
    { foreign_id: foreign_id, currency: currency, convert_to: api_convert_to }.compact
  end
  let(:request_body) { request_data.to_json }

  include_context 'CoinsPaid API request'

  let(:response_data) do
    {
      'data' => {
        'id' => 1,
        'currency' => 'BTC',
        'convert_to' => api_convert_to,
        'address' => '12983h13ro1hrt24it432t',
        'tag' => 123,
        'foreign_id' => 'user-id:2048'
      }.compact
    }
  end

  let(:args) do
    { foreign_id: 'user-id:2048', currency: 'BTC', convert_to: args_convert_to }.compact
  end
  subject(:take_address) { described_class.take_address(args) }

  shared_examples 'successful request' do
    it 'returns valid response' do
      stub_request(:post, endpoint)
        .with(body: request_body, headers: request_signature_headers)
        .to_return(status: 201, body: response_data.to_json)

      expected_address_attributes = {
        external_id: 1,
        address: '12983h13ro1hrt24it432t',
        tag: '123'
      }
      expect(take_address).to be_struct_with_params(
        CoinsPaid::API::TakeAddress::Response, expected_address_attributes
      )
    end
  end

  context 'with explicit convert_to not matching address currency' do
    let(:args_convert_to) { 'EUR' }
    let(:api_convert_to) { 'EUR' }
    it_behaves_like 'successful request'
    it_behaves_like 'CoinsPaid API error handling'
  end

  context 'with explicit convert_to matching address currency' do
    let(:args_convert_to) { 'BTC' }
    let(:api_convert_to) { nil }
    it_behaves_like 'successful request'
  end

  context 'with nil convert_to' do
    let(:args_convert_to) { nil }
    let(:api_convert_to) { nil }
    it_behaves_like 'successful request'
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
coins_paid_api-2.2.0 spec/take_address_spec.rb
coins_paid_api-2.1.0 spec/take_address_spec.rb
coins_paid_api-2.0.0 spec/take_address_spec.rb
coins_paid_api-1.3.0 spec/take_address_spec.rb
coins_paid_api-1.2.0 spec/take_address_spec.rb
coins_paid_api-1.1.0 spec/take_address_spec.rb