Skip to content

Commit

Permalink
Handle empty product payload on /get_products
Browse files Browse the repository at this point in the history
  • Loading branch information
huoxito committed Oct 24, 2014
1 parent 11d73f9 commit 7c4150a
Show file tree
Hide file tree
Showing 3 changed files with 23 additions and 1 deletion.
9 changes: 9 additions & 0 deletions lib/SF_services/base.rb
Original file line number Diff line number Diff line change
@@ -1,4 +1,13 @@
module SFService
# Note about `query` methods:
#
# http://www.salesforce.com/us/developer/docs/api_rest/Content/resources_query.htm
#
# If the query results are too large, the response contains the first batch
# of results and a query identifier in the nextRecordsUrl field of the
# response. The identifier can be used in an additional request to retrieve
# the next batch.
#
class Base
attr_reader :salesforce, :config, :model_name

Expand Down
3 changes: 2 additions & 1 deletion lib/integrations/product.rb
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,9 @@ def upsert!(item = nil)

def fetch_updates
products = product_service.latest_updates config[:salesforce_products_since]
product_ids = products.map { |p| "'#{p["Id"]}'" }.join(", ")
return [] if products.to_a.empty?

product_ids = products.map { |p| "'#{p["Id"]}'" }.join(", ")
prices = product_service.find_prices_by_product_ids product_ids

products.map do |product|
Expand Down
12 changes: 12 additions & 0 deletions spec/salesforce_endpoint_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -100,4 +100,16 @@
expect(json_response["products"]).to be_a Array
end
end

it "empty get products result" do
payload = {
parameters: config.merge(salesforce_products_since: "2014-10-24T19:14:57-03:00")
}

VCR.use_cassette "requests/get_products_empty" do
post "/get_products", payload.to_json, auth
expect(json_response["summary"]).to be_nil
expect(last_response.status).to eq 200
end
end
end

0 comments on commit 7c4150a

Please sign in to comment.