Lines 17-23
Link Here
|
17 |
|
17 |
|
18 |
use Modern::Perl; |
18 |
use Modern::Perl; |
19 |
|
19 |
|
20 |
use Test::More tests => 99; |
20 |
use Test::More tests => 101; |
21 |
use Test::MockModule; |
21 |
use Test::MockModule; |
22 |
use Test::Mojo; |
22 |
use Test::Mojo; |
23 |
use t::lib::Mocks; |
23 |
use t::lib::Mocks; |
Lines 26-32
use t::lib::TestBuilder;
Link Here
|
26 |
use DateTime; |
26 |
use DateTime; |
27 |
|
27 |
|
28 |
use C4::Context; |
28 |
use C4::Context; |
29 |
use C4::Circulation qw( AddIssue AddReturn ); |
29 |
use C4::Circulation qw( AddIssue AddReturn CanBookBeIssued ); |
30 |
|
30 |
|
31 |
use Koha::Database; |
31 |
use Koha::Database; |
32 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
32 |
use Koha::DateUtils qw( dt_from_string output_pref ); |
Lines 232-234
$t->get_ok( "//$userid:$password@/api/v1/checkouts/" . $issue2->issue_id . "/all
Link Here
|
232 |
current_renewals => 1, |
232 |
current_renewals => 1, |
233 |
error => 'too_many' |
233 |
error => 'too_many' |
234 |
}); |
234 |
}); |
235 |
- |
235 |
|
|
|
236 |
$schema->storage->txn_rollback; |
237 |
|
238 |
subtest 'get_availability' => sub { |
239 |
|
240 |
plan tests => 27; |
241 |
|
242 |
$schema->storage->txn_begin; |
243 |
my $librarian = $builder->build_object( |
244 |
{ |
245 |
class => 'Koha::Patrons', |
246 |
value => { flags => 2 } |
247 |
} |
248 |
); |
249 |
my $password = 'thePassword123'; |
250 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
251 |
my $userid = $librarian->userid; |
252 |
|
253 |
my $patron = $builder->build_object( |
254 |
{ |
255 |
class => 'Koha::Patrons', |
256 |
value => { flags => 0 } |
257 |
} |
258 |
); |
259 |
my $unauth_password = 'thePassword000'; |
260 |
$patron->set_password( |
261 |
{ password => $unauth_password, skip_validattion => 1 } ); |
262 |
my $unauth_userid = $patron->userid; |
263 |
my $patron_id = $patron->borrowernumber; |
264 |
|
265 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
266 |
|
267 |
my $item1 = $builder->build_sample_item; |
268 |
my $item1_id = $item1->id; |
269 |
|
270 |
my %issuingimpossible = (); |
271 |
my %needsconfirmation = (); |
272 |
my %alerts = (); |
273 |
my %messages = (); |
274 |
my $mocked_circ = Test::MockModule->new('C4::Circulation'); |
275 |
$mocked_circ->mock( |
276 |
'CanBookBeIssued', |
277 |
sub { |
278 |
return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages ); |
279 |
} |
280 |
); |
281 |
|
282 |
$t->get_ok( |
283 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
284 |
)->status_is(403)->json_is( |
285 |
{ |
286 |
error => "Authorization failure. Missing required permission(s).", |
287 |
required_permissions => |
288 |
{ circulate => "circulate_remaining_permissions" } |
289 |
} |
290 |
); |
291 |
|
292 |
# Available |
293 |
$t->get_ok( |
294 |
"//$userid:$password@/api/v1/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
295 |
)->status_is(200)->json_is( '/blockers' => {} ) |
296 |
->json_is( '/confirms' => {} )->json_is( '/warnings' => {} ) |
297 |
->json_is( '/confirmation_token' => undef ); |
298 |
|
299 |
# Blocked |
300 |
%issuingimpossible = ( GNA => 1 ); |
301 |
$t->get_ok( |
302 |
"//$userid:$password@/api/v1/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
303 |
)->status_is(200)->json_is( '/blockers' => { GNA => 1 } ) |
304 |
->json_is( '/confirms' => {} )->json_is( '/warnings' => {} ) |
305 |
->json_is( '/confirmation_token' => undef ); |
306 |
%issuingimpossible = (); |
307 |
|
308 |
# Warnings/Info |
309 |
%alerts = ( alert1 => "this is an alert" ); |
310 |
%messages = ( message1 => "this is a message" ); |
311 |
$t->get_ok( |
312 |
"//$userid:$password@/api/v1/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
313 |
)->status_is(200)->json_is( '/blockers' => {} ) |
314 |
->json_is( '/confirms' => {} ) |
315 |
->json_is( '/warnings' => |
316 |
{ alert1 => "this is an alert", message1 => "this is a message" } ) |
317 |
->json_is( '/confirmation_token' => undef ); |
318 |
%alerts = (); |
319 |
%messages = (); |
320 |
|
321 |
# Needs confirm |
322 |
%needsconfirmation = ( confirm1 => 1, confirm2 => 'please' ); |
323 |
$t->get_ok( |
324 |
"//$userid:$password@/api/v1/checkouts/availability?item_id=$item1_id&patron_id=$patron_id" |
325 |
)->status_is(200)->json_is( '/blockers' => {} ) |
326 |
->json_is( '/confirms' => { confirm1 => 1, confirm2 => 'please' } ) |
327 |
->json_is( '/warnings' => {} ) |
328 |
->json_is( '/confirmation_token' => 'eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw' ); |
329 |
|
330 |
$schema->storage->txn_rollback; |
331 |
}; |
332 |
|
333 |
subtest 'add checkout' => sub { |
334 |
|
335 |
plan tests => 6; |
336 |
|
337 |
$schema->storage->txn_begin; |
338 |
my $librarian = $builder->build_object( |
339 |
{ |
340 |
class => 'Koha::Patrons', |
341 |
value => { flags => 2 } |
342 |
} |
343 |
); |
344 |
my $password = 'thePassword123'; |
345 |
$librarian->set_password( { password => $password, skip_validation => 1 } ); |
346 |
my $userid = $librarian->userid; |
347 |
|
348 |
my $patron = $builder->build_object( |
349 |
{ |
350 |
class => 'Koha::Patrons', |
351 |
value => { flags => 0 } |
352 |
} |
353 |
); |
354 |
my $unauth_password = 'thePassword000'; |
355 |
$patron->set_password( |
356 |
{ password => $unauth_password, skip_validattion => 1 } ); |
357 |
my $unauth_userid = $patron->userid; |
358 |
my $patron_id = $patron->borrowernumber; |
359 |
|
360 |
my $branchcode = $builder->build( { source => 'Branch' } )->{branchcode}; |
361 |
|
362 |
my $item1 = $builder->build_sample_item; |
363 |
my $item1_id = $item1->id; |
364 |
|
365 |
my %issuingimpossible = (); |
366 |
my %needsconfirmation = (); |
367 |
my %alerts = (); |
368 |
my %messages = (); |
369 |
my $mocked_circ = Test::MockModule->new('C4::Circulation'); |
370 |
$mocked_circ->mock( |
371 |
'CanBookBeIssued', |
372 |
sub { |
373 |
return ( \%issuingimpossible, \%needsconfirmation, \%alerts, \%messages ); |
374 |
} |
375 |
); |
376 |
|
377 |
$t->post_ok( |
378 |
"//$unauth_userid:$unauth_password@/api/v1/checkouts" => json => |
379 |
{ item_id => $item1_id, patron_id => $patron_id } )->status_is(403) |
380 |
->json_is( |
381 |
{ |
382 |
error => "Authorization failure. Missing required permission(s).", |
383 |
required_permissions => |
384 |
{ circulate => "circulate_remaining_permissions" } |
385 |
} |
386 |
); |
387 |
|
388 |
$t->post_ok( "//$userid:$password@/api/v1/checkouts" => json => |
389 |
{ item_id => $item1_id, patron_id => $patron_id } )->status_is(201); |
390 |
|
391 |
# Needs confirm |
392 |
%needsconfirmation = ( confirm1 => 1, confirm2 => 'please' ); |
393 |
$t->post_ok( |
394 |
"//$userid:$password@/api/v1/checkouts" => json => { |
395 |
item_id => $item1_id, |
396 |
patron_id => $patron_id, |
397 |
} |
398 |
)->status_is(412); |
399 |
|
400 |
my $token = "eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJjb25maXJtMSI6MSwiY29uZmlybTIiOjF9.4QBpITwnIGOAfohyKjaFDoeBWnGmQTdyJrPn9pavArw"; |
401 |
$t->post_ok( |
402 |
"//$userid:$password@/api/v1/checkouts?confirmation=$token" => json => { |
403 |
item_id => $item1_id, |
404 |
patron_id => $patron_id |
405 |
} |
406 |
)->status_is(201)->or(sub { diag $t->tx->res->body }); |
407 |
%needsconfirmation = (); |
408 |
|
409 |
$schema->storage->txn_rollback; |
410 |
}; |