Skip to content

Commit

Permalink
Corrigir tratamento de exceção na classe Salesforce::Request
Browse files Browse the repository at this point in the history
  • Loading branch information
gildemberg-santos committed Apr 17, 2024
1 parent 71311d1 commit 56f92e1
Show file tree
Hide file tree
Showing 3 changed files with 8 additions and 6 deletions.
6 changes: 4 additions & 2 deletions lib/salesforce/v2/request.rb
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,9 @@ def request

def post
response = HTTParty.post(url, headers: headers, body: body)
handle_exception(:indefinied_message, handle_exception_message(response)) unless [201, 200].include? response.code
unless [201, 200].include? response.code
handle_exception(:indefinied_message, handle_exception_message(response))
end

response
end
Expand All @@ -44,7 +46,7 @@ def body

def valid!
return handle_exception(:invalid_url) if url.nil?
return handle_exception(:invalid_token) if options[:token].nil? && !options[:method] == :refresh
return handle_exception(:invalid_token) if options[:token].nil? && options[:method] != :refresh

handle_exception(:indefinied_method) if options[:method].nil?
end
Expand Down
6 changes: 3 additions & 3 deletions spec/lib/salesforce/lead_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@
@lead.send({ "Company" => "Test" })
end.to raise_error(
an_instance_of(Salesforce::Error).and(
having_attributes(message: "Required fields are missing: [LastName, marcas__c]")
having_attributes(message: "Required fields are missing: [LastName]")
)
)
}
Expand All @@ -42,14 +42,14 @@
@lead.send({ "LastName" => "Test" })
end.to raise_error(
an_instance_of(Salesforce::Error).and(
having_attributes(message: "Required fields are missing: [Company, marcas__c]")
having_attributes(message: "Required fields are missing: [Company]")
)
)
}

it {
expect(
@lead.send({ "Company" => "Test", "LastName" => "Test", "marcas__c" => "carro, moto" })["success"]
@lead.send({ "Company" => "Test", "LastName" => "Test" })["success"]
).to eq true
}
end
2 changes: 1 addition & 1 deletion spec/lib/salesforce/v2/request_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,7 @@
end

context "when invalid token" do
let(:options) { { method: :post } }
let(:options) { { method: :post, token: nil } }

it { expect(request.data[:exception].message).to eq "Salesforce token is not valid" }
end
Expand Down

0 comments on commit 56f92e1

Please sign in to comment.