customer_test.rb 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. require 'test_helper'
  2. class CustomerTest < Test::Unit::TestCase
  3. def setup
  4. super
  5. fake('customers/207119551', body: load_fixture('customers'))
  6. @customer = ShopifyAPI::Customer.find(207119551)
  7. end
  8. test "search should get a customers collection" do
  9. fake(
  10. "customers/search.json?query=Bob+country%3AUnited+States",
  11. extension: false,
  12. body: load_fixture('customers_search')
  13. )
  14. results = ShopifyAPI::Customer.search(query: 'Bob country:United States')
  15. assert_equal('Bob', results.first.first_name)
  16. end
  17. test "account_activation_url should create an account activation url" do
  18. fake(
  19. "customers/207119551/account_activation_url",
  20. method: :post,
  21. body: load_fixture('customers_account_activation_url')
  22. )
  23. activation_url = "http://apple.myshopify.com/account/activate/207119551/86688abf23572680740b1c062fa37111-1458248616"
  24. assert_equal(activation_url, @customer.account_activation_url)
  25. end
  26. test "#send_invite with no params" do
  27. customer_invite_fixture = load_fixture('customer_invite')
  28. customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
  29. fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
  30. customer_invite_response = @customer.send_invite
  31. assert_equal('{"customer_invite":{}}', WebMock.last_request.body)
  32. assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
  33. assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
  34. end
  35. test "#send_invite with params" do
  36. customer_invite_fixture = load_fixture('customer_invite')
  37. customer_invite = ActiveSupport::JSON.decode(customer_invite_fixture)
  38. fake('customers/207119551/send_invite', method: :post, body: customer_invite_fixture)
  39. customer_invite_response = @customer.send_invite(ShopifyAPI::CustomerInvite.new(customer_invite['customer_invite']))
  40. assert_equal(customer_invite, ActiveSupport::JSON.decode(WebMock.last_request.body))
  41. assert_kind_of(ShopifyAPI::CustomerInvite, customer_invite_response)
  42. assert_equal(customer_invite['customer_invite']['to'], customer_invite_response.to)
  43. end
  44. end