From 4b0e086007811aa79a69ecca80c054e048e6b409 Mon Sep 17 00:00:00 2001 From: Jeff Davis Date: Wed, 3 Feb 2016 15:03:49 -0800 Subject: [PATCH] LP#1533329: live tests for opt-in feature Signed-off-by: Jeff Davis Signed-off-by: Galen Charlton --- .../src/perlmods/live_t/12-lp1533329-opt-in.t | 162 ++++++++++++++++++ .../Pg/t/lp1533329-restrict-opt-in-setting.pg | 30 ++++ 2 files changed, 192 insertions(+) create mode 100644 Open-ILS/src/perlmods/live_t/12-lp1533329-opt-in.t create mode 100644 Open-ILS/src/sql/Pg/t/lp1533329-restrict-opt-in-setting.pg diff --git a/Open-ILS/src/perlmods/live_t/12-lp1533329-opt-in.t b/Open-ILS/src/perlmods/live_t/12-lp1533329-opt-in.t new file mode 100644 index 0000000000..cdf9019656 --- /dev/null +++ b/Open-ILS/src/perlmods/live_t/12-lp1533329-opt-in.t @@ -0,0 +1,162 @@ +#!perl + +use Test::More tests => 12; + +diag("Test checking for, creating, and restricting patron opt-in."); + +use constant WORKSTATION_NAME => 'BR1-test-12-lp1533329-opt-in.t'; +use constant WORKSTATION_LIB => 4; # BR1, a branch of SYS1 +use constant PATRON_LIB => 6; # BR3, a branch of SYS2 +use constant PATRON_SYS => 3; # SYS2 +use constant SYS_DEPTH => 1; # depth of "System" org type +use constant PATRON_BARCODE => '99999359616'; + +use strict; use warnings; + +use OpenILS::Utils::TestUtils; +use OpenILS::Utils::CStoreEditor qw/:funcs/; +use OpenILS::Utils::Fieldmapper; + +my $script = OpenILS::Utils::TestUtils->new(); +$script->bootstrap; + +our $U = "OpenILS::Application::AppUtils"; + +my $e = new_editor(xact => 1); +$e->init; + +# initialize a new aous object for insertion into the db +sub new_org_setting { + my ($org_unit, $name, $value) = @_; + my $set = Fieldmapper::actor::org_unit_setting->new(); + $set->org_unit($org_unit); + $set->name($name); + $set->value($value); + return $set; +} + +# do an opt-in check +sub opt_in_check { + my ($authtoken, $usr_id) = @_; + my $resp = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.org_unit_opt_in.check', + $authtoken, $usr_id); + return $resp; +} + +#---------------------------------------------------------------- +# 1. Login, register workstation, get authtoken. +#---------------------------------------------------------------- +$script->authenticate({ + username => 'admin', + password => 'demo123', + type => 'staff'}); +ok( + $script->authtoken, + 'Have an authtoken' +); +my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB); +ok( + ! ref $ws, + 'Registered a new workstation' +); +$script->logout(); +$script->authenticate({ + username => 'admin', + password => 'demo123', + type => 'staff', + workstation => WORKSTATION_NAME}); +ok( + $script->authtoken, + 'Have an authtoken associated with the workstation' +); + +#---------------------------------------------------------------- +# 2. Set org.patron_opt_boundary for SYS2, so that BR1 is outside +# the boundary. +#---------------------------------------------------------------- +$e->xact_begin; +my $boundary = new_org_setting(PATRON_SYS, 'org.patron_opt_boundary', SYS_DEPTH); +my $boundary_stat = $e->create_actor_org_unit_setting($boundary); +ok($boundary_stat, 'Opt boundary setting created successfully'); +$e->xact_commit; + +#---------------------------------------------------------------- +# 3. Check opt-in for test patron. It should return 0. +#---------------------------------------------------------------- +my $patron = $U->fetch_user_by_barcode(PATRON_BARCODE); +is( + opt_in_check($script->authtoken, $patron->id), + '0', + 'Opt-in check for non-opted-in patron correctly returned 0' +); + +#---------------------------------------------------------------- +# 4. Set org.restrict_opt_to_depth at SYS2, so that BR1 is +# outside SYS2's section of the tree at the specified depth (thus +# preventing opt-in). +#---------------------------------------------------------------- +$e->xact_begin; +my $restrict = new_org_setting(PATRON_SYS, 'org.restrict_opt_to_depth', SYS_DEPTH); +my $restrict_stat = $e->create_actor_org_unit_setting($restrict); +ok($restrict_stat, 'Opt restrict depth setting created successfully'); +$e->xact_commit; + +#---------------------------------------------------------------- +# 5. Check opt-in for test patron. It should return 2. +#---------------------------------------------------------------- +is( + opt_in_check($script->authtoken, $patron->id), + '2', + 'Opt-in check for patron at restricted opt-in library correctly returned 2' +); + +#---------------------------------------------------------------- +# 6. Remove the org.restrict_opt_to_depth setting for SYS2. +#---------------------------------------------------------------- +$e->xact_begin; +my $delete_restrict_stat = $e->delete_actor_org_unit_setting($restrict); +ok($delete_restrict_stat, 'Opt restrict depth setting deleted successfully'); +$e->xact_commit; + +#---------------------------------------------------------------- +# 7. Create opt-in for test patron. +#---------------------------------------------------------------- +my $opt_id = $U->simplereq( + 'open-ils.actor', + 'open-ils.actor.user.org_unit_opt_in.create', + $script->authtoken, $patron->id, WORKSTATION_LIB); +ok($opt_id, 'Patron successfully opted in'); + +#---------------------------------------------------------------- +# 8. Check opt-in for test patron. It should return 1. +#---------------------------------------------------------------- +is( + opt_in_check($script->authtoken, $patron->id), + '1', + 'Opt-in check for opted-in patron correctly returned 1' +); + +#---------------------------------------------------------------- +# 9. Delete opt-in. +#---------------------------------------------------------------- +my $opt = $U->simplereq( + 'open-ils.cstore', + 'open-ils.cstore.direct.actor.usr_org_unit_opt_in.retrieve', + $opt_id +); +$e->xact_begin; +my $delete_opt_stat = $e->delete_actor_usr_org_unit_opt_in($opt); +ok($delete_opt_stat, 'Opt-in deleted successfully'); +$e->xact_commit; + +#---------------------------------------------------------------- +# 10. Remove opt boundary setting. +#---------------------------------------------------------------- +$e->xact_begin; +my $delete_setting_stat = $e->delete_actor_org_unit_setting($boundary); +ok($delete_setting_stat, 'Opt boundary setting deleted successfully'); +$e->xact_commit; + + diff --git a/Open-ILS/src/sql/Pg/t/lp1533329-restrict-opt-in-setting.pg b/Open-ILS/src/sql/Pg/t/lp1533329-restrict-opt-in-setting.pg new file mode 100644 index 0000000000..1bd365e7c1 --- /dev/null +++ b/Open-ILS/src/sql/Pg/t/lp1533329-restrict-opt-in-setting.pg @@ -0,0 +1,30 @@ +\set ECHO +\set QUIET 1 +-- Turn off echo and keep things quiet. + +-- Format the output for nice TAP. +\pset format unaligned +\pset tuples_only true +\pset pager + +-- Revert all changes on failure. +\set ON_ERROR_ROLLBACK 1 +\set ON_ERROR_STOP true +\set QUIET 1 + +-- Load the TAP functions. +BEGIN; + +-- Plan the tests. +SELECT plan(1); + +-- Run the tests. + +SELECT isnt_empty( + 'SELECT * FROM config.org_unit_setting_type WHERE name = $$org.restrict_opt_to_depth$$', + 'org.restrict_opt_to_depth exists' +); + +-- Finish the tests and clean up. +SELECT * FROM finish(); +ROLLBACK; -- 2.43.2