limits_test.rb 1.1 KB

123456789101112131415161718192021222324252627282930313233343536373839
  1. # frozen_string_literal: true
  2. require 'test_helper'
  3. class LimitsTest < Test::Unit::TestCase
  4. def setup
  5. super
  6. @header_hash = { '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 = { '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. should "raise error when header doesn't exist" do
  26. @header_hash = {}
  27. ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
  28. assert_raises(ShopifyAPI::Limits::LimitUnavailable) do
  29. ShopifyAPI.credit_left
  30. end
  31. end
  32. end
  33. end