From 227af4a527c19c660315cd14f2a6e8a115d8558d Mon Sep 17 00:00:00 2001 From: Dan Wells Date: Wed, 19 Aug 2015 15:43:51 -0400 Subject: [PATCH] LP#1479107 Direct API tests The feature is tested in the broad sense, but not specifically the API bits. This adds a couple API specific cases. Signed-off-by: Dan Wells --- .../perlmods/live_t/09-lp1198465_neg_balances.t | 62 +++++++++++++++++++++- .../datasets/sql/neg_bal_custom_transactions.sql | 29 ++++++++-- .../tests/datasets/sql/neg_bal_testing_reset.sql | 4 +- 3 files changed, 87 insertions(+), 8 deletions(-) diff --git a/Open-ILS/src/perlmods/live_t/09-lp1198465_neg_balances.t b/Open-ILS/src/perlmods/live_t/09-lp1198465_neg_balances.t index 3ee057624a..ff8602455d 100644 --- a/Open-ILS/src/perlmods/live_t/09-lp1198465_neg_balances.t +++ b/Open-ILS/src/perlmods/live_t/09-lp1198465_neg_balances.t @@ -1,6 +1,6 @@ #!perl -use Test::More tests => 127; +use Test::More tests => 134; diag("Test features of Conditional Negative Balances code."); @@ -79,6 +79,18 @@ sub void_bills { return $resp; } +sub adjust_bills_to_zero { + my $billing_ids = shift; #array ref + my $resp = $apputils->simplereq( + 'open-ils.circ', + 'open-ils.circ.money.billable_xact.adjust_to_zero', + $script->authtoken, + @$billing_ids + ); + + return $resp; +} + #---------------------------------------------------------------- # The tests... assumes stock sample data, full-auto install by # eg_wheezy_installer.sh, etc. @@ -1519,6 +1531,54 @@ is( ); +## API tests (pre-configured circs) +my $circ_ses = $script->session('open-ils.circ'); + +$xact_id = 17; + +$summary = fetch_billable_xact_summary($xact_id); +ok( $summary, 'API CASE 1: Zero out negative balance'); +is( + $summary->balance_owed, + '-10.00', + 'Starting balance owed is -10.00' +); + +adjust_bills_to_zero([$xact_id]); +$summary = fetch_billable_xact_summary($xact_id); +is( + $summary->balance_owed, + '0.00', + 'Ending balance owed is 0.00' +); + +adjust_bills_to_zero([$xact_id]); +$summary = fetch_billable_xact_summary($xact_id); +is( + $summary->balance_owed, + '0.00', + 'Ending balance owed is still 0.00' +); + +$xact_id = 18; + +$summary = fetch_billable_xact_summary($xact_id); +ok( $summary, 'API CASE 2: Zero out positive, partially-adjusted, partially-paid balance'); +is( + $summary->balance_owed, + '0.20', + 'Starting balance owed is 0.20' +); + +adjust_bills_to_zero([$xact_id]); +$summary = fetch_billable_xact_summary($xact_id); +is( + $summary->balance_owed, + '0.00', + 'Ending balance owed is 0.00' +); + + $script->logout(); diff --git a/Open-ILS/tests/datasets/sql/neg_bal_custom_transactions.sql b/Open-ILS/tests/datasets/sql/neg_bal_custom_transactions.sql index c6a2083495..ccec1eeabf 100644 --- a/Open-ILS/tests/datasets/sql/neg_bal_custom_transactions.sql +++ b/Open-ILS/tests/datasets/sql/neg_bal_custom_transactions.sql @@ -19,8 +19,8 @@ UPDATE action.circulation SET checkin_lib = NULL, checkin_time = NULL, checkin_scan_time = NULL -WHERE id IN (1,2,3,4,5,6,12,13,15); -UPDATE asset.copy SET status = 3 WHERE id IN (2,3,4,5,6,7,13,14,16); +WHERE id IN (1,2,3,4,5,6,12,13,15,17); +UPDATE asset.copy SET status = 3 WHERE id IN (2,3,4,5,6,7,13,14,16,18); -- relative LOST circ UPDATE action.circulation SET @@ -70,6 +70,7 @@ WHERE id IN (7, 14, 16); UPDATE asset.copy SET status = 1 WHERE id IN (8, 15, 17); -- Setup a non-lost, maxfines circ +-- Setup a non-lost, checked-in, overdue, partially-paid circ UPDATE action.circulation SET xact_start = '2014-05-14 08:39:13.070326-04', due_date = '2014-05-21 23:59:59-04', @@ -81,8 +82,12 @@ UPDATE action.circulation SET checkin_lib = NULL, checkin_time = NULL, checkin_scan_time = NULL -WHERE id = 11; +WHERE id IN (11,18); UPDATE asset.copy SET status = 1 WHERE id = 12; +UPDATE action.circulation SET + max_fine = '5.00' +WHERE id = 18; +UPDATE asset.copy SET status = 0 WHERE id = 19; -- Create LOST and overdue fines @@ -140,7 +145,13 @@ INSERT INTO money.billing (id, xact, billing_ts, voided, voider, void_time, amou (DEFAULT, 16, '2014-05-26 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), (DEFAULT, 16, '2014-05-27 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), (DEFAULT, 16, '2014-05-28 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), - -- XACT 10 must be last, because we use CURRVAL() to put their IDs in the account adjustments + (DEFAULT, 17, '2014-05-28 08:39:13.070326-04', true, 1, '2014-05-28 09:39:13.070326-04', 50.00, 'Lost Materials', 3, 'SYSTEM GENERATED'), + (DEFAULT, 18, '2014-05-22 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), + (DEFAULT, 18, '2014-05-23 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), + (DEFAULT, 18, '2014-05-24 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), + -- XACTs 10 and 18 must be last, because we use CURRVAL() to put their IDs in the account adjustments + (DEFAULT, 18, '2014-05-25 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), + (DEFAULT, 18, '2014-05-26 23:59:59-04', false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), (DEFAULT, 10, (DATE(NOW() - '9 days'::interval) || ' 23:59:59')::TIMESTAMP, false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), (DEFAULT, 10, (DATE(NOW() - '8 days'::interval) || ' 23:59:59')::TIMESTAMP, false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), (DEFAULT, 10, (DATE(NOW() - '7 days'::interval) || ' 23:59:59')::TIMESTAMP, false, NULL, NULL, 0.10, 'Overdue materials', 1, 'System Generated Overdue Fine'), @@ -152,6 +163,8 @@ INSERT INTO money.billing (id, xact, billing_ts, voided, voider, void_time, amou INSERT INTO money.account_adjustment (id, xact, payment_ts, voided, amount, note, amount_collected, accepting_usr, billing) VALUES + (DEFAULT, 18, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 9), + (DEFAULT, 18, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 8), (DEFAULT, 10, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 7), (DEFAULT, 10, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 6), (DEFAULT, 10, NOW() - '3 days'::interval, false, 0.10, '', 0.10, 1, CURRVAL('money.billing_id_seq') - 5), @@ -163,7 +176,9 @@ INSERT INTO money.account_adjustment (id, xact, payment_ts, voided, amount, note INSERT INTO money.cash_payment (id, xact, payment_ts, voided, amount, note, amount_collected, accepting_usr, cash_drawer) VALUES (DEFAULT, 8, NOW() - '30 minutes'::interval, false, 50.00, 'LOST payment', 50.00, 1, 51), (DEFAULT, 9, NOW() - '2 hours'::interval, false, 50.00, 'LOST payment', 50.00, 1, 51), - (DEFAULT, 10, NOW() - '2 days'::interval, false, 10.00, 'Partial LOST payment', 10.00, 1, 51); + (DEFAULT, 10, NOW() - '2 days'::interval, false, 10.00, 'Partial LOST payment', 10.00, 1, 51), + (DEFAULT, 17, NOW() - '2 days'::interval, false, 10.00, 'Partial LOST payment', 10.00, 1, 51), + (DEFAULT, 18, NOW() - '2 days'::interval, false, 0.10, 'Partial overdue payment', 0.20, 1, 51); -- if rerunning, make sure our mangled bills have the right total in the summary UPDATE money.materialized_billable_xact_summary SET balance_owed = 50.00 @@ -176,3 +191,7 @@ UPDATE money.materialized_billable_xact_summary SET balance_owed = 40.00 WHERE id = 10; UPDATE money.materialized_billable_xact_summary SET balance_owed = 0.70 WHERE id = 11; +UPDATE money.materialized_billable_xact_summary SET balance_owed = -10.00 + WHERE id = 17; +UPDATE money.materialized_billable_xact_summary SET balance_owed = 0.20 + WHERE id = 18; diff --git a/Open-ILS/tests/datasets/sql/neg_bal_testing_reset.sql b/Open-ILS/tests/datasets/sql/neg_bal_testing_reset.sql index 94149e0c00..1ba9715af8 100644 --- a/Open-ILS/tests/datasets/sql/neg_bal_testing_reset.sql +++ b/Open-ILS/tests/datasets/sql/neg_bal_testing_reset.sql @@ -7,8 +7,8 @@ BEGIN; -- Once both files are run, the tests should succeed again. -- clear bills and payments for our test circs -DELETE FROM money.billing WHERE xact <= 16; -DELETE FROM money.payment WHERE xact <= 16; +DELETE FROM money.billing WHERE xact <= 18; +DELETE FROM money.payment WHERE xact <= 18; -- clear any non-stock settings -- XXX This will need adjusting if new stock settings are added, so -- 2.11.0