refund_test.rb 1.3 KB

123456789101112131415161718192021222324252627282930313233343536
  1. require 'test_helper'
  2. class RefundTest < Test::Unit::TestCase
  3. test '#create should create a refund' do
  4. fake("orders/450789469/refunds", method: :post, status: 201, body: load_fixture('refund'))
  5. refund = ShopifyAPI::Refund.create(
  6. order_id: 450789469,
  7. restock: true,
  8. note: "wrong size",
  9. shipping: { full_refund: true },
  10. refund_line_items: [{ line_item_id: 518995019, quantity: 1 }]
  11. )
  12. assert_equal(703073504, refund.refund_line_items.first.line_item_id)
  13. end
  14. test '#find should return a refund' do
  15. fake(
  16. "orders/450789469/refunds/509562969.json?order_id=450789469",
  17. extension: false,
  18. method: :get,
  19. body: load_fixture('refund')
  20. )
  21. fake("orders/450789469/refunds/509562969", method: :get, body: load_fixture('refund'))
  22. refund = ShopifyAPI::Refund.find(509562969, params: { order_id: 450789469 })
  23. assert_equal(509562969, refund.id)
  24. end
  25. test '#calculate a refund' do
  26. fake("orders/450789469/refunds/calculate", method: :post, body: load_fixture('refund'))
  27. data = { shipping: { amount: 0 } }
  28. refund = ShopifyAPI::Refund.calculate(data, params: { order_id: 450789469 })
  29. assert_equal(2, refund.refund_line_items.count)
  30. assert_equal(703073504, refund.refund_line_items.first.line_item_id)
  31. end
  32. end