Add residential property to driver. Add test for quantity checking.

This commit is contained in:
Colin Kuskie 2009-07-21 15:53:00 -07:00
parent cc7b28ecce
commit b7b86fd248
2 changed files with 45 additions and 9 deletions

View file

@ -9,6 +9,7 @@ use LWP;
use Tie::IxHash;
use Locales::Country qw/ en /;
use Class::InsideOut qw/ :std /;
use Data::Dumper;
public testMode => my %testMode;
@ -109,6 +110,9 @@ sub buildXML {
},
Package => [],
};
if ($self->get('residentialIndicator') eq 'residential') {
$xmlRate->{Shipment}->{ShipTo}->{Address}->[0]->{ResidentialAddressIndicator} = [''];
}
my $packHash = $xmlRate->{Shipment}->{Package};
PACKAGE: foreach my $package (@{ $packages }) {
my $weight = 0;
@ -137,9 +141,9 @@ sub buildXML {
}
return '' unless scalar @{ $packHash }; ##Nothing to calculate shipping for.
$xml .= XMLout(\%xmlHash,
KeepRoot => 1,
NoSort => 1,
SuppressEmpty => 0,
KeepRoot => 1,
NoSort => 1,
SuppressEmpty => '',
XMLDecl => 1,
);
@ -367,6 +371,16 @@ sub definition {
options => \%customerClassification,
defaultValue => '01',
},
residential => {
fieldType => 'radioList',
label => $i18n->get('residential'),
hoverHelp => $i18n->get('residential help'),
options => {
residential => $i18n->get('residential'),
commercial => $i18n->get('commercial'),
},
defaultValue => 'commercial',
},
##Note, if a flat fee is added to this driver, then according to the license
##terms the website must display a note to the user (shop customer) that additional
##fees have been added.

View file

@ -35,7 +35,7 @@ $session->user({user => $user});
#----------------------------------------------------------------------------
# Tests
my $tests = 37;
my $tests = 40;
plan tests => 1 + $tests;
#----------------------------------------------------------------------------
@ -348,17 +348,19 @@ $properties->{sourceCountry} = 'United States';
$properties->{shipService} = '03';
$properties->{pickupType} = '01';
$properties->{customerClassification} = '04';
$properties->{residentialIndicator} = 'residential';
$driver->update($properties);
$driver->testMode(1);
$rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $smallHammer));
my $rockItem = $rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $smallHammer));
my @shippableUnits = $driver->_getShippableUnits($cart);
##Must look them up one zip at a time
my $xml = $driver->buildXML($cart, $shippableUnits[0]);
like($xml, qr/^<.xml version='1.0'.+?<.xml version=/ms, 'buildXML: has two xml declarations');
like($xml, qr/<AccessRequest xml:lang/, '... xml:lang is an attribute of AccessRequest');
#diag $xml;
my ($xmlA, $xmlR) = split /\n(?=<\?xml)/, $xml;
@ -379,12 +381,12 @@ cmp_deeply(
'... correct access request data structure for 1 package'
);
diag $xmlR;
my $xmlRate = XMLin($xmlR,
KeepRoot => 1,
);
diag Dumper $xmlRate;
cmp_deeply(
$xmlRate, {
RatingServiceSelectionRequest => {
@ -397,7 +399,7 @@ cmp_deeply(
Address => { PostalCode => 97123, CountryCode => 'us', },
},
ShipTo => {
Address => { PostalCode => 53715, CountryCode => 'us', },
Address => { PostalCode => 53715, CountryCode => 'us', ResidentialAddressIndicator => {}, },
},
Service => { Code => '03', },
Package => {
@ -416,12 +418,32 @@ SKIP: {
my $response = $driver->_doXmlRequest($xml);
ok($response->is_success, '_doXmlRequest to UPS successful for 1 package');
#diag $response->content;
my $xmlData = XMLin($response->content, ForceArray => [qw/RatedPackage/],);
ok($xmlData->{Response}->{ResponseStatusCode}, '... responseCode is successful');
ok($xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue}, '... total charges returned');
diag($xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue});
}
$rockItem->setQuantity(2);
@shippableUnits = $driver->_getShippableUnits($cart);
$xml = $driver->buildXML($cart, $shippableUnits[0]);
SKIP: {
skip 'No UPS credentials for testing', 3 unless $hasUPSCredentials;
my $response = $driver->_doXmlRequest($xml);
ok($response->is_success, '_doXmlRequest to UPS successful for 1 item, quantity=2');
#diag $response->content;
my $xmlData = XMLin($response->content, ForceArray => [qw/RatedPackage/],);
ok($xmlData->{Response}->{ResponseStatusCode}, '... responseCode is successful');
ok($xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue}, '... total charges returned');
diag($xmlData->{RatedShipment}->{TotalCharges}->{MonetaryValue});
}
TODO: {
local $TODO = 'single item shipping cost calculation';
ok(0, 'call _calculateFromXML with arranged data');
@ -434,7 +456,7 @@ $xml = $driver->buildXML($cart, @shippableUnits);
($xmlA, $xmlR) = split /\n(?=<\?xml)/, $xml;
diag $xmlR;
#diag $xmlR;
$xmlRate = XMLin( $xmlR,
KeepRoot => 1,