]> git.evergreen-ils.org Git - Evergreen.git/blob - Open-ILS/src/perlmods/live_t/32-lp1207533-triggered-events.t
LP1207533 patron triggered events log
[Evergreen.git] / Open-ILS / src / perlmods / live_t / 32-lp1207533-triggered-events.t
1 #!perl
2
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;
8
9 diag("Test patron triggered event log infrastructure");
10
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;
15
16 my $script = OpenILS::Utils::TestUtils->new();
17 our $apputils = 'OpenILS::Application::AppUtils';
18
19 # -----------------------------------------------------------------------------
20 # 0. Let's get our auth token
21 # -----------------------------------------------------------------------------
22
23 $script->authenticate({
24     username => 'admin',
25     password => 'demo123',
26     type => 'staff',
27     workstation => WORKSTATION_NAME});
28 my $authtoken = $script->authtoken;
29 ok(
30     $authtoken,
31     'Have an authtoken associated with the workstation'
32 );
33
34 # -----------------------------------------------------------------------------
35 # 1. Let's create an easy A/T event definition template for circs
36 # -----------------------------------------------------------------------------
37
38 my $e = new_editor(xact => 1);
39 $e->init;
40
41 my $atevdef = Fieldmapper::action_trigger::event_definition->new;
42 $atevdef->active(1);
43 $atevdef->owner(1);
44 $atevdef->name('circ event test');
45 $atevdef->hook('checkout');
46 $atevdef->validator('NOOP_True');
47 $atevdef->reactor('NOOP_True');
48 $atevdef->delay('0');
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');
54
55 $e->create_action_trigger_event_definition( $atevdef );
56 $e->commit;
57
58 my $defs = $e->search_action_trigger_event_definition({name => 'circ event test'});
59 is(scalar(@$defs), 1, 'Successfully created atevdef');
60
61 my $def_id = $defs->[0]->id;
62 diag("def id = $def_id");
63
64 # ---------------------------------------------------------------------------------
65 # 3. Let's redo an earlier circulation from another test and get an event this time
66 # ---------------------------------------------------------------------------------
67
68 my $checkout_resp = $script->do_checkout({
69     patron => 1,
70     barcode => ITEM_BARCODE});
71 is(
72     ref $checkout_resp,
73     'HASH',
74     'Checkout request returned a HASH'
75 );
76 is(
77     $checkout_resp->{ilsevent},
78     0,
79     'Checkout returned a SUCCESS event'
80 );
81
82 my $circ_id = $checkout_resp->{payload}->{circ}->id;
83
84 diag("circ id = $circ_id");
85  
86 # -----------------------------------------------------------------------------
87 # 4. Let's find said event
88 # -----------------------------------------------------------------------------
89
90 sleep 2; # race condition
91
92 my $events = $e->search_action_trigger_event({event_def => $def_id, target => $circ_id});
93 is(scalar(@$events), 1, 'Found event');
94
95 # -----------------------------------------------------------------------------
96 # 5. Let's run action_trigger_runner to flesh said event
97 # -----------------------------------------------------------------------------
98
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');
102
103 # -----------------------------------------------------------------------------
104 # 6. Let's re-fetch the event and see if it's fleshed
105 # -----------------------------------------------------------------------------
106
107 sleep 2; # race condition
108
109 $events = $e->search_action_trigger_event({event_def => $def_id, target => $circ_id});
110 is(scalar(@$events), 1, 'Found event');
111
112 my $event = $events->[0];
113
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');
117
118 #use Data::Dumper::Perltidy;
119 #diag( Dumper($event) );