LP#1251415: Juv-to-adult live test
authorBill Erickson <berickxx@gmail.com>
Fri, 14 Aug 2015 14:54:31 +0000 (10:54 -0400)
committerGalen Charlton <gmc@esilibrary.com>
Wed, 4 Nov 2015 21:56:45 +0000 (21:56 +0000)
Confirms org unit setting takes precedence and deleted users are
ignored.

Signed-off-by: Bill Erickson <berickxx@gmail.com>
Signed-off-by: Galen Charlton <gmc@esilibrary.com>
Open-ILS/src/perlmods/live_t/10-lp1251415_udpate_juv.t [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/live_t/10-lp1251415_udpate_juv.t b/Open-ILS/src/perlmods/live_t/10-lp1251415_udpate_juv.t
new file mode 100644 (file)
index 0000000..2425503
--- /dev/null
@@ -0,0 +1,105 @@
+#!perl
+
+use Test::More tests => 8;
+
+diag("Test juv-to-adult batch updater.");
+
+use strict; use warnings;
+
+use constant USER_ID => 2;
+
+use OpenILS::Utils::TestUtils;
+use OpenILS::Utils::CStoreEditor qw/:funcs/;
+use OpenILS::Utils::Fieldmapper;
+
+my $script = OpenILS::Utils::TestUtils->new();
+$script->bootstrap;
+
+my $e = new_editor(xact => 1);
+$e->init;
+
+# -------------
+# User is 19 years old.  Juv-to-adult with 18 years should clear the flag.
+
+my $user = $e->retrieve_actor_user(USER_ID);
+
+my $dt = DateTime->now;
+$dt->set_year($dt->year - 19);
+$user->dob($dt->strftime('%F'));
+$user->juvenile('t');
+my $stat = $e->update_actor_user($user);
+ok($stat, 'User update succeeded');
+$e->xact_commit;
+
+my $storage = $script->session('open-ils.storage');
+my $req = $storage->request(
+    'open-ils.storage.actor.user.juvenile_to_adult', '18 years');
+$req->recv;
+
+$e->xact_begin;
+$user = $e->retrieve_actor_user(USER_ID);
+is($user->juvenile, 'f', 'Junenile flag should be false');
+
+# -------------
+# User is 17 years old.  Juv-to-adult with 18 years should leave the flag.
+
+$dt = DateTime->now;
+$dt->set_year($dt->year - 17);
+$user->dob($dt->strftime('%F'));
+$user->juvenile('t');
+$stat = $e->update_actor_user($user);
+ok($stat, 'User update succeeded');
+$e->xact_commit;
+
+$req = $storage->request(
+    'open-ils.storage.actor.user.juvenile_to_adult', '18 years');
+$req->recv;
+
+$e->xact_begin;
+$user = $e->retrieve_actor_user(USER_ID);
+is($user->juvenile, 't', 'Junenile flag should be true');
+
+# -------------
+# User is 17 years old, but the juv org unit setting is 16,
+# so the flag should be cleared.
+
+my $aous = Fieldmapper::actor::org_unit_setting->new;
+$aous->org_unit(1);
+$aous->name('global.juvenile_age_threshold');
+$aous->value('"16 years"');
+$stat = $e->create_actor_org_unit_setting($aous);
+ok($stat, 'Org unit setting create successfully');
+$e->xact_commit;
+
+# passing "18 years", but the org unit setting should supercede it.
+$req = $storage->request(
+    'open-ils.storage.actor.user.juvenile_to_adult', '18 years');
+$req->recv;
+
+$user = $e->retrieve_actor_user(USER_ID);
+is($user->juvenile, 'f', 'Junenile flag should be false');
+
+# -------------
+# Delete the user.  No modification should occur.
+$user->juvenile('t');
+$user->deleted('t');
+$e->xact_begin;
+$stat = $e->update_actor_user($user);
+ok($stat, 'User successfully deleted');
+$e->xact_commit;
+
+# passing "18 years", but the org unit setting should supercede it.
+$req = $storage->request(
+    'open-ils.storage.actor.user.juvenile_to_adult', '18 years');
+$req->recv;
+
+$user = $e->retrieve_actor_user(USER_ID);
+is($user->juvenile, 't', 'Junenile flag should be left true after deletion');
+
+# for ease of repeating this test, delete the new org setting
+$e->xact_begin;
+$aous = $e->search_actor_org_unit_setting(
+    {name => 'global.juvenile_age_threshold', org_unit => 1})->[0];
+$e->delete_actor_org_unit_setting($aous);
+$e->commit;
+