3 use strict; use warnings;
4 use Test::More tests => 10;
5 use OpenILS::Utils::TestUtils;
6 use OpenILS::Utils::CStoreEditor qw/:funcs/;
7 use OpenILS::Application::AppUtils;
9 diag("Test patron triggered event log infrastructure");
11 use constant WORKSTATION_NAME => 'BR4-test-02-simple-circ.t'; # we'll just re-use this
12 use constant WORKSTATION_LIB => 7;
13 use constant ITEM_BARCODE => 'CONC70000345';
14 use constant ITEM_ID => 310;
16 my $script = OpenILS::Utils::TestUtils->new();
17 our $apputils = 'OpenILS::Application::AppUtils';
19 # -----------------------------------------------------------------------------
20 # 0. Let's get our auth token
21 # -----------------------------------------------------------------------------
23 $script->authenticate({
25 password => 'demo123',
27 workstation => WORKSTATION_NAME});
28 my $authtoken = $script->authtoken;
31 'Have an authtoken associated with the workstation'
34 # -----------------------------------------------------------------------------
35 # 1. Let's create an easy A/T event definition template for circs
36 # -----------------------------------------------------------------------------
38 my $e = new_editor(xact => 1);
41 my $atevdef = Fieldmapper::action_trigger::event_definition->new;
44 $atevdef->name('circ event test');
45 $atevdef->hook('checkout');
46 $atevdef->validator('NOOP_True');
47 $atevdef->reactor('NOOP_True');
49 $atevdef->delay_field('xact_start');
50 $atevdef->group_field('usr');
51 $atevdef->context_usr_path('usr');
52 $atevdef->context_library_path('circ_lib');
53 $atevdef->context_bib_path('target_copy.call_number.record');
55 $e->create_action_trigger_event_definition( $atevdef );
58 my $defs = $e->search_action_trigger_event_definition({name => 'circ event test'});
59 is(scalar(@$defs), 1, 'Successfully created atevdef');
61 my $def_id = $defs->[0]->id;
62 diag("def id = $def_id");
64 # ---------------------------------------------------------------------------------
65 # 3. Let's redo an earlier circulation from another test and get an event this time
66 # ---------------------------------------------------------------------------------
68 my $checkout_resp = $script->do_checkout({
70 barcode => ITEM_BARCODE});
74 'Checkout request returned a HASH'
77 $checkout_resp->{ilsevent},
79 'Checkout returned a SUCCESS event'
82 my $circ_id = $checkout_resp->{payload}->{circ}->id;
84 diag("circ id = $circ_id");
86 # -----------------------------------------------------------------------------
87 # 4. Let's find said event
88 # -----------------------------------------------------------------------------
90 sleep 2; # race condition
92 my $events = $e->search_action_trigger_event({event_def => $def_id, target => $circ_id});
93 is(scalar(@$events), 1, 'Found event');
95 # -----------------------------------------------------------------------------
96 # 5. Let's run action_trigger_runner to flesh said event
97 # -----------------------------------------------------------------------------
99 my $command = '/openils/bin/action_trigger_runner.pl --osrf-config /openils/conf/opensrf_core.xml --run-pending --verbose';
100 chomp(my $output = `$command`);
101 like($output, qr/run_pending: NON-GRANULAR/, 'action_trigger_runner.pl ran correctly');
103 # -----------------------------------------------------------------------------
104 # 6. Let's re-fetch the event and see if it's fleshed
105 # -----------------------------------------------------------------------------
107 sleep 2; # race condition
109 $events = $e->search_action_trigger_event({event_def => $def_id, target => $circ_id});
110 is(scalar(@$events), 1, 'Found event');
112 my $event = $events->[0];
114 is($event->context_user, 1, 'context_user is correct');
115 is($event->context_library, 7, 'context_library is correct');
116 is($event->context_bib, 10, 'context_bib is correct');
118 #use Data::Dumper::Perltidy;
119 #diag( Dumper($event) );