LP 1198465: Add pgtap tests for schema and data changes.
authorJason Stephenson <jason@sigio.com>
Fri, 24 Jan 2014 20:37:12 +0000 (15:37 -0500)
committerJason Stephenson <jason@sigio.com>
Thu, 20 Feb 2014 23:07:20 +0000 (18:07 -0500)
These tests only check that org_unit settings were properly added,
that the new money.void_payment table, its indexes and triggers were
created, that three columns were dropped from the money.billing
table, and that three functions exist.

Other tests for the view changes require test data and are beyond my
pgtap fu at the moment.  They will have to be added later.

Signed-off-by: Jason Stephenson <jason@sigio.com>
Signed-off-by: Kathy Lussier <klussier@masslnc.org>
Open-ILS/src/sql/Pg/t/lp1198465-conditional-negative-balances.pg [new file with mode: 0644]

diff --git a/Open-ILS/src/sql/Pg/t/lp1198465-conditional-negative-balances.pg b/Open-ILS/src/sql/Pg/t/lp1198465-conditional-negative-balances.pg
new file mode 100644 (file)
index 0000000..3fd9e88
--- /dev/null
@@ -0,0 +1,92 @@
+\set ECHO
+\set QUIET 1
+-- Turn off echo and keep things quiet.
+
+-- Format the output for nice TAP.
+\pset format unaligned
+\pset tuples_only true
+\pset pager
+
+-- Revert all changes on failure.
+\set ON_ERROR_ROLLBACK 1
+\set ON_ERROR_STOP true
+\set QUIET 1
+
+-- Load the TAP functions.
+BEGIN;
+
+-- Plan the tests.
+SELECT plan(21);
+
+-- Check for new org_unit settings.
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$bill.prohibit_negative_balance_default$$',
+    'bill.prohibit_negative_balance_default exists'
+);
+
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$bill.prohibit_negative_balance_on_overdues$$',
+    'bill.prohibit_negative_balance_on_overdues exists'
+);
+
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$bill.prohibit_negative_balance_on_lost$$',
+    'bill.prohibit_negative_balance_on_lost exists'
+);
+
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$bill.negative_balance_interval_default$$',
+    'bill.negative_balance_interval_default exists'
+);
+
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$bill.negative_balance_interval_on_overdues$$',
+    'bill.negative_balance_interval_on_overdues exists'
+);
+
+SELECT isnt_empty(
+    'SELECT * FROM config.org_unit_setting_type WHERE name = $$bill.negative_balance_interval_on_lost$$',
+    'bill.negative_balance_interval_on_lost exists'
+);
+
+-- Check for schema changes.
+-- Check for new table: money.void_payment, its indexes, and triggers.
+SELECT has_table('money', 'void_payment', 'money.void_payment table exists');
+SELECT has_index('money', 'void_payment', 'money_void_payment_xact_idx',
+       ARRAY['xact'], 'money_void_payment_xact_idx index exists');
+SELECT has_index('money', 'void_payment', 'money_void_payment_bill_idx',
+       ARRAY['billing'], 'money_void_payment_bill_idx index exists');
+SELECT has_index('money', 'void_payment', 'money_void_payment_payment_ts_idx',
+       ARRAY['payment_ts'], 'money_void_payment_payment_ts_idx index exists');
+SELECT has_index('money', 'void_payment', 'money_void_payment_accepting_usr_idx',
+       ARRAY['accepting_usr'], 'money_void_payment_accepting_usr_idx index exists');
+SELECT has_trigger('money', 'void_payment', 'mat_summary_add_tgr',
+       'mat_summary_add_tgr trigger exists');
+SELECT has_trigger('money', 'void_payment', 'mat_summary_upd_tgr',
+       'mat_summary_upd_tgr trigger exists');
+SELECT has_trigger('money', 'void_payment', 'mat_summary_del_tgr',
+       'mat_summary_del_tgr trigger exists');
+
+-- Check that columns were dropped from money.billing.
+SELECT hasnt_column('money', 'billing', 'voided',
+       'column voided dropped from money.billing');
+SELECT hasnt_column('money', 'billing', 'void_time',
+       'column void_time dropped from money.billing');
+SELECT hasnt_column('money', 'billing', 'voider',
+       'column voider dropped from money.billing');
+
+-- Make sure the view, money.billable_xact_with_void_summary, was dropped.
+SELECT hasnt_view('money', 'billable_xact_with_void_summary',
+       'view money.billable_xact_with_void_summary successfully dropped');
+
+-- Check for functions.
+SELECT has_function('money', 'materialized_summary_billing_add',
+       'function money.materialized_summary_billing_add exists');
+SELECT has_function('money', 'materialized_summary_billing_update',
+       'function money.materialized_summary_billing_update exists');
+SELECT has_function('money', 'materialized_summary_billing_del',
+       'function money.materialized_summary_billing_del exists');
+
+-- Finish the tests and clean up.
+SELECT * FROM finish();
+ROLLBACK;