shop_test.rb 2.1 KB

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