Merge branch 'ShipDriver_cio' into WebGUI8

This commit is contained in:
Colin Kuskie 2010-10-14 20:02:14 -07:00
commit bf8bdd1ac6
16 changed files with 552 additions and 940 deletions

View file

@ -124,13 +124,13 @@ cmp_deeply(
eval { $shipper = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', {}); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'addShipper croaks without options to build a object with');
isa_ok($e, 'WebGUI::Error::InvalidParam', 'addShipper croaks with empty options to build a object with');
cmp_deeply(
$e,
methods(
error => 'You must pass a hashref of options to create a new ShipDriver object',
),
'addShipper croaks without options to build a object with',
'addShipper croaks with empty options to build a object with',
);
my $driver = $ship->addShipper('WebGUI::Shop::ShipDriver::FlatRate', { enabled=>1, label=>q{Jake's Jailbird Airmail}, groupToUse=>7});

View file

@ -21,6 +21,8 @@ use HTML::Form;
use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::ShipDriver;
use Clone;
#----------------------------------------------------------------------------
# Init
@ -29,125 +31,41 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 44;
plan tests => 1 + $tests;
plan tests => 32;
#----------------------------------------------------------------------------
# put your tests here
my $e;
my $loaded = use_ok('WebGUI::Shop::ShipDriver');
my $storage;
#######################################################################
#
# definition
#
#######################################################################
my $definition;
eval { $definition = WebGUI::Shop::ShipDriver->definition(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'definition: requires a session variable',
);
$definition = WebGUI::Shop::ShipDriver->definition($session);
cmp_deeply(
$definition,
[ {
name => 'Shipper Driver',
properties => {
label => {
fieldType => 'text',
label => ignore(),
hoverHelp => ignore(),
defaultValue => undef,
},
enabled => {
fieldType => 'yesNo',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 1,
},
groupToUse => {
fieldType => 'group',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 7,
},
}
} ],
,
'Definition returns an array of hashrefs',
);
$definition = WebGUI::Shop::ShipDriver->definition($session, [ { name => 'Red' }]);
cmp_deeply(
$definition,
[
{
name => 'Red',
},
{
name => 'Shipper Driver',
properties => ignore(),
}
],
,
'New data is appended correctly',
);
#######################################################################
#
# create
# new
#
#######################################################################
my $driver;
eval { $driver = WebGUI::Shop::ShipDriver->create(); };
eval { $driver = WebGUI::Shop::ShipDriver->new(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it a session object');
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a session object');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'create takes exception to not giving it a session object',
'new takes exception to not giving it a session object',
);
eval { $driver = WebGUI::Shop::ShipDriver->create($session); };
eval { $driver = WebGUI::Shop::ShipDriver->new($session); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it a hashref of options');
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a hashref of options');
cmp_deeply(
$e,
methods(
error => 'Must provide a hashref of options',
error => 'Must provide a shipperId',
),
'create takes exception to not giving it a hashref of options',
);
eval { $driver = WebGUI::Shop::ShipDriver->create($session, {}); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'create takes exception to not giving it an empty hashref of options');
cmp_deeply(
$e,
methods(
error => 'Must provide a hashref of options',
),
'create takes exception to not giving it an empty hashref of options',
'new takes exception to not giving it a shipperId',
);
my $options = {
@ -156,7 +74,8 @@ my $options = {
groupToUse => 7,
};
$driver = WebGUI::Shop::ShipDriver->create( $session, $options );
$driver = WebGUI::Shop::ShipDriver->new( $session, Clone::clone($options) );
$driver->write;
WebGUI::Test->addToCleanup($driver);
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
@ -167,8 +86,7 @@ is($session->getId, $driver->session->getId, 'session method returns OUR session
like($driver->getId, $session->id->getValidator, 'got a valid GUID for shipperId');
cmp_deeply($driver->get, $options, 'options accessor works');
cmp_deeply($driver->get, { %{$options}, shipperId=>ignore()} , 'get works');
my $dbData = $session->db->quickHashRef('select * from shipper where shipperId=?',[$driver->getId]);
cmp_deeply(
@ -187,7 +105,7 @@ cmp_deeply(
#
#######################################################################
is (WebGUI::Shop::ShipDriver->getName($session), 'Shipper Driver', 'getName returns the human readable name of this driver');
is (WebGUI::Shop::ShipDriver->getName($session), 'Shipping Driver', 'getName returns the human readable name of this driver');
#######################################################################
#
@ -238,10 +156,6 @@ cmp_deeply(
name => undef,
type => 'submit',
},
{
name => 'driverId',
type => 'hidden',
},
{
name => 'shop',
type => 'hidden',
@ -254,6 +168,10 @@ cmp_deeply(
name => 'do',
type => 'hidden',
},
{
name => 'driverId',
type => 'hidden',
},
{
name => 'label',
type => 'text',
@ -284,28 +202,6 @@ cmp_deeply(
my $oldDriver;
eval { $oldDriver = WebGUI::Shop::ShipDriver->new(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a session object');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'new takes exception to not giving it a session object',
);
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'new takes exception to not giving it a shipperId');
cmp_deeply(
$e,
methods(
error => 'Must provide a shipperId',
),
'new takes exception to not giving it a shipperId',
);
eval { $oldDriver = WebGUI::Shop::ShipDriver->new($session, 'notEverAnId'); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::ObjectNotFound', 'new croaks unless the requested shipperId object exists in the db');
@ -339,17 +235,6 @@ like ($@, qr/^You must override the calculate method/, 'calculate croaks to forc
#
#######################################################################
eval { $driver->update(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'update takes exception to not giving it a hashref of options');
cmp_deeply(
$e,
methods(
error => 'update was not sent a hashref of options to store in the database',
),
'update takes exception to not giving it a hashref of options',
);
isa_ok( $driver->get(), 'HASH', 'get returns a hashref if called with no param');
is($driver->get('groupToUse'), 7, '... default group is 7');

View file

@ -29,94 +29,13 @@ my $session = WebGUI::Test->session;
#----------------------------------------------------------------------------
# Tests
my $tests = 19;
plan tests => 1 + $tests;
plan tests => 17;
#----------------------------------------------------------------------------
# put your tests here
use_ok('WebGUI::Shop::ShipDriver::FlatRate');
#######################################################################
#
# definition
#
#######################################################################
my $definition;
my $e; ##Exception variable, used throughout the file
eval { $definition = WebGUI::Shop::ShipDriver::FlatRate->definition(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'definition: requires a session variable',
);
$definition = WebGUI::Shop::ShipDriver::FlatRate->definition($session);
cmp_deeply(
$definition,
[ {
name => 'Flat Rate',
properties => {
flatFee => {
fieldType => 'float',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 0,
},
percentageOfPrice => {
fieldType => 'float',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 0,
},
pricePerWeight => {
fieldType => 'float',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 0,
},
pricePerItem => {
fieldType => 'float',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 0,
},
}
},
{
name => 'Shipper Driver',
properties => {
label => {
fieldType => 'text',
label => ignore(),
hoverHelp => ignore(),
defaultValue => undef,
},
enabled => {
fieldType => 'yesNo',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 1,
},
groupToUse => {
fieldType => 'group',
label => ignore(),
hoverHelp => ignore(),
defaultValue => 7,
},
}
} ],
'Definition returns an array of hashrefs',
);
#######################################################################
#
# create
@ -132,7 +51,9 @@ my $options = {
pricePerItem => 0.1,
};
my $driver2 = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
my $driver2 = WebGUI::Shop::ShipDriver::FlatRate->new($session, $options);
$driver2->write;
WebGUI::Test->addToCleanup($driver2);
isa_ok($driver2, 'WebGUI::Shop::ShipDriver::FlatRate');
@ -183,10 +104,6 @@ cmp_deeply(
name => undef,
type => 'submit',
},
{
name => 'driverId',
type => 'hidden',
},
{
name => 'shop',
type => 'hidden',
@ -199,6 +116,10 @@ cmp_deeply(
name => 'do',
type => 'hidden',
},
{
name => 'driverId',
type => 'hidden',
},
{
name => 'label',
type => 'text',
@ -306,7 +227,7 @@ $options = {
pricePerItem => 10,
};
my $driver = WebGUI::Shop::ShipDriver::FlatRate->create($session, $options);
my $driver = WebGUI::Shop::ShipDriver::FlatRate->new($session, $options);
WebGUI::Test->addToCleanup($driver);
my $cart = WebGUI::Shop::Cart->newBySession($session);
@ -372,7 +293,6 @@ my $boughtCar = $car->addToCart($car->getCollateral('variantsJSON', 'variantId',
my $firstKey = $key->addToCart($key->getCollateral('variantsJSON', 'variantId', $metalKey));
is($driver->calculate($cart), 2, 'shipsSeparately: returns two, one for ships separately, one for ships bundled');
diag $boughtCar->getSku->getMaxAllowedInCart;
$boughtCar->adjustQuantity();
is($driver->calculate($cart), 2, '... returns two, one for ships separately, one for ships bundled, even for two items');

View file

@ -37,7 +37,7 @@ $session->user({user => $user});
#----------------------------------------------------------------------------
# Tests
plan tests => 41;
plan tests => 38;
#----------------------------------------------------------------------------
# put your tests here
@ -112,33 +112,6 @@ foreach my $asset($rockHammer, $bible, $feather) {
$asset = $asset->cloneFromDb;
}
#######################################################################
#
# definition
#
#######################################################################
my $definition;
my $e; ##Exception variable, used throughout the file
eval { $definition = WebGUI::Shop::ShipDriver::UPS->definition(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'... checking error message',
);
isa_ok(
$definition = WebGUI::Shop::ShipDriver::UPS->definition($session),
'ARRAY'
);
#######################################################################
#
# create
@ -150,7 +123,7 @@ my $options = {
enabled => 1,
};
$driver = WebGUI::Shop::ShipDriver::UPS->create($session, $options);
$driver = WebGUI::Shop::ShipDriver::UPS->new($session, $options);
isa_ok($driver, 'WebGUI::Shop::ShipDriver::UPS');
isa_ok($driver, 'WebGUI::Shop::ShipDriver');
@ -183,7 +156,9 @@ undef $driver;
#
#######################################################################
$driver = WebGUI::Shop::ShipDriver::UPS->create($session, {
my $e;
$driver = WebGUI::Shop::ShipDriver::UPS->new($session, {
label => 'Shipping from Shawshank',
enabled => 1,
shipType => 'PARCEL',
@ -201,9 +176,8 @@ cmp_deeply(
'... checking error message',
);
my $properties = $driver->get();
$properties->{sourceZip} = '97123';
$driver->update($properties);
$driver->sourceZip(97123);
$driver->sourceCountry('');
eval { $driver->calculate() };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'calculate throws an exception when no source country');
@ -215,9 +189,7 @@ cmp_deeply(
'... checking error message',
);
$properties = $driver->get();
$properties->{sourceCountry} = 'United States';
$driver->update($properties);
$driver->sourceCountry('US');
eval { $driver->calculate() };
$e = WebGUI::Error->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'calculate throws an exception when no userId');
@ -229,9 +201,7 @@ cmp_deeply(
'... checking error message',
);
$properties = $driver->get();
$properties->{userId} = 'Me';
$driver->update($properties);
$driver->userId('Me');
eval { $driver->calculate() };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'calculate throws an exception when no password');
@ -243,9 +213,7 @@ cmp_deeply(
'... checking error message',
);
$properties = $driver->get();
$properties->{password} = 'knock knock';
$driver->update($properties);
$driver->password('knock knock');
eval { $driver->calculate() };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'calculate throws an exception when no license number');
@ -353,19 +321,17 @@ if (! $license) {
$license = "bogey";
}
$properties = $driver->get();
$properties->{userId} = $userId;
$properties->{password} = $password;
$properties->{licenseNo} = $license;
$properties->{sourceZip} = '97123';
$properties->{sourceCountry} = 'United States';
$properties->{shipService} = '03';
$properties->{pickupType} = '01';
$properties->{customerClassification} = '04';
$properties->{residentialIndicator} = 'residential';
$driver->update($properties);
$driver->userId($userId);
$driver->password($password);
$driver->licenseNo($license);
$driver->sourceZip('97123');
$driver->sourceCountry('United States');
$driver->shipService('03');
$driver->pickupType('01');
$driver->customerClassification('04');
$driver->residentialIndicator('residential');
$driver->testMode(1);
#$driver->testMode(1);
my $rockItem = $rockHammer->addToCart($rockHammer->getCollateral('variantsJSON', 'variantId', $smallHammer));
my @shippableUnits = $driver->_getShippableUnits($cart);

View file

@ -23,7 +23,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::ShipDriver::USPS;
plan tests => 69;
plan tests => 66;
#----------------------------------------------------------------------------
# Init
@ -113,34 +113,7 @@ foreach my $asset ($bible, $rockHammer) {
#######################################################################
#
# definition
#
#######################################################################
my $definition;
my $e; ##Exception variable, used throughout the file
eval { $definition = WebGUI::Shop::ShipDriver::USPS->definition(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'... checking error message',
);
isa_ok(
$definition = WebGUI::Shop::ShipDriver::USPS->definition($session),
'ARRAY'
);
#######################################################################
#
# create
# new
#
#######################################################################
@ -149,7 +122,7 @@ my $options = {
enabled => 1,
};
$driver2 = WebGUI::Shop::ShipDriver::USPS->create($session, $options);
$driver2 = WebGUI::Shop::ShipDriver::USPS->new($session, $options);
addToCleanup($driver2);
isa_ok($driver2, 'WebGUI::Shop::ShipDriver::USPS');
@ -161,7 +134,7 @@ isa_ok($driver2, 'WebGUI::Shop::ShipDriver');
#
#######################################################################
is (WebGUI::Shop::ShipDriver::USPS->getName($session), 'U.S. Postal Service', 'getName returns the human readable name of this driver');
is (WebGUI::Shop::ShipDriver::USPS->getName($session), 'United States Postal Service', 'getName returns the human readable name of this driver');
#######################################################################
#
@ -183,13 +156,14 @@ undef $driver2;
#
#######################################################################
my $driver = WebGUI::Shop::ShipDriver::USPS->create($session, {
my $driver = WebGUI::Shop::ShipDriver::USPS->new($session, {
label => 'Shipping from Shawshank',
enabled => 1,
shipType => 'PARCEL',
});
addToCleanup($driver);
my $e;
eval { $driver->calculate() };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'calculate throws an exception when no zipcode has been set');

View file

@ -23,7 +23,7 @@ use WebGUI::Test; # Must use this before any other WebGUI modules
use WebGUI::Session;
use WebGUI::Shop::ShipDriver::USPSInternational;
plan tests => 40;
plan tests => 37;
#----------------------------------------------------------------------------
# Init
@ -111,33 +111,6 @@ foreach my $asset ($rockHammer, $bible) {
$asset = $asset->cloneFromDb;
}
#######################################################################
#
# definition
#
#######################################################################
my $definition;
my $e; ##Exception variable, used throughout the file
eval { $definition = WebGUI::Shop::ShipDriver::USPSInternational->definition(); };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable');
cmp_deeply(
$e,
methods(
error => 'Must provide a session variable',
),
'... checking error message',
);
isa_ok(
$definition = WebGUI::Shop::ShipDriver::USPSInternational->definition($session),
'ARRAY'
);
#######################################################################
#
# create
@ -149,7 +122,7 @@ my $options = {
enabled => 1,
};
$driver2 = WebGUI::Shop::ShipDriver::USPSInternational->create($session, $options);
$driver2 = WebGUI::Shop::ShipDriver::USPSInternational->new($session, $options);
addToCleanup($driver2);
isa_ok($driver2, 'WebGUI::Shop::ShipDriver::USPSInternational');
@ -183,12 +156,13 @@ undef $driver2;
#
#######################################################################
my $driver = WebGUI::Shop::ShipDriver::USPSInternational->create($session, {
my $driver = WebGUI::Shop::ShipDriver::USPSInternational->new($session, {
label => 'Shipping from Shawshank',
enabled => 1,
});
addToCleanup($driver);
my $e;
eval { $driver->calculate() };
$e = Exception::Class->caught();
isa_ok($e, 'WebGUI::Error::InvalidParam', 'calculate throws an exception when no userId');