Skip to content

Commit

Permalink
Fix rates response when there is only a single rate from UPS
Browse files Browse the repository at this point in the history
  • Loading branch information
calvinhughes committed Jun 14, 2019
1 parent c3151ea commit 7d22654
Show file tree
Hide file tree
Showing 4 changed files with 86 additions and 1 deletion.
4 changes: 4 additions & 0 deletions lib/ups/parsers/base_parser.rb
Expand Up @@ -32,6 +32,10 @@ def parsed_response

private

def normalize_response_into_array(response_node)
[response_node].flatten
end

def build_error_description(errors_node)
return errors_node.last[:ErrorDescription] if errors_node.is_a?(Array)

Expand Down
2 changes: 1 addition & 1 deletion lib/ups/parsers/rates_parser.rb
Expand Up @@ -11,7 +11,7 @@ def rated_shipments
private

def rates
root_response[:RatedShipment]
normalize_response_into_array(root_response[:RatedShipment])
end

def root_response
Expand Down
55 changes: 55 additions & 0 deletions spec/stubs/rates_success_single_rate.xml
@@ -0,0 +1,55 @@
<?xml version="1.0" encoding="UTF-8"?>
<RatingServiceSelectionResponse>
<Response>
<ResponseStatusCode>1</ResponseStatusCode>
<ResponseStatusDescription>Success</ResponseStatusDescription>
</Response>
<RatedShipment>
<Service>
<Code>11</Code>
</Service>
<RatedShipmentWarning>Your invoice may vary from the displayed reference rates</RatedShipmentWarning>
<RatedShipmentWarning>Ship To Address Classification is changed from Commercial to Residential</RatedShipmentWarning>
<BillingWeight>
<UnitOfMeasurement>
<Code>KGS</Code>
</UnitOfMeasurement>
<Weight>0.5</Weight>
</BillingWeight>
<TransportationCharges>
<CurrencyCode>GBP</CurrencyCode>
<MonetaryValue>25.03</MonetaryValue>
</TransportationCharges>
<ServiceOptionsCharges>
<CurrencyCode>GBP</CurrencyCode>
<MonetaryValue>0.00</MonetaryValue>
</ServiceOptionsCharges>
<TotalCharges>
<CurrencyCode>GBP</CurrencyCode>
<MonetaryValue>25.03</MonetaryValue>
</TotalCharges>
<GuaranteedDaysToDelivery />
<ScheduledDeliveryTime />
<RatedPackage>
<TransportationCharges>
<CurrencyCode />
<MonetaryValue />
</TransportationCharges>
<ServiceOptionsCharges>
<CurrencyCode />
<MonetaryValue />
</ServiceOptionsCharges>
<TotalCharges>
<CurrencyCode />
<MonetaryValue />
</TotalCharges>
<Weight>0.5</Weight>
<BillingWeight>
<UnitOfMeasurement>
<Code />
</UnitOfMeasurement>
<Weight />
</BillingWeight>
</RatedPackage>
</RatedShipment>
</RatingServiceSelectionResponse>
26 changes: 26 additions & 0 deletions spec/ups/connection/rates_standard_spec.rb
Expand Up @@ -68,6 +68,32 @@
}
]
end

describe 'when API responds with a single rate' do
before do
Excon.stub(method: :post) do |params|
case params[:path]
when UPS::Connection::RATE_PATH
{ body: File.read("#{stub_path}/rates_success_single_rate.xml"), status: 200 }
end
end
end

it 'returns rates' do
expect(subject.rated_shipments).wont_be_empty
expect(subject.rated_shipments).must_equal [
{
:service_code=>"11",
:service_name=>"UPS Standard",
:warnings=>[
"Your invoice may vary from the displayed reference rates",
"Ship To Address Classification is changed from Commercial to Residential"
],
:total=>"25.03"
}
]
end
end
end

describe 'error rates response' do
Expand Down

0 comments on commit 7d22654

Please sign in to comment.