limits_test.rb 1.1 KB

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