Skip to content

Instantly share code, notes, and snippets.

@stompro
Created March 7, 2023 14:01
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save stompro/2883dc9044520176a6e2eeaa6e5ba8f2 to your computer and use it in GitHub Desktop.
Save stompro/2883dc9044520176a6e2eeaa6e5ba8f2 to your computer and use it in GitHub Desktop.
/home/opensrf/Evergreen/Open-ILS/src/perlmods/live_t/zz-lp1752334-badcontact.t
#!perl
use strict; use warnings;
use Test::More tests => 7;
use OpenILS::Utils::TestUtils;
use OpenILS::Const qw(:const);
use OpenILS::Utils::Fieldmapper;
use Data::Dumper;
my $script = OpenILS::Utils::TestUtils->new();
$script->bootstrap();
my $U = 'OpenILS::Application::AppUtils';
diag("Test LP 1752334 BadContact");
use constant {
BR1_ID => 4,
BR3_ID => 6,
PHONE => '218-555-5555',
EMAIL => 'nouser@evergreen-ils.org',
PROFILE => 2, #patrons
};
# We are deliberately NOT using the admin user to check for a perm failure.
my $credentials = {
username => 'br1mtownsend',
password => 'maryt1234',
type => 'staff'
};
# Log in as staff.
my $authtoken = $script->authenticate($credentials);
ok(
$authtoken,
'Logged in'
) or BAIL_OUT('Must log in');
# Get a cstore editor for later use.
my $editor = $script->editor(authtoken=>$script->authtoken);
# Find a patron to use.
my $aus = $U->simplereq(
'open-ils.pcrud',
'open-ils.pcrud.search.au.atomic',
$authtoken,
{profile => PROFILE, active => 't', home_ou => BR1_ID },
{limit => 1}
);
my $user = $aus->[0];
isa_ok(
$user,
'Fieldmapper::actor::user',
'Found a patron'
) or BAIL_OUT('Patron not found');
#Set a phone number and email address
$user->email('sampleuser@evergreen-ils.org');
$user->day_phone('5555555555');
print Dumper($user);
my $resp = $U->simplereq(
'open-ils.actor',
'open-ils.actor.patron.update',
$authtoken,
$user
);
isa_ok($resp, 'Fieldmapper::actor::user', 'Email and Phone added');
print Dumper($resp);
############### Shows that email and phone values were not saved
exit;
#Invalidate day phone with no message
my $respi = $U->simplereq(
'open-ils.actor',
'open-ils.actor.invalidate.day_phone',
$authtoken,
$user->id(),
undef,
$user->home_ou()
);
print ref($respi)." - response\n";
#isa_ok($resp, 'OpenILS::Event', 'Event Returned');
is($respi->{textcode},'SUCCESS','day_phone Invalidation was a success');
#Invalidate email with a message
$respi = $U->simplereq(
'open-ils.actor',
'open-ils.actor.invalidate.email',
$authtoken,
$user->id(),
'Test Invalidate Message',
$user->home_ou()
);
#isa_ok($resp, 'OpenILS::Event', 'Event Returned');
is($respi->{textcode},'SUCCESS','email Invalidation was a success');
#Check the created penalties
#day_phone 32
my $ausp = $U->simplereq(
'open-ils.pcrud',
'open-ils.pcrud.search.aump.atomic',
$authtoken,
{usr => $user->id(), standing_penalty => '32' },
{limit => 1}
);
#print ref($ausp->[0])."\n";
isa_ok($ausp->[0], 'Fieldmapper::actor::usr_message_penalty', 'User Penalty Found -- day_phone');
is_ok($ausp->[0]->{message}, PHONE, 'Phone Note Correct');
#email 31
$ausp = $U->simplereq(
'open-ils.pcrud',
'open-ils.pcrud.search.aump.atomic',
$authtoken,
{usr => $user->id(), standing_penalty => '31' },
{limit => 1}
);
isa_ok($ausp->[0], 'Fieldmapper::actor::usr_message_penalty', 'User Penalty Found -- email');
is_ok($ausp->[0]->{message}, EMAIL, 'Email Note Correct - With Custom Note');
## Clean up the created standing penalties
# Logout
$script->logout(); # Not a test, just to be pedantic.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment