Skip to content
This repository has been archived by the owner on Apr 14, 2023. It is now read-only.

Commit

Permalink
Merge pull request #20 from solidusio/fix/errors
Browse files Browse the repository at this point in the history
Correctly parse error message for failure response
  • Loading branch information
cbrunsdon authored Sep 14, 2016
2 parents 7cd9b0b + 29bbf92 commit 8cceb55
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 6 deletions.
4 changes: 2 additions & 2 deletions app/models/solidus_paypal_braintree/response.rb
Original file line number Diff line number Diff line change
Expand Up @@ -34,8 +34,8 @@ def build_success(result)
end

def build_failure(result)
transaction = result.transaction
new(false, transaction.status, {}, {})
msg = result.errors.map { |e| "#{e.message} (#{e.code})" }.join(" ")
new(false, msg)
end
end
end
Expand Down
21 changes: 17 additions & 4 deletions spec/models/solidus_paypal_braintree/response_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -2,15 +2,16 @@

RSpec.describe SolidusPaypalBraintree::Response do
let(:error_result) do
transaction = instance_double(
'Braintree::Transaction',
status: 'error'
error = instance_double(
'Braintree::ValidationError',
code: '12345',
message: "Cannot refund a transaction unless it is settled."
)

instance_double(
'Braintree::ErrorResult',
success?: false,
transaction: transaction
errors: [error]
)
end

Expand Down Expand Up @@ -52,6 +53,18 @@
it { expect(successful_response.success?).to be true }
end

describe "#message" do
context "with a success response" do
subject { successful_response.message }
it { is_expected.to eq "ok" }
end

context "with an error response" do
subject { error_response.message }
it { is_expected.to eq "Cannot refund a transaction unless it is settled. (12345)" }
end
end

describe '#authorization' do
it 'is whatever the b.t. transaction id was' do
expect(successful_response.authorization).to eq 'abcdef'
Expand Down

0 comments on commit 8cceb55

Please sign in to comment.