diff --git a/t/Shop/Tax.t b/t/Shop/Tax.t index dda4a6c27..0d300996a 100644 --- a/t/Shop/Tax.t +++ b/t/Shop/Tax.t @@ -34,7 +34,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 73; +my $tests = 80; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -357,7 +357,7 @@ eval { }; ok (!$failure, 'Tax data not imported'); $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( $e, methods( @@ -365,7 +365,41 @@ cmp_deeply( brokenFile => WebGUI::Test->getTestCollateralPath('taxTables/badTaxTable.csv'), 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. 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}); ##Set up the tax information diff --git a/t/supporting_collateral/taxTables/badHeaders.csv b/t/supporting_collateral/taxTables/badHeaders.csv new file mode 100644 index 000000000..36ba113f0 --- /dev/null +++ b/t/supporting_collateral/taxTables/badHeaders.csv @@ -0,0 +1,3 @@ +where,value,taxRates +state,5.0 +code,53701,0.5 diff --git a/t/supporting_collateral/taxTables/missingHeaders.csv b/t/supporting_collateral/taxTables/missingHeaders.csv new file mode 100644 index 000000000..f23c5baa8 --- /dev/null +++ b/t/supporting_collateral/taxTables/missingHeaders.csv @@ -0,0 +1,3 @@ +field,taxRate +state,5.0 +code,53701,0.5