Selaa lähdekoodia

add location inventory_levels method

Jon Grenning 7 vuotta sitten
vanhempi
commit
4a4bca7897
2 muutettua tiedostoa jossa 18 lisäystä ja 0 poistoa
  1. 4 0
      lib/shopify_api/resources/location.rb
  2. 14 0
      test/location_test.rb

+ 4 - 0
lib/shopify_api/resources/location.rb

@@ -1,4 +1,8 @@
 module ShopifyAPI
   class Location < Base
+
+    def inventory_levels
+      ShopifyAPI::InventoryLevel.find :all, from: "/admin/locations/#{id}/inventory_levels.json"
+    end
   end
 end

+ 14 - 0
test/location_test.rb

@@ -0,0 +1,14 @@
+require 'test_helper'
+
+class LocationTest < Test::Unit::TestCase
+  test 'Retrieve inventory levels for the specified inventory_items and locations' do
+    location = ShopifyAPI::Location.new(id: 487838322)
+    expected_body = JSON.parse(load_fixture('inventory_levels'))
+    expected_body['inventory_levels'].delete_if {|level| level['location_id'] != location.id }
+    fake "locations/#{location.id}/inventory_levels", method: :get, status: 200, body: JSON(expected_body).to_s
+    inventory_levels = location.inventory_levels
+
+    assert inventory_levels.all? { |item| item.location_id == location.id },
+           message: 'Response contained locations other than the current location.'
+  end
+end