limits_test.rb 914 B

12345678910111213141516171819202122232425262728293031
  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_shop_api_call_limit' => '100/300'}
  7. ShopifyAPI::Base.connection.expects(:response).at_least(0).returns(@header_hash)
  8. end
  9. context "Limits" do
  10. should "fetch limit total" do
  11. assert_equal(299, ShopifyAPI.credit_limit(:shop))
  12. end
  13. should "fetch used calls" do
  14. assert_equal(100, ShopifyAPI.credit_used(:shop))
  15. end
  16. should "calculate remaining calls" do
  17. assert_equal(199, ShopifyAPI.credit_left)
  18. end
  19. should "flag maxed out credits" do
  20. assert !ShopifyAPI.maxed?
  21. @header_hash = {'http_x_shopify_shop_api_call_limit' => '299/300'}
  22. ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
  23. assert ShopifyAPI.maxed?
  24. end
  25. end
  26. end