Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Tests
class Reconciliation::Transaction < Reconciliation::Validator
def initialize transaction
@transaction = transaction
end
def new_error
Reconciliation::GatewayErrors.new @transaction.history, @transaction
end
def verify options = {}
return if @transaction.declined? || @transaction.data.nil?
super
end
def verify_missing_payment
@transaction.payment.present?
end
def verify_missing_gateway_transaction
@transaction.history.present?
end
def verify_amount_mismatch
if @transaction.history && @transaction.try(:order) && @transaction.history.amount != @transaction.order.total
return false, {:expected => @transaction.history.amount, :actual => @transaction.order.total}
end
true
end
def verify_missing_order
@transaction.order.present?
end
def verify_order_state_mismatch
if @transaction.order && @transaction.history && @transaction.history.state != @transaction.order.state
return false, {:expected => @transaction.history.state, :actual => @transaction.order.state}
end
true
end
def reconcile_order_state_mismatch
if @transaction.history.approved? && @transaction.history.state != @transaction.order.state
@transaction.approve!
end
end
end
test "if the order is pending there is an error" do
history = OpenStruct.new :approved? => true, :state => 'approved'
order = OpenStruct.new :state => 'not_approved'
transaction = MiniTest::Mock.new
transaction.expect :history, history
transaction.expect :order, order
transaction.expect :approve!, true
whatever = Reconciliation::Transaction.new(transaction)
whatever.reconcile_order_state_mismatch
assert transaction.verify
end
def setup
@transaction = Factory.create(:donation_tns_transaction)
end
test "if the order is pending there is an error" do
@transaction.order.update_attribute(:state, 'pending')
@transaction.reload
errors = Reconciliation::Transaction.new(@transaction).verify
assert errors
assert errors.has_error?(:order_state_mismatch)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.