Skip to content

Instantly share code, notes, and snippets.

@supriya
Created July 29, 2009 20:17
Show Gist options
  • Save supriya/158370 to your computer and use it in GitHub Desktop.
Save supriya/158370 to your computer and use it in GitHub Desktop.
require 'test_helper'
class CallHandlerTest < ActiveSupport::TestCase
setup do
skip_auditing
CallHandler.skip_log_entry = true
end
context "A CallHandler sent #top_up" do
setup do
# Create two cards. One with top up, one without
@card_with_topup = Factory(:card)
# Creating an account addon product puts them in the TopUp Program automatically in our current implementation
@card_with_topup.person.account_addon_products << OverdraftProtectionProduct.create(:credit_limit => 500.0, :credit_increment => 20, :fee_percentage => 5, :flat_fee => 2, :account_addon_program => Factory(:account_addon_program))
@card_with_topup.person.save!
@card_without_topup = Factory(:card)
@transaction_amount = 500.0
CallHandler.skip_log_entry = true
end
context "with valid options" do
context "for a cardholder who participates in the TopUp program" do
setup do
@result = CallHandler.top_up_card(:version => :v1, :account_number => @card_with_topup.pan, :transaction_amount => @transaction_amount, :available_balance => 488.00, :ip_address => "127.0.0.01")
end
# Success, at the moment, means we return a hash. If we return a call handler result, badness happened.
should "succeed" do
assert_equal true, @result.is_a?(Hash)
end
should "return a hash with 00 response code and a top up amount of $0, as CDS will just draw the account negative" do
assert_equal @result, {:pan => @card_with_topup.pan, :status => "00", :credit_advance => 0.00}
end
should_change "CallHandlerLogEntry.successful.for_method('top_up_card').count", :by => 1
should_change "CardTopUpTransaction.accepted.count", :by => 1
end
context "for a cardholder who does not participate in the TopUp program" do
setup do
@result = CallHandler.top_up_card(:version => :v1, :account_number => @card_without_topup.pan, :transaction_amount => @transaction_amount, :available_balance => 488.00, :ip_address => "127.0.0.01")
end
should "succeed" do
assert_equal true, @result.is_a?(Hash)
end
should "return a hash with 51 response code and a zero credit advance" do
assert_equal @result, {:pan => @card_without_topup.pan, :status => "51", :credit_advance => 0.00}
end
should_change "CallHandlerLogEntry.successful.for_method('top_up_card').count", :by => 1
should_change "CardTopUpTransaction.denied.count", :by => 1
end
end
context "with invalid options" do
setup do
@result = CallHandler.top_up_card(:version => :v1, :account_number => @card_with_topup.pan, :transaction_amount => nil, :available_balance => 488.00, :ip_address => "127.0.0.01")
end
should "fail" do
assert_equal false, @result.success?
end
should_change "CallHandlerLogEntry.unsuccessful.for_method('top_up_card').count", :by => 1
should_not_change "CardTopUpTransaction.count"
end
context "with frozen credit" do
setup do
@card.credit_account.freeze_credit!
@result = CallHandler.top_up_card(:version => :v1, :account_number => @card_with_topup.pan, :transaction_amount => @transaction_amount, :available_balance => 488.00, :ip_address => "127.0.0.01")
end
#
should "fail" do
assert_equal false, @result.success?
end
#
should_change "CallHandlerLogEntry.unsuccessful.for_method('top_up_card').count", :by =>1
should_not_change "CardTopUpTransaction.count"
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment