3 use Test::More tests => 12;
5 diag("Test checking for, creating, and restricting patron opt-in.");
7 use constant WORKSTATION_NAME => 'BR1-test-12-lp1533329-opt-in.t';
8 use constant WORKSTATION_LIB => 4; # BR1, a branch of SYS1
9 use constant PATRON_LIB => 6; # BR3, a branch of SYS2
10 use constant PATRON_SYS => 3; # SYS2
11 use constant SYS_DEPTH => 1; # depth of "System" org type
12 use constant PATRON_BARCODE => '99999359616';
14 use strict; use warnings;
16 use OpenILS::Utils::TestUtils;
17 use OpenILS::Utils::CStoreEditor qw/:funcs/;
18 use OpenILS::Utils::Fieldmapper;
20 my $script = OpenILS::Utils::TestUtils->new();
23 our $U = "OpenILS::Application::AppUtils";
25 my $e = new_editor(xact => 1);
28 # initialize a new aous object for insertion into the db
30 my ($org_unit, $name, $value) = @_;
31 my $set = Fieldmapper::actor::org_unit_setting->new();
32 $set->org_unit($org_unit);
39 my $resp = $U->simplereq(
41 'open-ils.actor.user.org_unit_opt_in.enabled'
48 my ($authtoken, $usr_id) = @_;
49 my $resp = $U->simplereq(
51 'open-ils.actor.user.org_unit_opt_in.check',
56 unless(opt_in_enabled()) {
57 BAIL_OUT('cannot test opt-in unless enabled in opensrf.xml');
60 #----------------------------------------------------------------
61 # 1. Login, register workstation, get authtoken.
62 #----------------------------------------------------------------
63 $script->authenticate({
65 password => 'demo123',
71 my $ws = $script->register_workstation(WORKSTATION_NAME,WORKSTATION_LIB);
74 'Registered a new workstation'
77 $script->authenticate({
79 password => 'demo123',
81 workstation => WORKSTATION_NAME});
84 'Have an authtoken associated with the workstation'
87 #----------------------------------------------------------------
88 # 2. Set org.patron_opt_boundary for SYS2, so that BR1 is outside
90 #----------------------------------------------------------------
92 my $boundary = new_org_setting(PATRON_SYS, 'org.patron_opt_boundary', SYS_DEPTH);
93 my $boundary_stat = $e->create_actor_org_unit_setting($boundary);
94 ok($boundary_stat, 'Opt boundary setting created successfully');
97 #----------------------------------------------------------------
98 # 3. Check opt-in for test patron. It should return 0.
99 #----------------------------------------------------------------
100 my $patron = $U->fetch_user_by_barcode(PATRON_BARCODE);
102 opt_in_check($script->authtoken, $patron->id),
104 'Opt-in check for non-opted-in patron correctly returned 0'
107 #----------------------------------------------------------------
108 # 4. Set org.restrict_opt_to_depth at SYS2, so that BR1 is
109 # outside SYS2's section of the tree at the specified depth (thus
110 # preventing opt-in).
111 #----------------------------------------------------------------
113 my $restrict = new_org_setting(PATRON_SYS, 'org.restrict_opt_to_depth', SYS_DEPTH);
114 my $restrict_stat = $e->create_actor_org_unit_setting($restrict);
115 ok($restrict_stat, 'Opt restrict depth setting created successfully');
118 #----------------------------------------------------------------
119 # 5. Check opt-in for test patron. It should return 2.
120 #----------------------------------------------------------------
122 opt_in_check($script->authtoken, $patron->id),
124 'Opt-in check for patron at restricted opt-in library correctly returned 2'
127 #----------------------------------------------------------------
128 # 6. Remove the org.restrict_opt_to_depth setting for SYS2.
129 #----------------------------------------------------------------
131 my $delete_restrict_stat = $e->delete_actor_org_unit_setting($restrict);
132 ok($delete_restrict_stat, 'Opt restrict depth setting deleted successfully');
135 #----------------------------------------------------------------
136 # 7. Create opt-in for test patron.
137 #----------------------------------------------------------------
138 my $opt_id = $U->simplereq(
140 'open-ils.actor.user.org_unit_opt_in.create',
141 $script->authtoken, $patron->id, WORKSTATION_LIB);
142 ok($opt_id, 'Patron successfully opted in');
144 #----------------------------------------------------------------
145 # 8. Check opt-in for test patron. It should return 1.
146 #----------------------------------------------------------------
148 opt_in_check($script->authtoken, $patron->id),
150 'Opt-in check for opted-in patron correctly returned 1'
153 #----------------------------------------------------------------
155 #----------------------------------------------------------------
156 my $opt = $U->simplereq(
158 'open-ils.cstore.direct.actor.usr_org_unit_opt_in.retrieve',
162 my $delete_opt_stat = $e->delete_actor_usr_org_unit_opt_in($opt);
163 ok($delete_opt_stat, 'Opt-in deleted successfully');
166 #----------------------------------------------------------------
167 # 10. Remove opt boundary setting.
168 #----------------------------------------------------------------
170 my $delete_setting_stat = $e->delete_actor_org_unit_setting($boundary);
171 ok($delete_setting_stat, 'Opt boundary setting deleted successfully');