|
Lines 81-87
get '/biblios' => sub {
Link Here
|
| 81 |
my $output = $c->req->params->to_hash; |
81 |
my $output = $c->req->params->to_hash; |
| 82 |
$output->{query} = $c->req->json if defined $c->req->json; |
82 |
$output->{query} = $c->req->json if defined $c->req->json; |
| 83 |
my $headers = $c->req->headers->to_hash; |
83 |
my $headers = $c->req->headers->to_hash; |
| 84 |
$output->{'x-koha-query'} = $headers->{'x-koha-query'} if defined $headers->{'x-koha-query'}; |
|
|
| 85 |
$c->validation->output($output); |
84 |
$c->validation->output($output); |
| 86 |
my $biblios_set = Koha::Biblios->new; |
85 |
my $biblios_set = Koha::Biblios->new; |
| 87 |
$c->stash("koha.embed", { |
86 |
$c->stash("koha.embed", { |
|
Lines 140-146
get '/cities/:city_id/rs' => sub {
Link Here
|
| 140 |
}; |
139 |
}; |
| 141 |
|
140 |
|
| 142 |
# The tests |
141 |
# The tests |
| 143 |
use Test::More tests => 18; |
142 |
use Test::More tests => 17; |
| 144 |
use Test::Mojo; |
143 |
use Test::Mojo; |
| 145 |
|
144 |
|
| 146 |
use t::lib::Mocks; |
145 |
use t::lib::Mocks; |
|
Lines 456-485
subtest 'objects.search helper with q parameter' => sub {
Link Here
|
| 456 |
$schema->storage->txn_rollback; |
455 |
$schema->storage->txn_rollback; |
| 457 |
}; |
456 |
}; |
| 458 |
|
457 |
|
| 459 |
subtest 'objects.search helper with x-koha-query header' => sub { |
|
|
| 460 |
plan tests => 4; |
| 461 |
|
| 462 |
$schema->storage->txn_begin; |
| 463 |
|
| 464 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 465 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 466 |
my $biblio1 = $builder->build_sample_biblio; |
| 467 |
my $biblio2 = $builder->build_sample_biblio; |
| 468 |
my $biblio3 = $builder->build_sample_biblio; |
| 469 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
| 470 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
| 471 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
| 472 |
|
| 473 |
my $t = Test::Mojo->new; |
| 474 |
$t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'}) |
| 475 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
| 476 |
|
| 477 |
$t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'}) |
| 478 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
| 479 |
|
| 480 |
$schema->storage->txn_rollback; |
| 481 |
}; |
| 482 |
|
| 483 |
subtest 'objects.search helper with all query methods' => sub { |
458 |
subtest 'objects.search helper with all query methods' => sub { |
| 484 |
plan tests => 6; |
459 |
plan tests => 6; |
| 485 |
|
460 |
|
|
Lines 495-508
subtest 'objects.search helper with all query methods' => sub {
Link Here
|
| 495 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
470 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
| 496 |
|
471 |
|
| 497 |
my $t = Test::Mojo->new; |
472 |
my $t = Test::Mojo->new; |
| 498 |
$t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron1->cardnumber}) |
473 |
my $query = { |
| 499 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
474 |
"suggestions.suggester.firstname" => $patron1->firstname, |
| 500 |
|
475 |
"suggestions.suggester.patron_id" => $patron1->id, |
| 501 |
$t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron2->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) |
476 |
}; |
| 502 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
477 |
$t->get_ok( |
| 503 |
|
478 |
'/biblios?q=' . encode_json($query) => json => { "suggestions.suggester.cardnumber" => $patron1->cardnumber } ) |
| 504 |
$t->get_ok('/biblios?q={"suggestions.suggester.firstname": "'.$patron1->firstname.'"}' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'} => json => {"suggestions.suggester.cardnumber" => $patron2->cardnumber}) |
479 |
->json_is( '/count' => 1, 'there should be 1 biblio with suggestions of patron 1' ); |
| 505 |
->json_is('/count' => 0, 'there shouldn\'t be biblios where suggester has patron1 fistname and patron2 id'); |
480 |
|
|
|
481 |
$query = { |
| 482 |
"suggestions.suggester.firstname" => $patron2->firstname, |
| 483 |
"suggestions.suggester.patron_id" => $patron2->id, |
| 484 |
}; |
| 485 |
$t->get_ok( |
| 486 |
'/biblios?q=' . encode_json($query) => json => { "suggestions.suggester.cardnumber" => $patron2->cardnumber } ) |
| 487 |
->json_is( '/count' => 2, 'there should be 2 biblios with suggestions of patron 2' ); |
| 488 |
|
| 489 |
$query = { |
| 490 |
"suggestions.suggester.firstname" => $patron1->firstname, |
| 491 |
"suggestions.suggester.patron_id" => $patron2->id, |
| 492 |
}; |
| 493 |
$t->get_ok( |
| 494 |
'/biblios?q=' . encode_json($query) => json => { "suggestions.suggester.cardnumber" => $patron2->cardnumber } ) |
| 495 |
->json_is( '/count' => 0, 'there shouldn\'t be biblios where suggester has patron1 fistname and patron2 id' ); |
| 506 |
|
496 |
|
| 507 |
$schema->storage->txn_rollback; |
497 |
$schema->storage->txn_rollback; |
| 508 |
}; |
498 |
}; |
| 509 |
- |
|
|