]> git.evergreen-ils.org Git - working/Evergreen.git/blob - Open-ILS/src/perlmods/live_t/zz-lp1779467-mark-item-discard.t
LP1615805 No inputs after submit in patron search (AngularJS)
[working/Evergreen.git] / Open-ILS / src / perlmods / live_t / zz-lp1779467-mark-item-discard.t
1 #!perl
2 use strict; use warnings;
3 use Test::More tests => 17;
4 use OpenILS::Utils::TestUtils;
5 use OpenILS::Const qw(:const);
6
7 my $script = OpenILS::Utils::TestUtils->new();
8 my $U = 'OpenILS::Application::AppUtils';
9
10 diag("Test LP 1779467 Enhance Mark Item Discard/Weed.");
11
12 use constant {
13     BR1_ID => 4,
14     BR3_ID => 6,
15     WORKSTATION => 'BR1-lp1779467-test-mark-item-discard'
16 };
17
18 # We are deliberately NOT using the admin user to check for a perm failure.
19 my $credentials = {
20     username => 'br1mtownsend',
21     password => 'maryt1234',
22     type => 'staff'
23 };
24
25 # Log in as staff.
26 my $authtoken = $script->authenticate($credentials);
27 ok(
28     $authtoken,
29     'Logged in'
30 ) or BAIL_OUT('Must log in');
31
32 # Find or register workstation.
33 my $ws = $script->find_or_register_workstation(WORKSTATION, BR1_ID);
34 ok(
35     ! ref $ws,
36     'Found or registered workstation'
37 ) or BAIL_OUT('Need Workstation');
38
39 # Logout.
40 $script->logout();
41 ok(
42     ! $script->authtoken,
43     'Logged out'
44 );
45
46 # Login with workstation.
47 $credentials->{workstation} = WORKSTATION;
48 $credentials->{password} = 'maryt1234';
49 $authtoken = $script->authenticate($credentials);
50 ok(
51     $script->authtoken,
52     'Logged in with workstation'
53 ) or BAIL_OUT('Must log in');
54
55 # Find available copy at BR1
56 my $acps = $U->simplereq(
57     'open-ils.pcrud',
58     'open-ils.pcrud.search.acp.atomic',
59     $authtoken,
60     {circ_lib => BR1_ID, status => OILS_COPY_STATUS_AVAILABLE},
61     {limit => 1}
62 );
63 my $copy = $acps->[0];
64 isa_ok(
65     ref $copy,
66     'Fieldmapper::asset::copy',
67     'Got available copy from BR1'
68 );
69
70 # Mark it discard/weed.
71 my $result = $U->simplereq(
72     'open-ils.circ',
73     'open-ils.circ.mark_item_discard',
74     $authtoken,
75     $copy->id()
76 );
77 is(
78     $result,
79     1,
80     'Mark available copy Discard/Weed'
81 );
82
83 # Check its status.
84 $copy = $U->simplereq(
85     'open-ils.pcrud',
86     'open-ils.pcrud.retrieve.acp',
87     $authtoken,
88     $copy->id()
89 );
90 is(
91     $copy->status(),
92     OILS_COPY_STATUS_DISCARD,
93     'Copy has Discard/Weed status'
94 );
95
96 # Find available copy at BR3.
97 $acps = $U->simplereq(
98     'open-ils.pcrud',
99     'open-ils.pcrud.search.acp.atomic',
100     $authtoken,
101     {circ_lib => BR3_ID, status => OILS_COPY_STATUS_AVAILABLE},
102     {limit => 1}
103 );
104 $copy = $acps->[0];
105 isa_ok(
106     ref $copy,
107     'Fieldmapper::asset::copy',
108     'Got available copy from BR3'
109 );
110
111 # Attempt to mark it discard/weed.
112 # Should fail with a perm error.
113 $result = $U->simplereq(
114     'open-ils.circ',
115     'open-ils.circ.mark_item_discard',
116     $authtoken,
117     $copy->id()
118 );
119 is(
120     $result->{textcode},
121     'PERM_FAILURE',
122     'Mark BR3 copy Discard/Weed'
123 );
124
125 # Find checked out copy at BR1.
126 $acps = $U->simplereq(
127     'open-ils.pcrud',
128     'open-ils.pcrud.search.acp.atomic',
129     $authtoken,
130     {circ_lib => BR1_ID, status => OILS_COPY_STATUS_CHECKED_OUT},
131     {limit => 1}
132 );
133 $copy = $acps->[0];
134 isa_ok(
135     ref $copy,
136     'Fieldmapper::asset::copy',
137     'Got checked out copy from BR1'
138 );
139
140 # Mark it discard/weed with handle_checkin: 1.
141 $result = $U->simplereq(
142     'open-ils.circ',
143     'open-ils.circ.mark_item_discard',
144     $authtoken,
145     $copy->id(),
146     {handle_checkin => 1}
147 );
148 ok(
149     $result == 1,
150     'Mark checked out item discard'
151 );
152
153 # Check its status.
154 $copy = $U->simplereq(
155     'open-ils.pcrud',
156     'open-ils.pcrud.retrieve.acp',
157     $authtoken,
158     $copy->id()
159 );
160 is(
161     $copy->status(),
162     OILS_COPY_STATUS_DISCARD,
163     'Checked out copy has Discard/Weed status'
164 );
165
166 # Check that it is no longer checked out.
167 my $circ = $U->simplereq(
168     'open-ils.pcrud',
169     'open-ils.pcrud.search.circ',
170     $authtoken,
171     {target_copy => $copy->id(), checkin_time => undef}
172 );
173 ok(
174     ! defined $circ,
175     'No circulation for marked copy'
176 );
177
178 # Find another checked out copy at BR1.
179 $acps = $U->simplereq(
180     'open-ils.pcrud',
181     'open-ils.pcrud.search.acp.atomic',
182     $authtoken,
183     {circ_lib => BR1_ID, status => OILS_COPY_STATUS_CHECKED_OUT},
184     {limit => 1}
185 );
186 $copy = $acps->[0];
187 isa_ok(
188     ref $copy,
189     'Fieldmapper::asset::copy',
190     'Got another checked out copy from BR1'
191 );
192
193 # Mark it discard/weed with handle_checkin: 0.
194 $result = $U->simplereq(
195     'open-ils.circ',
196     'open-ils.circ.mark_item_discard',
197     $authtoken,
198     $copy->id(),
199     {handle_checkin => 0}
200 );
201 # Check that we got the appropriate event: ITEM_TO_MARK_CHECKED_OUT
202 is(
203     $result->{textcode},
204     'ITEM_TO_MARK_CHECKED_OUT',
205     'Mark second checked out item discard'
206 );
207
208 # Check its status.
209 $copy = $U->simplereq(
210     'open-ils.pcrud',
211     'open-ils.pcrud.retrieve.acp',
212     $authtoken,
213     $copy->id()
214 );
215 is(
216     $copy->status(),
217     OILS_COPY_STATUS_CHECKED_OUT,
218     'Second checked out copy has Checked Out status'
219 );
220
221 # Check that it is still checked out.
222 $circ = $U->simplereq(
223     'open-ils.pcrud',
224     'open-ils.pcrud.search.circ',
225     $authtoken,
226     {target_copy => $copy->id(), checkin_time => undef}
227 );
228 isa_ok(
229     $circ,
230     'Fieldmapper::action::circulation',
231     'Second copy still has a circulation'
232 );
233
234 # We could add more tests for other conditions, i.e. a copy in transit
235 # and for marking other statuses.
236
237 # Logout
238 $script->logout(); # Not a test, just to be pedantic.