Fix a bug in the upgrade script, with a default applied to the wrong column.
Built the add method, and tested it, too.
This commit is contained in:
parent
649d34f1a7
commit
19591d37d4
3 changed files with 107 additions and 4 deletions
70
t/Shop/Tax.t
70
t/Shop/Tax.t
|
|
@ -17,6 +17,7 @@ use FindBin;
|
|||
use strict;
|
||||
use lib "$FindBin::Bin/../lib";
|
||||
use Test::More;
|
||||
use Test::Deep;
|
||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||
use WebGUI::Session;
|
||||
|
||||
|
|
@ -27,7 +28,7 @@ my $session = WebGUI::Test->session;
|
|||
#----------------------------------------------------------------------------
|
||||
# Tests
|
||||
|
||||
my $tests = 5;
|
||||
my $tests = 11;
|
||||
plan tests => 1 + $tests;
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
|
|
@ -39,6 +40,12 @@ SKIP: {
|
|||
|
||||
skip 'Unable to load module WebGUI::Shop::Tax', $tests unless $loaded;
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# new
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
my $taxer = WebGUI::Shop::Tax->new($session);
|
||||
|
||||
isa_ok($taxer, 'WebGUI::Shop::Tax');
|
||||
|
|
@ -47,17 +54,76 @@ isa_ok($taxer->session, 'WebGUI::Session', 'session method returns a session obj
|
|||
|
||||
is($session->getId, $taxer->session->getId, 'session method returns OUR session object');
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# getItems
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
my $taxIterator = $taxer->getItems;
|
||||
|
||||
isa_ok($taxIterator, 'WebGUI::SQL::ResultSet');
|
||||
|
||||
is($taxIterator->rows, 0, 'WebGUI ships with no predefined tax data');
|
||||
|
||||
#######################################################################
|
||||
#
|
||||
# add
|
||||
#
|
||||
#######################################################################
|
||||
|
||||
my $taxData = {
|
||||
field => 'state',
|
||||
value => 'Oregon',
|
||||
taxRate => '0',
|
||||
};
|
||||
|
||||
my $oregonTaxId = $taxer->add($taxData);
|
||||
|
||||
ok($session->id->valid($oregonTaxId), 'add method returns a valid GUID');
|
||||
|
||||
$taxIterator = $taxer->getItems;
|
||||
is($taxIterator->rows, 1, 'add added only 1 row to the tax table');
|
||||
|
||||
my $addedData = $taxIterator->hashRef;
|
||||
$taxData->{taxId} = $oregonTaxId;
|
||||
|
||||
cmp_deeply($taxData, $addedData, 'add put the right data into the database for Oregon');
|
||||
|
||||
$taxData = {
|
||||
field => 'state',
|
||||
value => 'Wisconsin',
|
||||
taxRate => '5',
|
||||
};
|
||||
|
||||
my $wisconsinTaxId = $taxer->add($taxData);
|
||||
|
||||
$taxIterator = $taxer->getItems;
|
||||
is($taxIterator->rows, 2, 'add added another row to the tax table');
|
||||
|
||||
$taxData = {
|
||||
field => 'state',
|
||||
value => 'Oregon',
|
||||
taxRate => '0.1',
|
||||
};
|
||||
|
||||
eval {$taxer->add($taxData)};
|
||||
|
||||
ok($@, 'add threw an exception to having taxes in Oregon when they were defined as 0 initially');
|
||||
|
||||
$taxIterator = $taxer->getItems;
|
||||
is($taxIterator->rows, 2, 'add did not add another row since it would be a duplicate');
|
||||
|
||||
##Madison zip codes:
|
||||
##53701-53709
|
||||
##city rate: 0.5%
|
||||
##Wisconsin rate 5.0%
|
||||
|
||||
}
|
||||
|
||||
|
||||
#----------------------------------------------------------------------------
|
||||
# Cleanup
|
||||
END {
|
||||
|
||||
$session->db->write('delete from tax');
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue