Add coverage tests for more bad CSV file handling,
and two files to exercise the header checks in importTaxData
This commit is contained in:
parent
7fa4e945b5
commit
cd55ff1a9e
3 changed files with 46 additions and 3 deletions
43
t/Shop/Tax.t
43
t/Shop/Tax.t
|
|
@ -34,7 +34,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 73;
|
my $tests = 80;
|
||||||
plan tests => 1 + $tests;
|
plan tests => 1 + $tests;
|
||||||
|
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
|
|
@ -357,7 +357,7 @@ eval {
|
||||||
};
|
};
|
||||||
ok (!$failure, 'Tax data not imported');
|
ok (!$failure, 'Tax data not imported');
|
||||||
$e = Exception::Class->caught();
|
$e = Exception::Class->caught();
|
||||||
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with a ');
|
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with an error on 1 line');
|
||||||
cmp_deeply(
|
cmp_deeply(
|
||||||
$e,
|
$e,
|
||||||
methods(
|
methods(
|
||||||
|
|
@ -365,7 +365,41 @@ cmp_deeply(
|
||||||
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/badTaxTable.csv'),
|
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/badTaxTable.csv'),
|
||||||
brokenLine => 1,
|
brokenLine => 1,
|
||||||
),
|
),
|
||||||
'importTaxData: error handling for file that that cannot be read',
|
'importTaxData: error handling for file with errors in the CSV data',
|
||||||
|
);
|
||||||
|
|
||||||
|
eval {
|
||||||
|
$failure = $taxer->importTaxData(
|
||||||
|
WebGUI::Test->getTestCollateralPath('taxTables/missingHeaders.csv')
|
||||||
|
);
|
||||||
|
};
|
||||||
|
ok (!$failure, 'Tax data not imported when headers are missing');
|
||||||
|
$e = Exception::Class->caught();
|
||||||
|
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with a missing header column');
|
||||||
|
cmp_deeply(
|
||||||
|
$e,
|
||||||
|
methods(
|
||||||
|
error => 'Bad header found in the CSV file',
|
||||||
|
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/missingHeaders.csv'),
|
||||||
|
),
|
||||||
|
'importTaxData: error handling for a file with a missing header',
|
||||||
|
);
|
||||||
|
|
||||||
|
eval {
|
||||||
|
$failure = $taxer->importTaxData(
|
||||||
|
WebGUI::Test->getTestCollateralPath('taxTables/badHeaders.csv')
|
||||||
|
);
|
||||||
|
};
|
||||||
|
ok (!$failure, 'Tax data not imported when headers are wrong');
|
||||||
|
$e = Exception::Class->caught();
|
||||||
|
isa_ok($e, 'WebGUI::Error::InvalidFile', 'importTaxData: a file with a bad header column');
|
||||||
|
cmp_deeply(
|
||||||
|
$e,
|
||||||
|
methods(
|
||||||
|
error => 'Bad header found in the CSV file',
|
||||||
|
brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/badHeaders.csv'),
|
||||||
|
),
|
||||||
|
'importTaxData: error handling for a file with a bad header',
|
||||||
);
|
);
|
||||||
|
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
@ -433,6 +467,9 @@ is($e->error, 'Must pass in a WebGUI::Shop::Cart object', 'calculate: error hand
|
||||||
##Build a cart, add some Donation SKUs to it. Set one to be taxable.
|
##Build a cart, add some Donation SKUs to it. Set one to be taxable.
|
||||||
|
|
||||||
my $cart = WebGUI::Shop::Cart->create($session);
|
my $cart = WebGUI::Shop::Cart->create($session);
|
||||||
|
|
||||||
|
is($taxer->calculate($cart), 0, 'calculate returns 0 if there is no shippingAddressId in the cart');
|
||||||
|
|
||||||
$cart->update({ shippingAddressId => $taxingAddress->getId});
|
$cart->update({ shippingAddressId => $taxingAddress->getId});
|
||||||
|
|
||||||
##Set up the tax information
|
##Set up the tax information
|
||||||
|
|
|
||||||
3
t/supporting_collateral/taxTables/badHeaders.csv
Normal file
3
t/supporting_collateral/taxTables/badHeaders.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
where,value,taxRates
|
||||||
|
state,5.0
|
||||||
|
code,53701,0.5
|
||||||
|
3
t/supporting_collateral/taxTables/missingHeaders.csv
Normal file
3
t/supporting_collateral/taxTables/missingHeaders.csv
Normal file
|
|
@ -0,0 +1,3 @@
|
||||||
|
field,taxRate
|
||||||
|
state,5.0
|
||||||
|
code,53701,0.5
|
||||||
|
Loading…
Add table
Add a link
Reference in a new issue