marketing_event_test.rb 2.4 KB

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