From 6a9f2d238593efcf8e061bbd986477d03f8234b7 Mon Sep 17 00:00:00 2001 From: Bill Erickson Date: Mon, 28 Dec 2015 10:43:58 -0500 Subject: [PATCH] LP#1527342 Patron checkout history PGTAP tests Signed-off-by: Bill Erickson Signed-off-by: Kathy Lussier --- .../src/sql/Pg/live_t/user-circ-history.pg | 85 +++++++++++++++++++ 1 file changed, 85 insertions(+) create mode 100644 Open-ILS/src/sql/Pg/live_t/user-circ-history.pg diff --git a/Open-ILS/src/sql/Pg/live_t/user-circ-history.pg b/Open-ILS/src/sql/Pg/live_t/user-circ-history.pg new file mode 100644 index 0000000000..a78879bcc3 --- /dev/null +++ b/Open-ILS/src/sql/Pg/live_t/user-circ-history.pg @@ -0,0 +1,85 @@ +BEGIN; + +SELECT plan(5); + +-- at the time of writing, user '2' has zero circulations +-- in the default sample data set. +\set circ_usr 2 + +-- activate circ history tracking for a patron +INSERT INTO actor.usr_setting (usr, name, value) VALUES + (:circ_usr, 'history.circ.retention_start', '"2015-01-01"'); + +INSERT INTO action.circulation ( + usr, target_copy, circ_lib, circ_staff, renewal_remaining, + grace_period, duration, recurring_fine, max_fine, duration_rule, + recurring_fine_rule, max_fine_rule, due_date ) +VALUES ( + :circ_usr, 1, 4, 1, 2, '1 day', '14 days','0.10', '10', + 'default','default','default', now() + '14 days'::interval +); + +SELECT isnt_empty( + 'SELECT * FROM action.usr_circ_history WHERE usr = ' || :circ_usr, + 'Confirm a history row was inserted' +); + +SELECT is( + (SELECT checkin_time FROM action.usr_circ_history WHERE usr = :circ_usr), + NULL, + 'Confirm checkin_time is NULL' +); + +-- simulate a renewal +UPDATE action.circulation + SET checkin_time = NOW(), stop_fines = 'RENEW' + WHERE usr = :circ_usr; + +-- create the renewal +INSERT INTO action.circulation ( + usr, target_copy, circ_lib, circ_staff, renewal_remaining, + grace_period, duration, recurring_fine, max_fine, duration_rule, + recurring_fine_rule, max_fine_rule, due_date, parent_circ ) +VALUES ( + :circ_usr, 1, 4, 1, 2, '1 day', '14 days','0.10', '10', + 'default','default','default', '3001-01-01', + (SELECT id FROM action.circulation WHERE usr = :circ_usr) +); + +-- confirm due_date on the history object is updated to match the +-- due date of the renewal circ. +SELECT is( + (SELECT DATE(due_date) FROM action.usr_circ_history WHERE usr = :circ_usr), + '3001-01-01', + 'Confirm due_date matches renewal due date' +); + +UPDATE action.circulation SET checkin_time = NOW() + WHERE usr = :circ_usr AND stop_fines IS NULL; + +SELECT isnt( + (SELECT checkin_time FROM action.usr_circ_history WHERE usr = :circ_usr), + NULL, + 'Confirm checkin_time is set' +); + +-- Confirm no history is created users that are not opted in. +-- Assumes :circ_usr + 1 is a valid user id. +INSERT INTO action.circulation ( + usr, target_copy, circ_lib, circ_staff, renewal_remaining, + grace_period, duration, recurring_fine, max_fine, duration_rule, + recurring_fine_rule, max_fine_rule, due_date ) +VALUES ( + :circ_usr + 1, 1, 4, 1, 2, '1 day', '14 days','0.10', '10', + 'default','default','default', now() + '14 days'::interval +); + +SELECT is_empty( + 'SELECT * FROM action.usr_circ_history WHERE usr = ' || :circ_usr + 1, + 'Confirm no history is created' +); + + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK; -- 2.43.2