shop_test.rb 1.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556
  1. require 'test_helper'
  2. class ShopTest < Test::Unit::TestCase
  3. def setup
  4. super
  5. fake "shop"
  6. @shop = ShopifyAPI::Shop.current
  7. end
  8. def test_current_should_return_current_shop
  9. assert @shop.is_a?(ShopifyAPI::Shop)
  10. assert_equal "Apple Computers", @shop.name
  11. assert_equal "apple.myshopify.com", @shop.myshopify_domain
  12. assert_equal 690933842, @shop.id
  13. assert_equal "2007-12-31T19:00:00-05:00", @shop.created_at
  14. assert_nil @shop.tax_shipping
  15. end
  16. def test_current_with_options_should_return_current_shop
  17. fake "shop.json?fields%5B%5D=name&fields%5B%5D=myshopify_domain", :extension => false, :method => :get, :status => 201, :body => load_fixture('shop')
  18. @shop = ShopifyAPI::Shop.current(params: { fields: [:name, :myshopify_domain]})
  19. assert @shop.is_a?(ShopifyAPI::Shop)
  20. assert_equal "Apple Computers", @shop.name
  21. assert_equal "apple.myshopify.com", @shop.myshopify_domain
  22. end
  23. def test_get_metafields_for_shop
  24. fake "metafields"
  25. metafields = @shop.metafields
  26. assert_equal 2, metafields.length
  27. assert metafields.all?{|m| m.is_a?(ShopifyAPI::Metafield)}
  28. end
  29. def test_add_metafield
  30. fake "metafields", :method => :post, :status => 201, :body =>load_fixture('metafield')
  31. field = @shop.add_metafield(ShopifyAPI::Metafield.new(:namespace => "contact", :key => "email", :value => "123@example.com", :value_type => "string"))
  32. assert_equal ActiveSupport::JSON.decode('{"metafield":{"namespace":"contact","key":"email","value":"123@example.com","value_type":"string"}}'), ActiveSupport::JSON.decode(FakeWeb.last_request.body)
  33. assert !field.new_record?
  34. assert_equal "contact", field.namespace
  35. assert_equal "email", field.key
  36. assert_equal "123@example.com", field.value
  37. end
  38. def test_events
  39. fake "events"
  40. events = @shop.events
  41. assert_equal 3, events.length
  42. assert events.all?{|m| m.is_a?(ShopifyAPI::Event)}
  43. end
  44. end