resource_feedback_test.rb 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243
  1. # frozen_string_literal: true
  2. class ResourceFeedbackTest < Test::Unit::TestCase
  3. def test_get_resource_feedback
  4. body = { resource_feedback: [{ resource_type: 'Shop' }] }.to_json
  5. fake('resource_feedback', method: :get, body: body)
  6. resource_feedback = ShopifyAPI::ResourceFeedback.find(:all)
  7. assert_equal('Shop', resource_feedback.first.resource_type)
  8. end
  9. def test_save_with_resource_feedback_endpoint
  10. body = { resource_feedback: {} }.to_json
  11. fake('resource_feedback', method: :post, body: body)
  12. ShopifyAPI::ResourceFeedback.new.save
  13. assert_request_body(body)
  14. end
  15. def test_get_resource_feedback_with_product_id
  16. body = { resource_feedback: [{ resource_type: 'Product' }] }.to_json
  17. fake('products/42/resource_feedback', method: :get, body: body)
  18. resource_feedback = ShopifyAPI::ResourceFeedback.find(:all, params: { product_id: 42 })
  19. assert_equal('Product', resource_feedback.first.resource_type)
  20. end
  21. def test_save_with_product_id_resource_feedback_endpoint
  22. body = { resource_feedback: {} }.to_json
  23. fake('products/42/resource_feedback', method: :post, body: body)
  24. ShopifyAPI::ResourceFeedback.new(product_id: 42).save
  25. assert_request_body(body)
  26. end
  27. def test_save_raises_exception_when_already_persisted
  28. body = { resource_feedback: {} }.to_json
  29. fake('resource_feedback', method: :post, body: body)
  30. resource_feedback = ShopifyAPI::ResourceFeedback.new
  31. resource_feedback.save
  32. assert_request_body(body)
  33. ShopifyAPI::ResourceFeedback.any_instance.expects(:persisted?).returns(true)
  34. assert_raises(ShopifyAPI::ResourceFeedback::ExistingFeedbackSaved) do
  35. resource_feedback.save
  36. end
  37. end
  38. end