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

View file

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