From f2020f0ab091f425708eaa49bf412e456df19064 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Tue, 25 Feb 2014 11:30:18 -0500 Subject: [PATCH] LP#800478 pgtap test to confirm error condition This test demonstrates a problem with acq.fund_transfer, where the final amounts in the allocation and transfer are incorrect. When the transfer is successful, mutiple rows are added to acq.fund_transfer and acq.fund_allocation. Accommodate those in the test. Signed-off-by: Bill Erickson --- Open-ILS/src/sql/Pg/t/acq_fund_transfer.pg | 78 ++++++++++++++++++++++++++++++ 1 file changed, 78 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/t/acq_fund_transfer.pg diff --git a/Open-ILS/src/sql/Pg/t/acq_fund_transfer.pg b/Open-ILS/src/sql/Pg/t/acq_fund_transfer.pg new file mode 100644 index 0000000000..a898af8247 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/acq_fund_transfer.pg @@ -0,0 +1,78 @@ +BEGIN; + +SELECT plan(2); + +INSERT INTO acq.funding_source (name, owner, currency_type, code) + VALUES ('FS1', 1, 'USD', 'FS1'); + +INSERT INTO acq.funding_source_credit (funding_source, amount, deadline_date ) +VALUES + ( + (SELECT id FROM acq.funding_source WHERE name = 'FS1'), + 300, + NOW() + '1 DAY'::INTERVAL + ), ( + (SELECT id FROM acq.funding_source WHERE name = 'FS1'), + 500, + NULL -- no deadline_date ensures this credit will be used first + -- for transfers, giving us a predictable (testable) outcome. + ); + +INSERT INTO acq.fund (org, name, year, currency_type, active) VALUES + (1, 'F1', '2014', 'USD', TRUE), + (1, 'F2', '2014', 'USD', TRUE); + +-- LP#800478 +-- allocation must exceed transfer amount but be less than total credits +INSERT INTO acq.fund_allocation + (funding_source, fund, amount, allocator, note) +VALUES ( + (SELECT id FROM acq.funding_source WHERE name = 'FS1'), + (SELECT id FROM acq.fund WHERE name = 'F1'), + 700 , 1, 'test' +); + +-- LP#800478 +-- transfer amount must exceed any one funding source credit but be less +-- than the allocation amount +SELECT acq.transfer_fund( + (SELECT id FROM acq.fund WHERE name = 'F1'), 600, + (SELECT id FROM acq.fund WHERE name = 'F2'), 600, 1, 'test' +); + +-- fund transfer should show 600 moved between funds +-- 500 from the 500 credit, 100 from the 300 credit +SELECT is( + ( + SELECT ARRAY_AGG(dest_amount) FROM ( + SELECT dest_amount FROM acq.fund_transfer + WHERE + src_fund = (SELECT id FROM acq.fund WHERE name = 'F1') AND + dest_fund = (SELECT id FROM acq.fund WHERE name = 'F2') + ORDER BY dest_amount + ) dest_amount + ), + '{100.00,500.00}', + 'Transfer amount should be 100 and 500' +); + +-- destination fund should have a 600 allocation +SELECT is( + ( + SELECT ARRAY_AGG(amount) FROM ( + SELECT amount FROM acq.fund_allocation + WHERE + funding_source = + (SELECT id FROM acq.funding_source WHERE name = 'FS1') AND + fund = (SELECT id FROM acq.fund WHERE name = 'F2') + ORDER BY amount + ) amount + ), + '{100.00,500.00}', + 'Allocation amount should be 100 and 500' +); + +ROLLBACK; + + +-- vim: ft=sql -- 2.11.0