LP#1847680: live test for barcode completion
authorJeff Davis <jeff.davis@bc.libraries.coop>
Thu, 10 Oct 2019 23:01:06 +0000 (16:01 -0700)
committerJane Sandberg <sandbej@linnbenton.edu>
Tue, 21 Jul 2020 14:52:06 +0000 (07:52 -0700)
Signed-off-by: Jeff Davis <jeff.davis@bc.libraries.coop>
Signed-off-by: Jane Sandberg <sandbej@linnbenton.edu>
Open-ILS/src/perlmods/live_t/30-barcode-completion.t [new file with mode: 0644]

diff --git a/Open-ILS/src/perlmods/live_t/30-barcode-completion.t b/Open-ILS/src/perlmods/live_t/30-barcode-completion.t
new file mode 100644 (file)
index 0000000..84a815f
--- /dev/null
@@ -0,0 +1,99 @@
+#!perl
+
+use Test::More tests => 4;
+
+diag("Tests barcode completion");
+
+use strict; use warnings;
+use OpenILS::Utils::TestUtils;
+use OpenILS::Utils::CStoreEditor (':funcs');
+use OpenILS::Utils::Fieldmapper;
+our $U = "OpenILS::Application::AppUtils";
+
+my $script = OpenILS::Utils::TestUtils->new();
+$script->bootstrap();
+
+# test values
+my $org = 5; # test org: BR2
+my $bc_base = 'bc_complete_user';
+my $bc_prefix = 'JUSTATEST_';
+my $bc = $bc_prefix . $bc_base;
+
+# get authtoken for future use
+$script->authenticate({
+    username => 'admin',
+    password => 'demo123',
+    type => 'staff'
+});
+
+my $authtoken = $script->authtoken;
+ok($authtoken, 'was able to authenticate');
+
+# create test user
+my $new_user = Fieldmapper::actor::user->new();
+my $new_card = Fieldmapper::actor::card->new();
+
+$new_card->barcode($bc);
+$new_card->id(-1); # virtual ID
+$new_card->usr(undef);
+$new_card->isnew(1);
+
+$new_user->cards([ $new_card ]);
+$new_user->card($new_card);
+$new_user->usrname($bc);
+$new_user->passwd('dummypwd');
+$new_user->family_name('Doe');
+$new_user->first_given_name('Jane');
+$new_user->profile(2);
+$new_user->home_ou($org);
+$new_user->ident_type(1);
+$new_user->isnew(1);
+
+my $user = $U->simplereq(
+    'open-ils.actor',
+    'open-ils.actor.patron.update',
+    $authtoken,
+    $new_user
+);
+isa_ok($user, 'Fieldmapper::actor::user', 'new patron');
+
+# create barcode completion rule
+my $new_rule = Fieldmapper::config::barcode_completion->new();
+
+$new_rule->isnew(1);
+$new_rule->active('t');
+$new_rule->org_unit($org);
+$new_rule->prefix($bc_prefix);
+$new_rule->actor('t');
+$new_rule->asset('f'); # TODO test item barcodes too
+
+my $e = new_editor(xact => 1);
+$e->init;
+
+$e->xact_begin;
+$e->create_config_barcode_completion($new_rule);
+$e->xact_commit;
+
+my $bc_rule = $e->search_config_barcode_completion({
+    org_unit => 5, actor => 't', prefix => $bc_prefix
+})->[0];
+isa_ok($bc_rule, 'Fieldmapper::config::barcode_completion', 'Created and retrieved new barcode completion rule');
+
+my $get_barcodes = $U->simplereq(
+    'open-ils.actor',
+    'open-ils.actor.get_barcodes',
+    $authtoken, $org, 'actor', $bc_base
+);
+is($get_barcodes->[0]->{barcode}, $bc, 'Retrieved correct user with barcode completion');
+
+# clean up
+$U->simplereq(
+    'open-ils.actor',
+    'open-ils.actor.user.delete',
+    $authtoken,
+    $user->id()
+);
+$e->xact_begin;
+$e->delete_config_barcode_completion($bc_rule);
+$e->commit;
+