2 use strict; use warnings;
3 use Test::More tests => 17;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
7 my $U = 'OpenILS::Application::AppUtils';
8 my $script = OpenILS::Utils::TestUtils->new();
10 diag("Test LP1929593 Wishlist: need separate permission for editing barcode");
15 WORKSTATION => 'BR1-lp1929593-ebarc'
18 # We are deliberately NOT using the admin user to check for a perm failure.
20 username => 'br1mtownsend',
21 password => 'maryt1234',
26 my $authtoken = $script->authenticate($credentials);
30 ) or BAIL_OUT('Must log in');
32 # Find or register workstation.
33 my $ws = $script->find_or_register_workstation(WORKSTATION, BR1_ID);
36 'Found or registered workstation'
37 ) or BAIL_OUT('Need Workstation');
46 # Login with workstation.
47 $credentials->{workstation} = WORKSTATION;
48 $credentials->{password} = 'maryt1234';
49 $authtoken = $script->authenticate($credentials);
52 'Logged in with workstation'
53 ) or BAIL_OUT('Must log in');
55 # Find available copy at BR1
56 my $acps = $U->simplereq(
58 'open-ils.pcrud.search.acp.atomic',
60 {circ_lib => BR1_ID, status => OILS_COPY_STATUS_AVAILABLE},
63 my $copy = $acps->[0];
66 'Fieldmapper::asset::copy',
67 'Got available copy from BR1'
70 sub test_barcode_rename_expecting_success {
73 diag('Testing re-barcoding of ' . $copy->barcode() . ', expecting successful re-barcoding.');
74 my $original_barcode = $copy->barcode();
77 my $result = $U->simplereq(
79 'open-ils.cat.update_copy_barcode',
82 'new' . $original_barcode
87 'open-ils.cat.update_copy_barcode indicates success'
90 # Double-check to be sure
91 $copy = $U->simplereq(
93 'open-ils.pcrud.retrieve.acp',
99 'new' . $original_barcode,
100 'Copy was indeed re-barcoded'
102 diag('Current barcode: ' . $copy->barcode());
105 $result = $U->simplereq(
107 'open-ils.cat.update_copy_barcode',
115 'open-ils.cat.update_copy_barcode indicates success'
118 # Double-check to be sure
119 $copy = $U->simplereq(
121 'open-ils.pcrud.retrieve.acp',
128 'Copy was indeed re-barcoded'
130 diag('Current barcode: ' . $copy->barcode());
133 diag('Testing when user has both UPDATE_COPY and UPDATE_COPY_BARCODE');
134 test_barcode_rename_expecting_success($copy);
139 diag('Changing ' . $from . ' permission to ' . $to);
141 # stateful cstore session
142 my $cstore_ses = $script->session('open-ils.cstore');
143 $cstore_ses->connect;
145 # Now let's fetch the $from perm
146 my $xact = $cstore_ses->request('open-ils.cstore.transaction.begin')->gather(1);
147 my $retrieve_req = $cstore_ses->request(
148 'open-ils.cstore.direct.permission.perm_list.search',
151 my $perm = $retrieve_req->gather(1);
155 "Fetched $from permission"
158 # now let's change the code
160 my $update_req = $cstore_ses->request(
161 'open-ils.cstore.direct.permission.perm_list.update',
164 my $update_resp = $update_req->gather(1);
168 'cstore update successful'
171 $cstore_ses->request('open-ils.cstore.transaction.commit')->gather(1);
172 $cstore_ses->disconnect();
175 changePermCode('UPDATE_COPY', 'WAS_UPDATE_COPY');
176 diag('Testing when user only has UPDATE_COPY_BARCODE');
177 test_barcode_rename_expecting_success($copy);
179 sub test_barcode_rename_expecting_failure {
182 diag('Testing re-barcoding of ' . $copy->barcode() . ', expecting unsuccessful re-barcoding.');
183 my $original_barcode = $copy->barcode();
186 my $result = $U->simplereq(
188 'open-ils.cat.update_copy_barcode',
191 'new' . $original_barcode
196 'open-ils.cat.update_copy_barcode indicates failure'
199 # Double-check to be sure
200 $copy = $U->simplereq(
202 'open-ils.pcrud.retrieve.acp',
209 'Copy was indeed not re-barcoded'
211 diag('Current barcode: ' . $copy->barcode());
213 # Attempt to change it back, just in case things are succeeding when they're not supposed to
214 $result = $U->simplereq(
216 'open-ils.cat.update_copy_barcode',
224 'open-ils.cat.update_copy_barcode indicates failure'
227 # Double-check to be sure
228 $copy = $U->simplereq(
230 'open-ils.pcrud.retrieve.acp',
237 'Copy was indeed not re-barcoded'
239 diag('Current barcode: ' . $copy->barcode());
242 changePermCode('UPDATE_COPY_BARCODE', 'WAS_UPDATE_COPY_BARCODE');
244 diag('Testing when user has neither UPDATE_COPY_BARCODE nor UPDATE_COPY');
245 test_barcode_rename_expecting_failure($copy);
247 # back to the way they were
248 changePermCode('WAS_UPDATE_COPY', 'UPDATE_COPY');
249 changePermCode('WAS_UPDATE_COPY_BARCODE', 'UPDATE_COPY_BARCODE');
252 $script->logout(); # Not a test, just to be pedantic.