]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/live_t/0852.prox_adjust.pg
683be42c3e5afd0f0ebe8874a9dce9aac0a9407e
[Evergreen.git] / Open-ILS / src / sql / Pg / live_t / 0852.prox_adjust.pg
1 \set ECHO
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 \set QUIET 1
14
15 -- let's do this thing
16 BEGIN;
17
18 SELECT plan(7);
19
20 -- The effect of this will be rolled back, so don't worry.
21 DELETE FROM actor.org_unit_proximity_adjustment;
22
23 -- Tests in the directory where we are rely on stock and Concerto data being
24 -- loaded.
25 INSERT INTO actor.org_unit_proximity_adjustment (
26     item_circ_lib, hold_pickup_lib, absolute_adjustment, prox_adjustment
27 ) VALUES (2, 2, true, 0);
28
29 SELECT is(
30     (SELECT pickup_lib = 5 FROM action.hold_request WHERE id = 3),
31     TRUE,
32     'Data suitable for test: hold #3 has pickup_lib 5'
33 );
34
35 SELECT is(
36     (SELECT pickup_lib = 9 FROM action.hold_request WHERE id = 4),
37     TRUE,
38     'Data suitable for test: hold #4 has pickup_lib 9'
39 );
40
41 SELECT is(
42     (SELECT circ_lib = 4 FROM asset.copy WHERE id = 2884),
43     TRUE,
44     'Data suitable for test: copy #2884 has circ_lib 4'
45 );
46
47 SELECT is(
48     (SELECT aou.parent_ou = 2 AND aout.depth = 2
49         FROM actor.org_unit aou
50         JOIN actor.org_unit_type aout ON (aout.id = aou.ou_type)
51         WHERE aou.id = 5),
52     TRUE,
53     'Data suitable for test: ou #5 has parent_ou 2 and depth 2'
54 );
55
56 SELECT is(
57     (SELECT aou.parent_ou <> 2 AND aout.depth >= 2
58         FROM actor.org_unit aou
59         JOIN actor.org_unit_type aout ON (aout.id = aou.ou_type)
60         WHERE aou.id = 9),
61     TRUE,
62     'Data suitable for test: ou #9 doesn''t have parent_ou 2, does have depth at least 2'
63 );
64         
65 SELECT is(
66     action.hold_copy_calculated_proximity (3, 2884)::INT,
67     0,
68     'Org unit proximity adjustment takes effect when it should'
69 );
70
71 SELECT is(
72     action.hold_copy_calculated_proximity (4, 2884)::INT,
73     5,
74     '(regression test) Org unit proximity adjustment doesn''t take effect when it shouldn''t'
75 );
76
77 SELECT * FROM finish();
78 ROLLBACK;
79