customer_test.rb 2.2 KB

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