limits_test.rb 1.1 KB

1234567891011121314151617181920212223242526272829303132333435363738
  1. require 'test_helper'
  2. class LimitsTest < Test::Unit::TestCase
  3. def setup
  4. ShopifyAPI::Base.site = "test.myshopify.com"
  5. @header_hash = {'http_x_shopify_shop_api_call_limit' => '100/300'}
  6. ShopifyAPI::Base.connection.expects(:response).at_least(0).returns(@header_hash)
  7. end
  8. context "Limits" do
  9. should "fetch limit total" do
  10. assert_equal(299, ShopifyAPI.credit_limit(:shop))
  11. end
  12. should "fetch used calls" do
  13. assert_equal(100, ShopifyAPI.credit_used(:shop))
  14. end
  15. should "calculate remaining calls" do
  16. assert_equal(199, ShopifyAPI.credit_left)
  17. end
  18. should "flag maxed out credits" do
  19. assert !ShopifyAPI.maxed?
  20. @header_hash = {'http_x_shopify_shop_api_call_limit' => '299/300'}
  21. ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
  22. assert ShopifyAPI.maxed?
  23. end
  24. should "raise error when header doesn't exist" do
  25. @header_hash = {}
  26. ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
  27. assert_raise ShopifyAPI::Limits::LimitUnavailable do
  28. ShopifyAPI.credit_left
  29. end
  30. end
  31. end
  32. end