marketing_event_test.rb 2.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667
  1. require 'test_helper'
  2. class MarketingEventTest < Test::Unit::TestCase
  3. def test_get_marketing_events
  4. fake("marketing_events", method: :get, body: load_fixture('marketing_events'))
  5. marketing_events = ShopifyAPI::MarketingEvent.all
  6. assert_equal(2, marketing_events.size)
  7. end
  8. def test_get_marketing_event
  9. fake("marketing_events/1", method: :get, body: load_fixture('marketing_event'))
  10. marketing_event = ShopifyAPI::MarketingEvent.find(1)
  11. assert_equal(1, marketing_event.id)
  12. end
  13. def test_create_marketing_event
  14. fake("marketing_events", method: :post, body: load_fixture('marketing_event'))
  15. marketing_event = ShopifyAPI::MarketingEvent.new
  16. marketing_event.currency_code = 'GBP'
  17. marketing_event.event_target = 'facebook'
  18. marketing_event.event_type = 'post'
  19. marketing_event.save
  20. assert_equal('facebook', marketing_event.event_target)
  21. assert_equal(1, marketing_event.id)
  22. end
  23. def test_delete_marketing_event
  24. fake("marketing_events/1", method: :get, body: load_fixture('marketing_event'))
  25. fake("marketing_events/1", method: :delete, body: "destroyed")
  26. marketing_event = ShopifyAPI::MarketingEvent.find(1)
  27. assert(marketing_event.destroy)
  28. end
  29. def test_update_marketing_event
  30. fake('marketing_events/1', method: :get, status: 200, body: load_fixture('marketing_event'))
  31. marketing_event = ShopifyAPI::MarketingEvent.find(1)
  32. marketing_event.currency = 'USD'
  33. fake('marketing_events/1', method: :put, status: 200, body: load_fixture('marketing_event'))
  34. assert(marketing_event.save)
  35. end
  36. def test_count_marketing_events
  37. fake("marketing_events/count", method: :get, body: '{"count": 2}')
  38. marketing_events_count = ShopifyAPI::MarketingEvent.count
  39. assert_equal(2, marketing_events_count)
  40. end
  41. def test_add_engagements
  42. fake("marketing_events/1", method: :get, body: load_fixture('marketing_event'))
  43. marketing_event = ShopifyAPI::MarketingEvent.find(1)
  44. fake("marketing_events/1/engagements", method: :post, status: 201, body: load_fixture('engagement'))
  45. engagement = {
  46. occurred_on: "2017-04-20",
  47. impressions_count: nil,
  48. views_count: nil,
  49. clicks_count: 10,
  50. shares_count: nil,
  51. favorites_count: nil,
  52. comments_count: nil,
  53. ad_spend: nil,
  54. is_cumulative: true,
  55. }
  56. marketing_event.add_engagements(engagement)
  57. assert("2017-04-20", engagement[:occurred_on])
  58. end
  59. end