require 'test_helper' module RubyPsigate # This class needs to perform a few functions: # 1) Retrieve summary level information (account, charge, invoice, template, email report) # 2) Perform body level functions # 3) Perform detail level functions class AccountTest < Test::Unit::TestCase def setup @account = Account.new end should "have a getter/setter for account_id" do assert @account.respond_to?(:account_id) assert @account.respond_to?(:account_id=) end context "actions" do should "have a getter/setter" do assert @account.respond_to?(:action) assert @account.respond_to?(:action=) end should "set action to :register, returns AMA01" do @account.action = { :account => :register } assert_equal "AMA01", @account.action end should "return :account_register when looking up with AMA01" do response = Account.action_reverse_lookup("AMA01") assert_equal :account_register, response end end context "credit card interface" do setup do @account = Order.new end should "accept a CreditCard object" do assert @account.respond_to?(:cc=) end should "not raise error when setting credit card object" do @cc = mock() @cc.expects(:is_a?).with(RubyPsigate::CreditCard).returns(true) assert_nothing_raised do @account.cc = @cc end end should "raise error if credit card object is not RubyPsigate::CreditCard" do assert_raises(InvalidCreditCard) do @cc = mock() @cc.expects(:is_a?).with(RubyPsigate::CreditCard).returns(false) @account.cc = @cc end end end context "address" do should "have a getter/setter" do assert @account.respond_to?(:address) assert @account.respond_to?(:address=) end should "raise error if address is not an Address object" do assert_raises(InvalidAddress) do @account.address = "my address" end end end should "have a email getter/setter" do assert @account.respond_to?(:email) assert @account.respond_to?(:email=) end should "have a comments getter/setter" do assert @account.respond_to?(:comments) assert @account.respond_to?(:comments=) end should "have a serial number getter/setter (used for payment method identifier)" do assert @account.respond_to?(:serial_no) assert @account.respond_to?(:serial_no=) end should "return a hash for :register" do @expectation = { :Action => "AMA01", :Account => { :AccountID => nil } } @expectation[:Account].merge!(valid_address_hash) @expectation[:Account][:CardInfo] = valid_credit_card_hash(:card_info) @account.action = { :account => :register } @account.account_id = nil @account.address = valid_address @account.cc = valid_credit_card assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for :update" do @expectation = { :Action => "AMA02", :Condition => { :AccountID => "1234567890" }, :Update => {} } @expectation[:Update].merge!(valid_address_hash) @expectation[:Update].merge!(:Email => "bob@gmail.com") @expectation[:Update].merge!(:Comments => "Some comment here") @account.action = { :account => :update } @account.account_id = "1234567890" @account.address = valid_address @account.email = "bob@gmail.com" @account.comments = "Some comment here" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for retrieving account details" do @expectation = { :Action => "AMA05", :Condition => { :AccountID => "1234567890" } } @account.action = { :account => :details } @account.account_id = "1234567890" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for enabling account" do @expectation = { :Action => "AMA08", :Condition => { :AccountID => "1234567890" } } @account.action = { :account => :enable } @account.account_id = "1234567890" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for disabling account" do @expectation = { :Action => "AMA09", :Condition => { :AccountID => "1234567890" } } @account.action = { :account => :disable } @account.account_id = "1234567890" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for adding a new credit card" do @expectation = { :Action => "AMA11", :Account => { :AccountID => "1234567890", :CardInfo => {} } } @expectation[:Account][:CardInfo].merge!(valid_credit_card_hash(:card_info)) @account.action = { :credit_card => :add } @account.account_id = "1234567890" @account.cc = valid_credit_card assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for deleting a credit card" do @expectation = { :Action => "AMA14", :Condition => { :AccountID => "1234567890", :SerialNo => "99" } } @account.action = { :credit_card => :delete } @account.account_id = "1234567890" @account.serial_no = "99" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for enabling a credit card" do @expectation = { :Action => "AMA18", :Condition => { :AccountID => "1234567890", :SerialNo => "99" } } @account.action = { :credit_card => :enable } @account.account_id = "1234567890" @account.serial_no = "99" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for disabling a credit card" do @expectation = { :Action => "AMA19", :Condition => { :AccountID => "1234567890", :SerialNo => "99" } } @account.action = { :credit_card => :disable } @account.account_id = "1234567890" @account.serial_no = "99" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for retrieval of charge summary" do @expectation = { :Action => "RBC00", :Condition => { :AccountID => "1234567890", :StoreID => "MYSTORE" } } @expectation[:Condition].merge!(valid_recurring_charge_hash) @account.action = { :charges => :summary } @account.rbcharge = valid_recurring_charge @account.account_id = "1234567890" @account.store_id = "MYSTORE" assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for registering a new charge" do @expectation = { :Action => "RBC01", :Charge => { :AccountID => "1234567890", :SerialNo => "99", :RBCID => "9999999999", :RBName => "Charge123", :Interval => "M", :RBTrigger => "25", :StartTime => "2010.08.01", :EndTime => "2015.12.31", :ItemInfo => [{ :ProductID => "Newspaper", :Description => "Toronto Star", :Quantity => "1", :Price => "25.00", :Tax1 => "2.00", :Tax2 => "1.25" }, { :ProductID => "Newspaper", :Description => "Toronto Star", :Quantity => "1", :Price => "25.00", :Tax1 => "2.00", :Tax2 => "1.25" }] } } @account.action = { :charges => :add } @account.account_id = "1234567890" @account.serial_no = "99" @recurring_charge = valid_recurring_charge @recurring_charge.status = nil @recurring_charge.processtype = nil 2.times { @recurring_charge << valid_recurring_item } @account.rbcharge = @recurring_charge assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for updating a charge" do @expectation = { :Action => "RBC02", :Condition => { :RBCID => "9999999999" }, :Update => { :RBTrigger => "25" } } @account.action = { :charges => :update } @account.rbcharge = RecurringCharge.new(:rbcid => "9999999999", :rbtrigger => "25") assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for deleting a charge" do @expectation = { :Action => "RBC04", :Condition => { :RBCID => "9999999999" } } @account.action = { :charges => :delete } @account.rbcharge = RecurringCharge.new(:rbcid => "9999999999") assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for retrieving a charge" do @expectation = { :Action => "RBC05", :Condition => { :RBCID => "9999999999" } } @account.action = { :charges => :details } @account.rbcharge = RecurringCharge.new(:rbcid => "9999999999") assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for enabling charges" do @expectation = { :Action => "RBC08", :Condition => { :RBCID => "9999999999" } } @account.action = { :charges => :enable } @account.rbcharge = RecurringCharge.new(:rbcid => "9999999999") assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for disabling charges" do @expectation = { :Action => "RBC09", :Condition => { :RBCID => "9999999999" } } @account.action = { :charges => :disable } @account.rbcharge = RecurringCharge.new(:rbcid => "9999999999") assert_equal @expectation, @account.to_hash(@account.action) end should "return a hash for immediate charge" do @expectation = { :Action => "RBC99", :Charge => { :AccountID => "1234567890", :SerialNo => "1", :RBName => "Immediate Payment", :ItemInfo => [ { :ProductID => "Newspaper", :Description => "Toronto Star", :Quantity => "1", :Price => "25.00", :Tax1 => "2.00", :Tax2 => "1.25" } ] } } @account.action = { :charges => :immediate } @account.account_id = "1234567890" @account.serial_no = "1" @recurring_charge = RecurringCharge.new(:rbname => "Immediate Payment") @recurring_charge << valid_recurring_item @account.rbcharge = @recurring_charge assert_equal @expectation, @account.to_hash(@account.action) end end end