From 7f05e02bbebe6777e0389d2bec943e2bf376031a Mon Sep 17 00:00:00 2001 From: einhverfr Date: Fri, 10 Oct 2008 18:25:24 +0000 Subject: More unit tests for stored procs git-svn-id: https://ledger-smb.svn.sourceforge.net/svnroot/ledger-smb/trunk@2363 4979c152-3d1c-0410-bac9-87ea11338e46 --- sql/modules/test/Account.sql | 122 +++++++++++++++++++++++++++++++++++++ sql/modules/test/Business_type.sql | 17 ++++++ sql/modules/test/admin.sql | 13 ++++ 3 files changed, 152 insertions(+) create mode 100644 sql/modules/test/Account.sql create mode 100644 sql/modules/test/Business_type.sql create mode 100644 sql/modules/test/admin.sql (limited to 'sql/modules/test') diff --git a/sql/modules/test/Account.sql b/sql/modules/test/Account.sql new file mode 100644 index 00000000..d2f1545d --- /dev/null +++ b/sql/modules/test/Account.sql @@ -0,0 +1,122 @@ +BEGIN; +\i Base.sql + + +INSERT INTO chart (description, charttype, category, accno) +VALUES ('TEST testing 1', 'A', 'A', '00001'); + +INSERT INTO chart (description, charttype, category, accno) +VALUES ('TEST testing 2', 'A', 'A', '00002'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP 1', 'A', 'L', '00003', 'AP'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP 2', 'A', 'L', '00004', 'AP'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AR 1', 'A', 'A', '00005', 'AR'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AR 2', 'A', 'A', '00006', 'AR'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AR PAID 1', 'A', 'A', '00007', 'AR_paid'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AR PAID 2', 'A', 'A', '00008', 'AR_paid1'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AR PAID 3', 'A', 'A', '00009', 'IC_tax:AR_paid'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AR PAID 4 INVALID', 'A', 'A', '00010', 'AR_p'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP PAID 1', 'A', 'A', '00011', 'AP_paid'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP PAID 2', 'A', 'A', '00012', 'AP_paid1'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP PAID 3', 'A', 'A', '00013', 'IC_tax:AP_paid'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP PAID 4 INVALID', 'A', 'A', '00014', 'AP_p'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 1', 'A', 'A', '00015', 'AP_overpayment'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 2', 'A', 'A', '00016', 'AP_overpayment1'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 3', 'A', 'A', '00017', 'IC_tax:AP_overpayment'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 4 INVALID', 'A', 'A', '00018', 'AP_overp'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 1', 'A', 'A', '00019', 'AR_overpayment'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 2', 'A', 'A', '00020', 'AR_overpayment1'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 3', 'A', 'A', '00021', 'IC_tax:AR_overpayment'); + +INSERT INTO chart (description, charttype, category, accno, link) +VALUES ('TEST AP Overpayment 4 INVALID', 'A', 'A', '00022', 'AR_overp'); + +INSERT INTO test_result(test_name, success) +VALUES ('Accounts created', currval('chart_id_seq') is not null); + +INSERT INTO ap (invnumber, netamount, amount) VALUES ('TEST', '0', '0'); +INSERT INTO acc_trans (trans_id, chart_id, amount) +VALUES (currval('id')::int, currval('chart_id_seq')::int, '0'); + +INSERT INTO test_result(test_name, success) +VALUES ('Chart 1 is orphaned', account_is_orphaned((select id from chart where description = 'TEST testing 1'))); + +INSERT INTO test_result(test_name, success) +VALUES ('Chart 2 is not orphaned', account_is_orphaned(currval('chart_id_seq')::int) is false); + +INSERT INTO test_result(test_name, success) +SELECT 'All Test Accounts Exist', count(*) = 22 FROM chart_list_all() +where accno like '0%' AND description LIKE 'TEST%'; + +INSERT INTO test_result(test_name, success) +SELECT 'List AR Cash Test Accounts', count(*) = 3 FROM chart_list_cash(2) +where accno like '0%' AND description LIKE 'TEST%'; + +INSERT INTO test_result(test_name, success) +SELECT 'List AP Cash Test Accounts', count(*) = 3 FROM chart_list_cash(1) +where accno like '0%' AND description LIKE 'TEST%'; + +INSERT INTO test_result(test_name, success) +SELECT 'List AP Overpayment Accts', count(*) = 3 FROM chart_list_overpayment(1) +where accno like '0%' AND description LIKE 'TEST%'; + +INSERT INTO test_result(test_name, success) +SELECT 'List AR Overpayment Accts', count(*) = 3 FROM chart_list_overpayment(2) +where accno like '0%' AND description LIKE 'TEST%'; + +INSERT INTO test_result(test_name, success) +SELECT 'Test AP Accounts Are Found', count(*) = 2 FROM chart_get_ar_ap(1) +where accno like '0%' AND description LIKE 'TEST%'; + +INSERT INTO test_result(test_name, success) +SELECT 'Test AR Accounts Are Found', count(*) = 2 FROM chart_get_ar_ap(2) +where accno like '0%' AND description LIKE 'TEST%'; + +SELECT * FROM test_result; + +SELECT (select count(*) from test_result where success is true) +|| ' tests passed and ' +|| (select count(*) from test_result where success is not true) +|| ' failed' as message; + +\echo This currently fails 2 tests due to some confusion as to +\echo account_is_orphaned is supposed to do. + +ROLLBACK; diff --git a/sql/modules/test/Business_type.sql b/sql/modules/test/Business_type.sql new file mode 100644 index 00000000..461537a3 --- /dev/null +++ b/sql/modules/test/Business_type.sql @@ -0,0 +1,17 @@ +BEGIN; +\i Base.sql + +INSERT INTO business (description) values ('testing'); + +INSERT INTO test_result (test_name, success) +SELECT 'Business Class Inserted', count(*) > 0 from business_type__list() +WHERE description = 'testing'; + +SELECT * FROM test_result; + +SELECT (select count(*) from test_result where success is true) +|| ' tests passed and ' +|| (select count(*) from test_result where success is not true) +|| ' failed' as message; + +ROLLBACK; diff --git a/sql/modules/test/admin.sql b/sql/modules/test/admin.sql new file mode 100644 index 00000000..0b8eb1b2 --- /dev/null +++ b/sql/modules/test/admin.sql @@ -0,0 +1,13 @@ +BEGIN; +\i Base.sql + +\echo no tests yet! + +SELECT * FROM test_result; + +SELECT (select count(*) from test_result where success is true) +|| ' tests passed and ' +|| (select count(*) from test_result where success is not true) +|| ' failed' as message; + +ROLLBACK; -- cgit v1.2.3