|
Lines 36-42
use C4::Circulation qw( AddIssue AddReturn );
Link Here
|
| 36 |
|
36 |
|
| 37 |
use Koha::Biblios; |
37 |
use Koha::Biblios; |
| 38 |
use Koha::Database; |
38 |
use Koha::Database; |
| 39 |
use Koha::DateUtils qw (dt_from_string output_pref); |
39 |
use Koha::DateUtils qw(dt_from_string output_pref); |
| 40 |
use Koha::Checkouts; |
40 |
use Koha::Checkouts; |
| 41 |
use Koha::Old::Checkouts; |
41 |
use Koha::Old::Checkouts; |
| 42 |
|
42 |
|
|
Lines 81-88
subtest 'get() tests' => sub {
Link Here
|
| 81 |
->status_is(400); |
81 |
->status_is(400); |
| 82 |
|
82 |
|
| 83 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) |
83 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) |
| 84 |
->status_is(200) |
84 |
->status_is(200)->json_is( '/title', 'The unbearable lightness of being' ) |
| 85 |
->json_is( '/title', 'The unbearable lightness of being' ) |
|
|
| 86 |
->json_is( '/author', 'Milan Kundera' ); |
85 |
->json_is( '/author', 'Milan Kundera' ); |
| 87 |
|
86 |
|
| 88 |
$t->get_ok( |
87 |
$t->get_ok( |
|
Lines 97-117
subtest 'get() tests' => sub {
Link Here
|
| 97 |
->status_is(200); |
96 |
->status_is(200); |
| 98 |
|
97 |
|
| 99 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
98 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
| 100 |
->status_is(200) |
99 |
->status_is(200)->content_is( $biblio->metadata->record->as_formatted ); |
| 101 |
->content_is( $biblio->metadata->record->as_formatted ); |
|
|
| 102 |
|
100 |
|
| 103 |
# Simulate a data error situation (BZ35246) |
101 |
# Simulate a data error situation (BZ35246) |
| 104 |
$biblio->biblioitem->delete(); |
102 |
$biblio->biblioitem->delete(); |
| 105 |
|
103 |
|
| 106 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) |
104 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/json' } ) |
| 107 |
->status_is(500) |
105 |
->status_is(500)->json_is( '/error_code', 'internal_server_error' ) |
| 108 |
->json_is( '/error_code', 'internal_server_error' ) |
106 |
->json_is( '/error', 'Something went wrong, check Koha logs for details.' ); |
| 109 |
->json_is( '/error', 'Something went wrong, check Koha logs for details.' ); |
|
|
| 110 |
|
107 |
|
| 111 |
$biblio->delete; |
108 |
$biblio->delete; |
| 112 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
109 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
| 113 |
->status_is(404) |
110 |
->status_is(404)->json_is( '/error', 'Bibliographic record not found' ); |
| 114 |
->json_is( '/error', 'Bibliographic record not found' ); |
|
|
| 115 |
|
111 |
|
| 116 |
subtest 'marc-in-json encoding tests' => sub { |
112 |
subtest 'marc-in-json encoding tests' => sub { |
| 117 |
|
113 |
|
|
Lines 128-135
subtest 'get() tests' => sub {
Link Here
|
| 128 |
|
124 |
|
| 129 |
my $result = $t->get_ok( |
125 |
my $result = $t->get_ok( |
| 130 |
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc-in-json' } ) |
126 |
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marc-in-json' } ) |
| 131 |
->status_is(200) |
127 |
->status_is(200)->tx->res->body; |
| 132 |
->tx->res->body; |
|
|
| 133 |
|
128 |
|
| 134 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
129 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
| 135 |
|
130 |
|
|
Lines 158-165
subtest 'get() tests' => sub {
Link Here
|
| 158 |
|
153 |
|
| 159 |
my $result = $t->get_ok( |
154 |
my $result = $t->get_ok( |
| 160 |
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marcxml+xml' } ) |
155 |
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber => { Accept => 'application/marcxml+xml' } ) |
| 161 |
->status_is(200) |
156 |
->status_is(200)->tx->res->body; |
| 162 |
->tx->res->body; |
|
|
| 163 |
|
157 |
|
| 164 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
158 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
| 165 |
|
159 |
|
|
Lines 192-207
subtest 'get_items() tests' => sub {
Link Here
|
| 192 |
|
186 |
|
| 193 |
$patron->flags(4)->store; |
187 |
$patron->flags(4)->store; |
| 194 |
|
188 |
|
| 195 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" ) |
189 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" )->status_is(200) |
| 196 |
->status_is(200) |
|
|
| 197 |
->json_is( '' => [], 'No items on the biblio' ); |
190 |
->json_is( '' => [], 'No items on the biblio' ); |
| 198 |
|
191 |
|
| 199 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
192 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 200 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
193 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->biblionumber } ); |
| 201 |
|
194 |
|
| 202 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items?_order_by=item_id" ) |
195 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items?_order_by=item_id" ) |
| 203 |
->status_is(200) |
196 |
->status_is(200)->json_is( '' => [ $item_1->to_api, $item_2->to_api ], 'The items are returned' ); |
| 204 |
->json_is( '' => [ $item_1->to_api, $item_2->to_api ], 'The items are returned' ); |
|
|
| 205 |
|
197 |
|
| 206 |
$t->get_ok( |
198 |
$t->get_ok( |
| 207 |
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" => { "x-koha-embed" => "+strings" } ) |
199 |
"//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/items" => { "x-koha-embed" => "+strings" } ) |
|
Lines 242-249
subtest 'get_items() tests' => sub {
Link Here
|
| 242 |
|
234 |
|
| 243 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" |
235 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" |
| 244 |
. $item->biblionumber |
236 |
. $item->biblionumber |
| 245 |
. "/items" => { "x-koha-embed" => "first_hold+strings" } ) |
237 |
. "/items" => { "x-koha-embed" => "first_hold+strings" } )->status_is(200) |
| 246 |
->status_is(200) |
|
|
| 247 |
->json_is( |
238 |
->json_is( |
| 248 |
'/0/first_hold/_strings/pickup_library_id' => { type => 'library', str => $pickup_library->branchname } ); |
239 |
'/0/first_hold/_strings/pickup_library_id' => { type => 'library', str => $pickup_library->branchname } ); |
| 249 |
}; |
240 |
}; |
|
Lines 291-298
subtest 'delete() tests' => sub {
Link Here
|
| 291 |
$item->delete(); |
282 |
$item->delete(); |
| 292 |
|
283 |
|
| 293 |
# Bibs with no items can be deleted |
284 |
# Bibs with no items can be deleted |
| 294 |
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id") |
285 |
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")->status_is( 204, 'REST3.2.4' ) |
| 295 |
->status_is( 204, 'REST3.2.4' ) |
|
|
| 296 |
->content_is( '', 'REST3.3.4' ); |
286 |
->content_is( '', 'REST3.3.4' ); |
| 297 |
|
287 |
|
| 298 |
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")->status_is(404); |
288 |
$t->delete_ok("//$userid:$password@/api/v1/biblios/$biblio_id")->status_is(404); |
|
Lines 339-346
subtest 'get_public() tests' => sub {
Link Here
|
| 339 |
. $biblio->biblionumber => { Accept => 'application/weird+format' } )->status_is(400); |
329 |
. $biblio->biblionumber => { Accept => 'application/weird+format' } )->status_is(400); |
| 340 |
|
330 |
|
| 341 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
331 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
| 342 |
->status_is(200) |
332 |
->status_is(200)->content_like(qr{100\s+_aMilan Kundera}) |
| 343 |
->content_like(qr{100\s+_aMilan Kundera}) |
|
|
| 344 |
->content_like(qr{245\s+_aThe unbearable lightness of being}); |
333 |
->content_like(qr{245\s+_aThe unbearable lightness of being}); |
| 345 |
|
334 |
|
| 346 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" |
335 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" |
|
Lines 354-361
subtest 'get_public() tests' => sub {
Link Here
|
| 354 |
->status_is(200); |
343 |
->status_is(200); |
| 355 |
|
344 |
|
| 356 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
345 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
| 357 |
->status_is(200) |
346 |
->status_is(200)->content_is( $biblio->metadata->record->as_formatted ); |
| 358 |
->content_is( $biblio->metadata->record->as_formatted ); |
|
|
| 359 |
|
347 |
|
| 360 |
subtest 'anonymous access' => sub { |
348 |
subtest 'anonymous access' => sub { |
| 361 |
plan tests => 9; |
349 |
plan tests => 9; |
|
Lines 369-376
subtest 'get_public() tests' => sub {
Link Here
|
| 369 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
357 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
| 370 |
->status_is(200); |
358 |
->status_is(200); |
| 371 |
|
359 |
|
| 372 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
360 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } )->status_is(200) |
| 373 |
->status_is(200) |
|
|
| 374 |
->content_is( $biblio->metadata->record->as_formatted ); |
361 |
->content_is( $biblio->metadata->record->as_formatted ); |
| 375 |
}; |
362 |
}; |
| 376 |
|
363 |
|
|
Lines 389-396
subtest 'get_public() tests' => sub {
Link Here
|
| 389 |
|
376 |
|
| 390 |
my $result = |
377 |
my $result = |
| 391 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc-in-json' } ) |
378 |
$t->get_ok( "/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc-in-json' } ) |
| 392 |
->status_is(200) |
379 |
->status_is(200)->tx->res->body; |
| 393 |
->tx->res->body; |
|
|
| 394 |
|
380 |
|
| 395 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
381 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
| 396 |
|
382 |
|
|
Lines 406-413
subtest 'get_public() tests' => sub {
Link Here
|
| 406 |
Koha::Caches->get_instance()->flush_all; |
392 |
Koha::Caches->get_instance()->flush_all; |
| 407 |
|
393 |
|
| 408 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
394 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'text/plain' } ) |
| 409 |
->status_is(200) |
395 |
->status_is(200)->content_unlike(qr{100\s+_aMilan Kundera}) |
| 410 |
->content_unlike(qr{100\s+_aMilan Kundera}) |
|
|
| 411 |
->content_like(qr{245\s+_aThe unbearable lightness of being}); |
396 |
->content_like(qr{245\s+_aThe unbearable lightness of being}); |
| 412 |
|
397 |
|
| 413 |
subtest 'hidden_in_opac tests' => sub { |
398 |
subtest 'hidden_in_opac tests' => sub { |
|
Lines 471-478
subtest 'get_public() tests' => sub {
Link Here
|
| 471 |
$biblio->delete; |
456 |
$biblio->delete; |
| 472 |
$t->get_ok( |
457 |
$t->get_ok( |
| 473 |
"//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
458 |
"//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber => { Accept => 'application/marc' } ) |
| 474 |
->status_is(404) |
459 |
->status_is(404)->json_is( '/error', 'Bibliographic record not found' ); |
| 475 |
->json_is( '/error', 'Bibliographic record not found' ); |
|
|
| 476 |
|
460 |
|
| 477 |
$schema->storage->txn_rollback; |
461 |
$schema->storage->txn_rollback; |
| 478 |
}; |
462 |
}; |
|
Lines 597-604
subtest 'pickup_locations() tests' => sub {
Link Here
|
| 597 |
. "patron_id=" |
581 |
. "patron_id=" |
| 598 |
. $patron->id |
582 |
. $patron->id |
| 599 |
. "&_order_by=marc_org_code" |
583 |
. "&_order_by=marc_org_code" |
| 600 |
. "&_per_page=1" ) |
584 |
. "&_per_page=1" )->json_is( [$library_1_api] ) |
| 601 |
->json_is( [$library_1_api] ) |
|
|
| 602 |
->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) |
585 |
->header_is( 'X-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) |
| 603 |
->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) |
586 |
->header_is( 'X-Base-Total-Count', '4', '4 is the count for libraries with pickup_location=1' ) |
| 604 |
->header_unlike( 'Link', qr|rel="prev"| ) |
587 |
->header_unlike( 'Link', qr|rel="prev"| ) |
|
Lines 629-639
subtest 'pickup_locations() tests' => sub {
Link Here
|
| 629 |
. "patron_id=" |
612 |
. "patron_id=" |
| 630 |
. $patron->id |
613 |
. $patron->id |
| 631 |
. "&_order_by=marc_org_code" |
614 |
. "&_order_by=marc_org_code" |
| 632 |
. "&_per_page=1" ) |
615 |
. "&_per_page=1" )->json_is( [$library_1_api] )->header_is( 'X-Total-Count', '2' ) |
| 633 |
->json_is( [$library_1_api] ) |
616 |
->header_is( 'X-Base-Total-Count', '2' )->header_unlike( 'Link', qr|rel="prev"| ) |
| 634 |
->header_is( 'X-Total-Count', '2' ) |
|
|
| 635 |
->header_is( 'X-Base-Total-Count', '2' ) |
| 636 |
->header_unlike( 'Link', qr|rel="prev"| ) |
| 637 |
->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# ) |
617 |
->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1.*)>\; rel="next"# ) |
| 638 |
->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# ) |
618 |
->header_like( 'Link', qr#(_per_page=1.*\&_page=1.*|_page=1.*\&_per_page=1).*>\; rel="first"# ) |
| 639 |
->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1).*>\; rel="last"# ); |
619 |
->header_like( 'Link', qr#(_per_page=1.*\&_page=2.*|_page=2.*\&_per_page=1).*>\; rel="last"# ); |
|
Lines 653-660
subtest 'pickup_locations() tests' => sub {
Link Here
|
| 653 |
|
633 |
|
| 654 |
$t->get_ok( |
634 |
$t->get_ok( |
| 655 |
"//$userid:$password@/api/v1/biblios/" . $biblio->id . "/pickup_locations?" . "patron_id=" . $patron->id ) |
635 |
"//$userid:$password@/api/v1/biblios/" . $biblio->id . "/pickup_locations?" . "patron_id=" . $patron->id ) |
| 656 |
->status_is(404) |
636 |
->status_is(404)->json_is( '/error' => 'Bibliographic record not found' ); |
| 657 |
->json_is( '/error' => 'Bibliographic record not found' ); |
|
|
| 658 |
|
637 |
|
| 659 |
$schema->storage->txn_rollback; |
638 |
$schema->storage->txn_rollback; |
| 660 |
}; |
639 |
}; |
|
Lines 693-707
subtest 'get_items_public() tests' => sub {
Link Here
|
| 693 |
|
672 |
|
| 694 |
my $biblio = $builder->build_sample_biblio(); |
673 |
my $biblio = $builder->build_sample_biblio(); |
| 695 |
|
674 |
|
| 696 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->id . "/items" ) |
675 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->id . "/items" )->status_is(200) |
| 697 |
->status_is(200) |
|
|
| 698 |
->json_is( '' => [], 'No items on the biblio' ); |
676 |
->json_is( '' => [], 'No items on the biblio' ); |
| 699 |
|
677 |
|
| 700 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id } ); |
678 |
my $item_1 = $builder->build_sample_item( { biblionumber => $biblio->id } ); |
| 701 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->id, withdrawn => 1 } ); |
679 |
my $item_2 = $builder->build_sample_item( { biblionumber => $biblio->id, withdrawn => 1 } ); |
| 702 |
|
680 |
|
| 703 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" ) |
681 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )->status_is(200) |
| 704 |
->status_is(200) |
|
|
| 705 |
->json_is( |
682 |
->json_is( |
| 706 |
'' => [ |
683 |
'' => [ |
| 707 |
$item_1->to_api( { public => 1 } ), |
684 |
$item_1->to_api( { public => 1 } ), |
|
Lines 712-719
subtest 'get_items_public() tests' => sub {
Link Here
|
| 712 |
|
689 |
|
| 713 |
$rules = { withdrawn => ['1'] }; |
690 |
$rules = { withdrawn => ['1'] }; |
| 714 |
|
691 |
|
| 715 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" ) |
692 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )->status_is(200) |
| 716 |
->status_is(200) |
|
|
| 717 |
->json_is( |
693 |
->json_is( |
| 718 |
'' => [ $item_1->to_api( { public => 1 } ) ], |
694 |
'' => [ $item_1->to_api( { public => 1 } ) ], |
| 719 |
'The items are returned, hidden one is not returned' |
695 |
'The items are returned, hidden one is not returned' |
|
Lines 726-733
subtest 'get_items_public() tests' => sub {
Link Here
|
| 726 |
|
702 |
|
| 727 |
$override_hidden_items = 1; |
703 |
$override_hidden_items = 1; |
| 728 |
|
704 |
|
| 729 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" ) |
705 |
$t->get_ok( "//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/items" )->status_is(200) |
| 730 |
->status_is(200) |
|
|
| 731 |
->json_is( |
706 |
->json_is( |
| 732 |
'' => [ |
707 |
'' => [ |
| 733 |
$item_1->to_api( { public => 1 } ), |
708 |
$item_1->to_api( { public => 1 } ), |
|
Lines 780-787
subtest 'get_bookings() tests' => sub {
Link Here
|
| 780 |
|
755 |
|
| 781 |
$t->get_ok( "//$unauth_userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(403); |
756 |
$t->get_ok( "//$unauth_userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(403); |
| 782 |
|
757 |
|
| 783 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" ) |
758 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(200) |
| 784 |
->status_is(200) |
|
|
| 785 |
->json_is( '' => [], 'No bookings on the biblio' ); |
759 |
->json_is( '' => [], 'No bookings on the biblio' ); |
| 786 |
|
760 |
|
| 787 |
# One booking |
761 |
# One booking |
|
Lines 800-807
subtest 'get_bookings() tests' => sub {
Link Here
|
| 800 |
); |
774 |
); |
| 801 |
|
775 |
|
| 802 |
my $ret = |
776 |
my $ret = |
| 803 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" ) |
777 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/bookings" )->status_is(200) |
| 804 |
->status_is(200) |
|
|
| 805 |
->tx->res->json; |
778 |
->tx->res->json; |
| 806 |
|
779 |
|
| 807 |
is_deeply( $ret, [ $booking_0->to_api ] ); |
780 |
is_deeply( $ret, [ $booking_0->to_api ] ); |
|
Lines 874-881
subtest 'get_checkouts() tests' => sub {
Link Here
|
| 874 |
AddIssue( $patron, $item_2->barcode ); |
847 |
AddIssue( $patron, $item_2->barcode ); |
| 875 |
|
848 |
|
| 876 |
my $ret = |
849 |
my $ret = |
| 877 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" ) |
850 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" )->status_is(200) |
| 878 |
->status_is(200) |
|
|
| 879 |
->tx->res->json; |
851 |
->tx->res->json; |
| 880 |
|
852 |
|
| 881 |
my $checkout_1 = Koha::Checkouts->find( { itemnumber => $item_1->id } ); |
853 |
my $checkout_1 = Koha::Checkouts->find( { itemnumber => $item_1->id } ); |
|
Lines 886-901
subtest 'get_checkouts() tests' => sub {
Link Here
|
| 886 |
AddReturn( $item_1->barcode ); |
858 |
AddReturn( $item_1->barcode ); |
| 887 |
|
859 |
|
| 888 |
$ret = |
860 |
$ret = |
| 889 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" ) |
861 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts" )->status_is(200) |
| 890 |
->status_is(200) |
|
|
| 891 |
->tx->res->json; |
862 |
->tx->res->json; |
| 892 |
|
863 |
|
| 893 |
is_deeply( $ret, [ $checkout_2->to_api ] ); |
864 |
is_deeply( $ret, [ $checkout_2->to_api ] ); |
| 894 |
|
865 |
|
| 895 |
$ret = |
866 |
$ret = |
| 896 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts?checked_in=1" ) |
867 |
$t->get_ok( "//$userid:$password@/api/v1/biblios/" . $biblio->biblionumber . "/checkouts?checked_in=1" ) |
| 897 |
->status_is(200) |
868 |
->status_is(200)->tx->res->json; |
| 898 |
->tx->res->json; |
|
|
| 899 |
|
869 |
|
| 900 |
my $old_checkout_1 = Koha::Old::Checkouts->find( $checkout_1->id ); |
870 |
my $old_checkout_1 = Koha::Old::Checkouts->find( $checkout_1->id ); |
| 901 |
|
871 |
|
|
Lines 927-944
subtest 'set_rating() tests' => sub {
Link Here
|
| 927 |
|
897 |
|
| 928 |
$t->post_ok( |
898 |
$t->post_ok( |
| 929 |
"//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/ratings" => json => { rating => 3 } ) |
899 |
"//$userid:$password@/api/v1/public/biblios/" . $biblio->biblionumber . "/ratings" => json => { rating => 3 } ) |
| 930 |
->status_is(200) |
900 |
->status_is(200)->json_is( '/rating', '3' )->json_is( '/average', '3' )->json_is( '/count', '1' ); |
| 931 |
->json_is( '/rating', '3' ) |
|
|
| 932 |
->json_is( '/average', '3' ) |
| 933 |
->json_is( '/count', '1' ); |
| 934 |
|
901 |
|
| 935 |
$t->post_ok( "//$userid:$password@/api/v1/public/biblios/" |
902 |
$t->post_ok( "//$userid:$password@/api/v1/public/biblios/" |
| 936 |
. $biblio->biblionumber |
903 |
. $biblio->biblionumber |
| 937 |
. "/ratings" => json => { rating => undef } ) |
904 |
. "/ratings" => json => { rating => undef } )->status_is(200)->json_is( '/rating', undef ) |
| 938 |
->status_is(200) |
905 |
->json_is( '/average', '0' )->json_is( '/count', '0' ); |
| 939 |
->json_is( '/rating', undef ) |
|
|
| 940 |
->json_is( '/average', '0' ) |
| 941 |
->json_is( '/count', '0' ); |
| 942 |
|
906 |
|
| 943 |
$schema->storage->txn_rollback; |
907 |
$schema->storage->txn_rollback; |
| 944 |
|
908 |
|
|
Lines 1364-1371
subtest 'add() tests' => sub {
Link Here
|
| 1364 |
|
1328 |
|
| 1365 |
$t->post_ok( "//$userid:$password@/api/v1/biblios" => |
1329 |
$t->post_ok( "//$userid:$password@/api/v1/biblios" => |
| 1366 |
{ 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml ) |
1330 |
{ 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml ) |
| 1367 |
->status_is(200) |
1331 |
->status_is(200)->json_has('/id') |
| 1368 |
->json_has('/id') |
|
|
| 1369 |
->header_is( 'Location' => "/api/v1/biblios/" . $t->tx->res->json->{id}, "REST3.4.1" ); |
1332 |
->header_is( 'Location' => "/api/v1/biblios/" . $t->tx->res->json->{id}, "REST3.4.1" ); |
| 1370 |
|
1333 |
|
| 1371 |
$t->post_ok( |
1334 |
$t->post_ok( |
|
Lines 1376-1383
subtest 'add() tests' => sub {
Link Here
|
| 1376 |
)->status_is(200)->json_has('/id'); |
1339 |
)->status_is(200)->json_has('/id'); |
| 1377 |
|
1340 |
|
| 1378 |
$t->post_ok( "//$userid:$password@/api/v1/biblios" => |
1341 |
$t->post_ok( "//$userid:$password@/api/v1/biblios" => |
| 1379 |
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc ) |
1342 |
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )->status_is(200) |
| 1380 |
->status_is(200) |
|
|
| 1381 |
->json_has('/id'); |
1343 |
->json_has('/id'); |
| 1382 |
|
1344 |
|
| 1383 |
subtest 'x-record-source-id header tests' => sub { |
1345 |
subtest 'x-record-source-id header tests' => sub { |
|
Lines 1421-1428
subtest 'add() tests' => sub {
Link Here
|
| 1421 |
$mock_biblio->mock( 'AddBiblio', sub { return ( undef, undef ); } ); |
1383 |
$mock_biblio->mock( 'AddBiblio', sub { return ( undef, undef ); } ); |
| 1422 |
|
1384 |
|
| 1423 |
$t->post_ok( "//$userid:$password@/api/v1/biblios" => |
1385 |
$t->post_ok( "//$userid:$password@/api/v1/biblios" => |
| 1424 |
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc ) |
1386 |
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )->status_is(400) |
| 1425 |
->status_is(400) |
|
|
| 1426 |
->json_is( |
1387 |
->json_is( |
| 1427 |
{ |
1388 |
{ |
| 1428 |
error => 'Error creating record', |
1389 |
error => 'Error creating record', |
|
Lines 1850-1857
subtest 'put() tests' => sub {
Link Here
|
| 1850 |
|
1811 |
|
| 1851 |
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" => |
1812 |
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" => |
| 1852 |
{ 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml ) |
1813 |
{ 'Content-Type' => 'application/marcxml+xml', 'x-framework-id' => $frameworkcode } => $marcxml ) |
| 1853 |
->status_is(200) |
1814 |
->status_is(200)->json_has('/id'); |
| 1854 |
->json_has('/id'); |
|
|
| 1855 |
|
1815 |
|
| 1856 |
$biblio = Koha::Biblios->find($biblionumber); |
1816 |
$biblio = Koha::Biblios->find($biblionumber); |
| 1857 |
|
1817 |
|
|
Lines 1859-1874
subtest 'put() tests' => sub {
Link Here
|
| 1859 |
|
1819 |
|
| 1860 |
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" => |
1820 |
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" => |
| 1861 |
{ 'Content-Type' => 'application/marc-in-json', 'x-framework-id' => $frameworkcode } => $mij ) |
1821 |
{ 'Content-Type' => 'application/marc-in-json', 'x-framework-id' => $frameworkcode } => $mij ) |
| 1862 |
->status_is(200) |
1822 |
->status_is(200)->json_has('/id'); |
| 1863 |
->json_has('/id'); |
|
|
| 1864 |
|
1823 |
|
| 1865 |
$biblio = Koha::Biblios->find($biblionumber); |
1824 |
$biblio = Koha::Biblios->find($biblionumber); |
| 1866 |
|
1825 |
|
| 1867 |
is( $biblio->title, 'Introduction to Attic Greek (Using mij) /' ); |
1826 |
is( $biblio->title, 'Introduction to Attic Greek (Using mij) /' ); |
| 1868 |
|
1827 |
|
| 1869 |
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" => |
1828 |
$t->put_ok( "//$userid:$password@/api/v1/biblios/$biblionumber" => |
| 1870 |
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc ) |
1829 |
{ 'Content-Type' => 'application/marc', 'x-framework-id' => $frameworkcode } => $marc )->status_is(200) |
| 1871 |
->status_is(200) |
|
|
| 1872 |
->json_has('/id'); |
1830 |
->json_has('/id'); |
| 1873 |
|
1831 |
|
| 1874 |
$biblio = Koha::Biblios->find($biblionumber); |
1832 |
$biblio = Koha::Biblios->find($biblionumber); |
|
Lines 1927-1934
subtest 'list() tests' => sub {
Link Here
|
| 1927 |
|
1885 |
|
| 1928 |
my $result = |
1886 |
my $result = |
| 1929 |
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/marcxml+xml' } ) |
1887 |
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/marcxml+xml' } ) |
| 1930 |
->status_is(200) |
1888 |
->status_is(200)->tx->res->body; |
| 1931 |
->tx->res->body; |
|
|
| 1932 |
|
1889 |
|
| 1933 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
1890 |
my $encoded_title = Encode::encode( "UTF-8", $title_with_diacritics ); |
| 1934 |
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); |
1891 |
like( $result, qr/\Q$encoded_title/, "The title is not double encoded" ); |
|
Lines 1956-1963
subtest 'list() tests' => sub {
Link Here
|
| 1956 |
|
1913 |
|
| 1957 |
$query = encode_json( { biblio_id => $biblio->id } ); |
1914 |
$query = encode_json( { biblio_id => $biblio->id } ); |
| 1958 |
|
1915 |
|
| 1959 |
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/json' } ) |
1916 |
$t->get_ok( "//$userid:$password@/api/v1/biblios?q=$query" => { Accept => 'application/json' } )->status_is(200) |
| 1960 |
->status_is(200) |
|
|
| 1961 |
->json_is( '/0/timestamp' => |
1917 |
->json_is( '/0/timestamp' => |
| 1962 |
output_pref( { dt => $fixed_date, dateformat => 'rfc3339' }, 'biblio table timestamp takes precedence' ) ); |
1918 |
output_pref( { dt => $fixed_date, dateformat => 'rfc3339' }, 'biblio table timestamp takes precedence' ) ); |
| 1963 |
|
1919 |
|
|
Lines 2321-2328
subtest 'merge() tests' => sub {
Link Here
|
| 2321 |
my $result = |
2277 |
my $result = |
| 2322 |
$t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id1/merge" => |
2278 |
$t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id1/merge" => |
| 2323 |
{ 'Content-Type' => 'application/json', 'Accept' => 'application/marc-in-json' } => $json_input1 ) |
2279 |
{ 'Content-Type' => 'application/json', 'Accept' => 'application/marc-in-json' } => $json_input1 ) |
| 2324 |
->status_is(200) |
2280 |
->status_is(200)->tx->res->body; |
| 2325 |
->tx->res->body; |
|
|
| 2326 |
like( $result, qr/$title_1/, "Merged record has the correct title" ); |
2281 |
like( $result, qr/$title_1/, "Merged record has the correct title" ); |
| 2327 |
unlike( $result, qr/$title_2/, "Merged record doesn't have the wrong title" ); |
2282 |
unlike( $result, qr/$title_2/, "Merged record doesn't have the wrong title" ); |
| 2328 |
|
2283 |
|
|
Lines 2334-2341
subtest 'merge() tests' => sub {
Link Here
|
| 2334 |
$result = |
2289 |
$result = |
| 2335 |
$t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id1/merge" => |
2290 |
$t->post_ok( "//$userid:$password@/api/v1/biblios/$biblio_id1/merge" => |
| 2336 |
{ 'Content-Type' => 'application/json', 'Accept' => 'application/marc-in-json' } => $json_input2 ) |
2291 |
{ 'Content-Type' => 'application/json', 'Accept' => 'application/marc-in-json' } => $json_input2 ) |
| 2337 |
->status_is(200) |
2292 |
->status_is(200)->tx->res->body; |
| 2338 |
->tx->res->body; |
|
|
| 2339 |
like( $result, qr/Using mij/, "Update with Marc-in-json record" ); |
2293 |
like( $result, qr/Using mij/, "Update with Marc-in-json record" ); |
| 2340 |
unlike( $result, qr/$title_1/, "Change all record with dat in the 'datarecord' field" ); |
2294 |
unlike( $result, qr/$title_1/, "Change all record with dat in the 'datarecord' field" ); |
| 2341 |
|
2295 |
|