Slide 323
Slide 323 text
require 'test_helper'
class SwapRequestCreditorTest < ActiveSupport::TestCase
fixtures :swap_requests, :basic_orders, :order_items, :skus, :order_skus
test "#credit_amount_cents sums out of stock sku price" do
order = basic_orders(:complete)
swap_request = swap_requests(:one)
swap_request.update!(order: order, state: SwapRequest::INITIATED)
out_of_stock_sku = skus(:one)
out_of_stock_sku.update!(in_stock: 0)
out_of_stock_order_sku = order_skus(:one).tap { |os| os.update!(sku: out_of_stock_sku, order: order) }
out_of_stock_order_item = order_items(:shirt).tap do |oi|
oi.update!(order_sku: out_of_stock_order_sku, price_cents: 100, quantity: 3)
end
order.order_items << out_of_stock_order_item
cents = SwapRequestCreditor.new(id: swap_request.id).credit_amount_cents
assert_equal(cents, 300)
end
end