Sha256: da71cc9aae3761f7205583b95a66744525b9afed241ac03c30a3584b53f822e1

Contents?: true

Size: 1.09 KB

Versions: 13

Compression:

Stored size: 1.09 KB

Contents

require 'test_helper'

class LimitsTest < Test::Unit::TestCase
  def setup
    super
    @header_hash = { 'X-Shopify-Shop-Api-Call-Limit' => '100/300' }
    ShopifyAPI::Base.connection.expects(:response).at_least(0).returns(@header_hash)
  end

  context "Limits" do
    should "fetch limit total" do
      assert_equal(299, ShopifyAPI.credit_limit(:shop))
    end

    should "fetch used calls" do
      assert_equal(100, ShopifyAPI.credit_used(:shop))
    end

    should "calculate remaining calls" do
      assert_equal(199, ShopifyAPI.credit_left)
    end

    should "flag maxed out credits" do
      assert !ShopifyAPI.maxed?
      @header_hash = { 'X-Shopify-Shop-Api-Call-Limit' => '299/300' }
      ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
      assert ShopifyAPI.maxed?
    end

    should "raise error when header doesn't exist" do
      @header_hash = {}
      ShopifyAPI::Base.connection.expects(:response).at_least(1).returns(@header_hash)
      assert_raises ShopifyAPI::Limits::LimitUnavailable do
        ShopifyAPI.credit_left
      end
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
shopify_api-9.2.0 test/limits_test.rb
shopify_api-9.1.0 test/limits_test.rb
shopify_api-9.0.4 test/limits_test.rb
shopify_api-9.0.3 test/limits_test.rb
shopify_api-9.0.2 test/limits_test.rb
shopify_api-9.0.1 test/limits_test.rb
shopify_api-9.0.0 test/limits_test.rb
shopify_api-8.1.0 test/limits_test.rb
shopify_api-8.0.0 test/limits_test.rb
shopify_api-7.1.0 test/limits_test.rb
shopify_api-7.0.2 test/limits_test.rb
shopify_api-7.0.1 test/limits_test.rb
shopify_api-7.0.0 test/limits_test.rb