refund_test.rb 1.3 KB

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