resource_feedback_test.rb 1.6 KB

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