]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/sql/Pg/live_t/user-circ-history.pg
LP#1527342 Patron checkout history PGTAP tests
[Evergreen.git] / Open-ILS / src / sql / Pg / live_t / user-circ-history.pg
1 BEGIN;
2
3 SELECT plan(5);
4
5 -- at the time of writing, user '2' has zero circulations 
6 -- in the default sample data set.
7 \set circ_usr 2
8
9 -- activate circ history tracking for a patron
10 INSERT INTO actor.usr_setting (usr, name, value) VALUES 
11     (:circ_usr, 'history.circ.retention_start', '"2015-01-01"');
12
13 INSERT INTO action.circulation (
14     usr, target_copy, circ_lib, circ_staff, renewal_remaining,
15     grace_period, duration, recurring_fine, max_fine, duration_rule,
16     recurring_fine_rule, max_fine_rule, due_date )
17 VALUES (
18     :circ_usr, 1, 4, 1, 2, '1 day', '14 days','0.10', '10',
19    'default','default','default', now() + '14 days'::interval
20 );
21
22 SELECT isnt_empty(
23     'SELECT * FROM action.usr_circ_history WHERE usr = ' || :circ_usr,
24     'Confirm a history row was inserted'
25 );
26
27 SELECT is(
28     (SELECT checkin_time FROM action.usr_circ_history WHERE usr = :circ_usr),
29     NULL,
30     'Confirm checkin_time is NULL'
31 );
32
33 -- simulate a renewal
34 UPDATE action.circulation 
35     SET checkin_time = NOW(), stop_fines = 'RENEW' 
36     WHERE usr = :circ_usr;
37
38 -- create the renewal
39 INSERT INTO action.circulation (
40     usr, target_copy, circ_lib, circ_staff, renewal_remaining,
41     grace_period, duration, recurring_fine, max_fine, duration_rule,
42     recurring_fine_rule, max_fine_rule, due_date, parent_circ )
43 VALUES (
44     :circ_usr, 1, 4, 1, 2, '1 day', '14 days','0.10', '10',
45    'default','default','default', '3001-01-01',
46    (SELECT id FROM action.circulation WHERE usr = :circ_usr)
47 );
48
49 -- confirm due_date on the history object is updated to match the
50 -- due date of the renewal circ.
51 SELECT is(
52     (SELECT DATE(due_date) FROM action.usr_circ_history WHERE usr = :circ_usr),
53     '3001-01-01',
54     'Confirm due_date matches renewal due date'
55 );
56
57 UPDATE action.circulation SET checkin_time = NOW() 
58     WHERE usr = :circ_usr AND stop_fines IS NULL;
59
60 SELECT isnt(
61     (SELECT checkin_time FROM action.usr_circ_history WHERE usr = :circ_usr),
62     NULL,
63     'Confirm checkin_time is set'
64 );
65
66 -- Confirm no history is created users that are not opted in.
67 -- Assumes :circ_usr + 1 is a valid user id.
68 INSERT INTO action.circulation (
69     usr, target_copy, circ_lib, circ_staff, renewal_remaining,
70     grace_period, duration, recurring_fine, max_fine, duration_rule,
71     recurring_fine_rule, max_fine_rule, due_date )
72 VALUES (
73     :circ_usr + 1, 1, 4, 1, 2, '1 day', '14 days','0.10', '10',
74    'default','default','default', now() + '14 days'::interval
75 );
76
77 SELECT is_empty(
78     'SELECT * FROM action.usr_circ_history WHERE usr = ' || :circ_usr + 1,
79     'Confirm no history is created'
80 );
81
82
83 -- Finish the tests and clean up.
84 SELECT * FROM finish();
85 ROLLBACK;