2 use strict; use warnings;
3 use Test::More tests => 17;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
7 my $script = OpenILS::Utils::TestUtils->new();
8 my $U = 'OpenILS::Application::AppUtils';
10 diag("Test LP 1779467 Enhance Mark Item Discard/Weed.");
15 WORKSTATION => 'BR1-lp1779467-test-mark-item-discard'
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 # Mark it discard/weed.
71 my $result = $U->simplereq(
73 'open-ils.circ.mark_item_discard',
80 'Mark available copy Discard/Weed'
84 $copy = $U->simplereq(
86 'open-ils.pcrud.retrieve.acp',
92 OILS_COPY_STATUS_DISCARD,
93 'Copy has Discard/Weed status'
96 # Find available copy at BR3.
97 $acps = $U->simplereq(
99 'open-ils.pcrud.search.acp.atomic',
101 {circ_lib => BR3_ID, status => OILS_COPY_STATUS_AVAILABLE},
107 'Fieldmapper::asset::copy',
108 'Got available copy from BR3'
111 # Attempt to mark it discard/weed.
112 # Should fail with a perm error.
113 $result = $U->simplereq(
115 'open-ils.circ.mark_item_discard',
122 'Mark BR3 copy Discard/Weed'
125 # Find checked out copy at BR1.
126 $acps = $U->simplereq(
128 'open-ils.pcrud.search.acp.atomic',
130 {circ_lib => BR1_ID, status => OILS_COPY_STATUS_CHECKED_OUT},
136 'Fieldmapper::asset::copy',
137 'Got checked out copy from BR1'
140 # Mark it discard/weed with handle_checkin: 1.
141 $result = $U->simplereq(
143 'open-ils.circ.mark_item_discard',
146 {handle_checkin => 1}
150 'Mark checked out item discard'
154 $copy = $U->simplereq(
156 'open-ils.pcrud.retrieve.acp',
162 OILS_COPY_STATUS_DISCARD,
163 'Checked out copy has Discard/Weed status'
166 # Check that it is no longer checked out.
167 my $circ = $U->simplereq(
169 'open-ils.pcrud.search.circ',
171 {target_copy => $copy->id(), checkin_time => undef}
175 'No circulation for marked copy'
178 # Find another checked out copy at BR1.
179 $acps = $U->simplereq(
181 'open-ils.pcrud.search.acp.atomic',
183 {circ_lib => BR1_ID, status => OILS_COPY_STATUS_CHECKED_OUT},
189 'Fieldmapper::asset::copy',
190 'Got another checked out copy from BR1'
193 # Mark it discard/weed with handle_checkin: 0.
194 $result = $U->simplereq(
196 'open-ils.circ.mark_item_discard',
199 {handle_checkin => 0}
201 # Check that we got the appropriate event: ITEM_TO_MARK_CHECKED_OUT
204 'ITEM_TO_MARK_CHECKED_OUT',
205 'Mark second checked out item discard'
209 $copy = $U->simplereq(
211 'open-ils.pcrud.retrieve.acp',
217 OILS_COPY_STATUS_CHECKED_OUT,
218 'Second checked out copy has Checked Out status'
221 # Check that it is still checked out.
222 $circ = $U->simplereq(
224 'open-ils.pcrud.search.circ',
226 {target_copy => $copy->id(), checkin_time => undef}
230 'Fieldmapper::action::circulation',
231 'Second copy still has a circulation'
234 # We could add more tests for other conditions, i.e. a copy in transit
235 # and for marking other statuses.
238 $script->logout(); # Not a test, just to be pedantic.