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 TESTMESSAGE_ZERO => '0',
24 PROFILE => 2, #patrons
27 ### Fields that can be invalidated
33 my @fields = ('email','day_phone','evening_phone','other_phone');
34 ### Notification data, field index 0 is the penalty type code
36 email => [ 31,'nouser1@evergreen-ils.test','nouser2@evergreen-ils.test',
37 'nouser3@evergreen-ils.test','nouser4@example.com',
38 'nouser5@example.test'],
39 day_phone => [32,'218-555-0177','218-555-0129','218-555-0110','218-555-0196','218-555-0181'],
40 evening_phone => [33,'701-555-0130','701-555-0104','701-555-0155','701-555-0156','701-555-0143'],
41 other_phone => [34,'612-555-0111','612-555-0115','612-555-0157','612-555-0162','612-555-0192'],
44 ### Options for invalidation
46 # Penalty Org Unit -- ignore
47 # Notification string - invalidates all occurences of that type of notification.
50 # We are deliberately NOT using the admin user to check for a perm failure.
52 username => 'br1mtownsend',
53 password => 'maryt1234',
57 sub remove_penalty_from_patron {
60 #Fetch the ausp object, we have aump
61 my $ausp = $U->simplereq(
63 'open-ils.pcrud.search.ausp.atomic',
65 {id => $penalty->id() }
68 #Use the ausp to remove the penalty
71 'open-ils.actor.user.penalty.remove',
78 sub set_notifications {
81 $user->email($data{email}[$i]);
82 $user->day_phone($data{day_phone}[$i]);
83 $user->evening_phone($data{evening_phone}[$i]);
84 $user->other_phone($data{other_phone}[$i]);
85 $user->ischanged(1); ## Has to be included or update won't happen
87 my $resp = $U->simplereq(
89 'open-ils.actor.patron.update',
98 my ($userid,$type,$note,$ou,$search) = @_;
99 my $respi = $U->simplereq(
101 'open-ils.actor.invalidate.'.$type,
112 my ($userid,$note,$ou,$search) = @_;
115 my $respi = invalidate($userid,$_,$note,$ou, defined($search) ? $data{$_}[$search] : undef);
116 is($respi->{textcode},'SUCCESS',$_.' Invalidation was a success');
120 sub check_all_penalties {
121 my ($userid,$note,$ou,$search,$i) = @_;
124 my $respi = check_penalty($userid,$_,$note,$ou,
125 defined($search) ? $data{$_}[$search] : undef,$i);
132 my ($userid,$type,$note,$ou,$search,$i) = @_;
134 my $code = $data{$type}[0]; #Penalty Type Code
135 my $ausp = $U->simplereq(
137 'open-ils.pcrud.search.aump.atomic',
139 {usr => $userid, standing_penalty => $code, stop_date => undef },
143 my $penalty = $ausp->[0];
144 #print ref($penalty)."\n";
145 my $message = $data{$type}[$i].(defined($note) ? ' '.$note : '');
147 isa_ok($penalty, 'Fieldmapper::actor::usr_message_penalty', 'User Penalty Found -- '.$type);
148 is($penalty->message(), $message, $type.' penalty note matches expected format.');
151 ok( ! ref (remove_penalty_from_patron($penalty)), $type.' invalid notification penalty pemoved');
156 my $authtoken = $script->authenticate($credentials);
160 ) or BAIL_OUT('Must log in');
162 # Get a cstore editor for later use.
163 my $editor = $script->editor(authtoken=>$script->authtoken);
166 # Find a patron to use.
167 my $aus = $U->simplereq(
169 'open-ils.pcrud.search.au.atomic',
171 {profile => PROFILE, active => 't', home_ou => BR1_ID },
174 ok(@{$aus} == 5, 'Found 5 patrons');
175 my $user = $aus->[0];
178 'Fieldmapper::actor::user',
180 ) or BAIL_OUT('Patron not found');
183 my $resp = set_notifications($user,1);
184 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 1');
186 #print Dumper($resp);
190 $resp = set_notifications($user,2);
191 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 2');
193 ## Users 3,4,5 have the same notifications set
195 $resp = set_notifications($user,3);
196 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 3');
199 $resp = set_notifications($user,3);
200 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 4');
203 $resp = set_notifications($user,3);
204 isa_ok($resp, 'Fieldmapper::actor::user', 'Notifications added patron 5');
206 #Invalidate all notifications for user 1 - default settings
207 diag("Patron 1 - default invalidate settings");
209 invalidate_all($user->id(),undef,$user->home_ou(),undef);
211 #Invalidate all notifications for user 2 - added note
212 diag("Patron 2 - Added note");
214 invalidate_all($user->id(),TESTMESSAGE_ZERO,$user->home_ou(),undef);
216 #Invalidate notifications for users 3,4,5 - using search method with test message
217 diag("Patron 3,4,5 - Added note - same contact info");
219 invalidate_all(undef,TESTMESSAGE,$user->home_ou(),3); #Search is index to notification data
222 ## Check and clear standing penalties
223 diag("Patron 1 - default invalidate settings");
225 check_all_penalties($user->id(),undef,$user->home_ou(),undef,1);
227 diag("Patron 2 - Added note");
229 check_all_penalties($user->id(),TESTMESSAGE_ZERO,$user->home_ou(),undef,2);
231 diag("Patron 3 - Added note - same contact info");
233 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
235 diag("Patron 4 - Added note - same contact info");
237 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
239 diag("Patron 5 - Added note - same contact info");
241 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
244 $script->logout(); # Not a test, just to be pedantic.