LP#1752334: (follow-up) adjust to allow "0" as a note
authorGalen Charlton <gmc@equinoxOLI.org>
Fri, 31 Mar 2023 13:43:53 +0000 (09:43 -0400)
committerGalen Charlton <gmc@equinoxOLI.org>
Fri, 31 Mar 2023 13:43:53 +0000 (09:43 -0400)
Also ignore the additional note parameter if all it has
are zero or more whitespace characters.

It's unlikely that a client would want to set the additional
note to "0", but it's nonetheless a good idea to distinguish
between difference versions of Perl's false value.

Signed-off-by: Galen Charlton <gmc@equinoxOLI.org>

Open-ILS/src/perlmods/lib/OpenILS/Utils/BadContact.pm
Open-ILS/src/perlmods/live_t/36-lp1752334-badcontact.t

index 78a5b4b..edacc92 100644 (file)
@@ -99,10 +99,15 @@ sub mark_users_contact_invalid {
         $usr_penalty->standing_penalty($penalty->id);
         $usr_penalty->staff($staff_id);
 
+        my $message = $_->$contact_type;
+        if (defined($addl_note) && $addl_note !~ /^\s*$/) {
+            $message .= ' ' . $addl_note;
+        }
+
         my ($result) = $U->simplereq('open-ils.actor', 'open-ils.actor.user.penalty.apply',
             $editor->authtoken,
             $usr_penalty,
-            { message => $addl_note ? $_->$contact_type.' '.$addl_note : $_->$contact_type }
+            { message => $message }
         );
 
         # FIXME: this perpetuates a bug; the patron editor UI doesn't handle these error states well
index f927227..c0ab921 100644 (file)
@@ -20,6 +20,7 @@ use constant {
     PHONE => '218-555-0177',
     EMAIL => 'nouser@evergreen-ils.test',
     TESTMESSAGE => '123456 TEST Invalidate Message',
+    TESTMESSAGE_ZERO => '0',
     PROFILE => 2, #patrons
 };
 
@@ -141,7 +142,7 @@ sub check_penalty {
 
     my $penalty = $ausp->[0];
     #print ref($penalty)."\n";
-    my $message = $data{$type}[$i].($note ? ' '.$note : '');
+    my $message = $data{$type}[$i].(defined($note) ? ' '.$note : '');
 
     isa_ok($penalty, 'Fieldmapper::actor::usr_message_penalty', 'User Penalty Found -- '.$type);
     is($penalty->message(), $message, $type.' penalty note matches expected format.');
@@ -210,7 +211,7 @@ invalidate_all($user->id(),undef,$user->home_ou(),undef);
 #Invalidate all notifications for user 2 - added note
 diag("Patron 2 - Added note");
 $user = $aus->[1];
-invalidate_all($user->id(),TESTMESSAGE,$user->home_ou(),undef);
+invalidate_all($user->id(),TESTMESSAGE_ZERO,$user->home_ou(),undef);
 
 #Invalidate notifications for users 3,4,5 - using search method with test message
 diag("Patron 3,4,5 - Added note - same contact info");
@@ -225,7 +226,7 @@ check_all_penalties($user->id(),undef,$user->home_ou(),undef,1);
 
 diag("Patron 2 - Added note");
 $user = $aus->[1];
-check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,2);
+check_all_penalties($user->id(),TESTMESSAGE_ZERO,$user->home_ou(),undef,2);
 
 diag("Patron 3 - Added note - same contact info");
 $user = $aus->[2];
@@ -240,4 +241,4 @@ $user = $aus->[4];
 check_all_penalties($user->id(),TESTMESSAGE,$user->home_ou(),undef,3);
 
 # Logout
-$script->logout(); # Not a test, just to be pedantic.
\ No newline at end of file
+$script->logout(); # Not a test, just to be pedantic.