3 -- Turn off echo and keep things quiet.
5 -- Format the output for nice TAP.
10 -- Revert all changes on failure.
11 \set ON_ERROR_ROLLBACK 1
12 \set ON_ERROR_STOP true
14 -- let's do this thing
17 -- putting tests in function to allow for variable reuse
18 CREATE OR REPLACE FUNCTION mtbs_test() RETURNS SETOF TEXT AS $$
23 RETURN QUERY SELECT plan(2);
25 SELECT max(mbx.id) INTO max_id
26 FROM money.billable_xact mbx
27 JOIN money.billing mb ON NOT mb.voided AND mb.xact = mbx.id;
29 RETURN QUERY SELECT is(
30 (SELECT DISTINCT ON (xact) billing_type FROM money.billing WHERE xact = max_id ORDER BY xact, billing_ts DESC),
31 (SELECT last_billing_type FROM money.transaction_billing_summary WHERE xact = max_id),
32 'mtbs has correct last billing type'
35 RETURN QUERY SELECT is(
36 (SELECT DISTINCT ON (xact) note FROM money.billing WHERE xact = max_id ORDER BY xact, billing_ts DESC),
37 (SELECT last_billing_note FROM money.transaction_billing_summary WHERE xact = max_id),
38 'mtbs has correct last billing note'
41 RETURN QUERY SELECT * FROM finish();