Sha256: 6f0cd4dc9b6731dd3b37497357730ff4bfca1746f2cd1b7c4644850dbcf713c0

Contents?: true

Size: 1.65 KB

Versions: 11

Compression:

Stored size: 1.65 KB

Contents

require 'test_helper'

class RemoteUpdateCreditCardTest < Test::Unit::TestCase

  def setup
    @environment = Spreedly::Environment.new(remote_test_environment_key, remote_test_access_secret)
  end

  def test_invalid_login
    assert_invalid_login do |environment|
      environment.update_credit_card("card_token", card_deets)
    end
  end

  def test_non_existent_card_token
    assert_raise_with_message(Spreedly::NotFoundError, "Unable to find the specified payment method.") do
      @environment.update_credit_card('unknown_card', card_deets)
    end
  end

  def test_failed_with_validation_errors
    card = create_card_on(@environment)
    error = assert_raises(Spreedly::TransactionCreationError) do
      @environment.update_credit_card(card.token, card_deets(last_name: '', first_name: ' '))
    end

    expected_errors = [
      { attribute: "first_name", key: "errors.blank", message: "First name can't be blank" },
      { attribute: "last_name", key: "errors.blank", message: "Last name can't be blank" }
    ]

    assert_equal expected_errors, error.errors
    assert_equal "First name can't be blank\nLast name can't be blank", error.message
  end

  def test_successful_update_card
    card = create_card_on(@environment)
    result = @environment.update_credit_card(card.token, card_deets)

    assert_kind_of(Spreedly::CreditCard, result)
    assert_equal 'Cauthon', result.last_name
    assert_equal 'Mat', result.first_name
    assert_equal 'cauthon@wot.com', result.email
  end

  private
  def card_deets(options = {})
    {
      email: 'cauthon@wot.com', month: 1, year: 2019,
      last_name: 'Cauthon', first_name: 'Mat'
    }.merge(options)
  end

end

Version data entries

11 entries across 11 versions & 1 rubygems

Version Path
spreedly-2.0.11 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.10 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.9 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.8 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.7 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.6 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.5 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.4 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.3 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.2 test/remote/remote_update_credit_card_test.rb
spreedly-2.0.1 test/remote/remote_update_credit_card_test.rb