2 use strict; use warnings;
3 use Test::More tests => 80;
5 use OpenILS::Utils::TestUtils;
6 use OpenILS::Const qw(:const);
7 use OpenILS::Utils::Fieldmapper;
10 my $script = OpenILS::Utils::TestUtils->new();
13 my $U = 'OpenILS::Application::AppUtils';
15 diag("Test LP 1752334 BadContact");
20 PHONE => '218-555-0177',
21 EMAIL => 'nouser@evergreen-ils.test',
22 TESTMESSAGE => '123456 TEST Invalidate Message',
23 PROFILE => 2, #patrons
26 ### Fields that can be invalidated
32 my @fields = ('email','day_phone','evening_phone','other_phone');
33 ### Notification data, field index 0 is the penalty type code
35 email => [ 31,'nouser1@evergreen-ils.test','nouser2@evergreen-ils.test',
36 'nouser3@evergreen-ils.test','nouser4@example.com',
37 'nouser5@example.test'],
38 day_phone => [32,'218-555-0177','218-555-0129','218-555-0110','218-555-0196','218-555-0181'],
39 evening_phone => [33,'701-555-0130','701-555-0104','701-555-0155','701-555-0156','701-555-0143'],
40 other_phone => [34,'612-555-0111','612-555-0115','612-555-0157','612-555-0162','612-555-0192'],
43 ### Options for invalidation
45 # Penalty Org Unit -- ignore
46 # Notification string - invalidates all occurences of that type of notification.
49 # We are deliberately NOT using the admin user to check for a perm failure.
51 username => 'br1mtownsend',
52 password => 'maryt1234',
56 sub remove_penalty_from_patron {
59 #Fetch the ausp object, we have aump
60 my $ausp = $U->simplereq(
62 'open-ils.pcrud.search.ausp.atomic',
64 {id => $penalty->id() }
67 #Use the ausp to remove the penalty
70 'open-ils.actor.user.penalty.remove',
77 sub set_notifications {
80 $user->email($data{email}[$i]);
81 $user->day_phone($data{day_phone}[$i]);
82 $user->evening_phone($data{evening_phone}[$i]);
83 $user->other_phone($data{other_phone}[$i]);
84 $user->ischanged(1); ## Has to be included or update won't happen
86 my $resp = $U->simplereq(
88 'open-ils.actor.patron.update',
97 my ($userid,$type,$note,$ou,$search) = @_;
98 my $respi = $U->simplereq(
100 'open-ils.actor.invalidate.'.$type,
111 my ($userid,$note,$ou,$search) = @_;
114 my $respi = invalidate($userid,$_,$note,$ou, defined($search) ? $data{$_}[$search] : undef);
115 is($respi->{textcode},'SUCCESS',$_.' Invalidation was a success');
119 sub check_all_penalties {
120 my ($userid,$note,$ou,$search,$i) = @_;
123 my $respi = check_penalty($userid,$_,$note,$ou,
124 defined($search) ? $data{$_}[$search] : undef,$i);
131 my ($userid,$type,$note,$ou,$search,$i) = @_;
133 my $code = $data{$type}[0]; #Penalty Type Code
134 my $ausp = $U->simplereq(
136 'open-ils.pcrud.search.aump.atomic',
138 {usr => $userid, standing_penalty => $code, stop_date => undef },
142 my $penalty = $ausp->[0];
143 #print ref($penalty)."\n";
144 my $message = $data{$type}[$i].($note ? ' '.$note : '');
146 isa_ok($penalty, 'Fieldmapper::actor::usr_message_penalty', 'User Penalty Found -- '.$type);
147 is($penalty->message(), $message, $type.' penalty note matches expected format.');
150 ok( ! ref (remove_penalty_from_patron($penalty)), $type.' invalid notification penalty pemoved');
155 my $authtoken = $script->authenticate($credentials);
159 ) or BAIL_OUT('Must log in');
161 # Get a cstore editor for later use.
162 my $editor = $script->editor(authtoken=>$script->authtoken);
165 # Find a patron to use.
166 my $aus = $U->simplereq(
168 'open-ils.pcrud.search.au.atomic',
170 {profile => PROFILE, active => 't', home_ou => BR1_ID },
173 ok(@{$aus} == 5, 'Found 5 patrons');
174 my $user = $aus->[0];
177 'Fieldmapper::actor::user',
179 ) or BAIL_OUT('Patron not found');
182 my $resp = set_notifications($user,1);
183 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 1');
185 #print Dumper($resp);
189 $resp = set_notifications($user,2);
190 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 2');
192 ## Users 3,4,5 have the same notifications set
194 $resp = set_notifications($user,3);
195 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 3');
198 $resp = set_notifications($user,3);
199 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 4');
202 $resp = set_notifications($user,3);
203 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 5');
205 #Invalidate all notifications for user 1 - default settings
206 diag("Patron 1 - default invalidate settings");
208 invalidate_all($user->id(),undef,$user->home_ou(),undef);
210 #Invalidate all notifications for user 2 - added note
211 diag("Patron 2 - Added note");
213 invalidate_all($user->id(),TESTMESSAGE,$user->home_ou(),undef);
215 #Invalidate notifications for users 3,4,5 - using search method with test message
216 diag("Patron 3,4,5 - Added note - same contact info");
218 invalidate_all(undef,TESTMESSAGE,$user->home_ou(),3); #Search is index to notification data
221 ## Check and clear standing penalties
222 diag("Patron 1 - default invalidate settings");
224 check_all_penalties($user->id(),undef,$user->home_ou(),undef,1);
226 diag("Patron 2 - Added note");
228 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,2);
230 diag("Patron 3 - Added note - same contact info");
232 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
234 diag("Patron 4 - Added note - same contact info");
236 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
238 diag("Patron 5 - Added note - same contact info");
240 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
243 $script->logout(); # Not a test, just to be pedantic.