]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/live_t/0959.schema.correct_mtbs_view.pg
LP#1206936 Stamping upgrade script; adding test
[Evergreen.git] / Open-ILS / src / sql / Pg / live_t / 0959.schema.correct_mtbs_view.pg
1 \set ECHO 'none'
2 \set QUIET 1
3 -- Turn off echo and keep things quiet.
4
5 -- Format the output for nice TAP.
6 \pset format unaligned
7 \pset tuples_only true
8 \pset pager
9
10 -- Revert all changes on failure.
11 \set ON_ERROR_ROLLBACK 1
12 \set ON_ERROR_STOP true
13
14 -- let's do this thing
15 BEGIN;
16
17 -- putting tests in function to allow for variable reuse
18 CREATE OR REPLACE FUNCTION mtbs_test() RETURNS SETOF TEXT AS $$
19 DECLARE
20         max_id bigint;
21 BEGIN
22
23 RETURN QUERY SELECT plan(2);
24
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;
28
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'
33 );
34
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'
39 );
40
41 RETURN QUERY SELECT * FROM finish();
42
43 END;
44 $$ LANGUAGE plpgsql;
45
46 SELECT mtbs_test();
47
48 ROLLBACK;