|
Lines 20-25
use Modern::Perl;
Link Here
|
| 20 |
use Koha::Acquisition::Orders; |
20 |
use Koha::Acquisition::Orders; |
| 21 |
use Koha::Cities; |
21 |
use Koha::Cities; |
| 22 |
use Koha::Holds; |
22 |
use Koha::Holds; |
|
|
23 |
use Koha::Biblios; |
| 23 |
|
24 |
|
| 24 |
# Dummy app for testing the plugin |
25 |
# Dummy app for testing the plugin |
| 25 |
use Mojolicious::Lite; |
26 |
use Mojolicious::Lite; |
|
Lines 55-62
get '/patrons/:patron_id/holds' => sub {
Link Here
|
| 55 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
56 |
$c->render( status => 200, json => {count => scalar(@$holds)} ); |
| 56 |
}; |
57 |
}; |
| 57 |
|
58 |
|
|
|
59 |
get '/biblios' => sub { |
| 60 |
my $c = shift; |
| 61 |
my $output = $c->req->params->to_hash; |
| 62 |
$output->{query} = $c->req->json if defined $c->req->json; |
| 63 |
my $headers = $c->req->headers->to_hash; |
| 64 |
$output->{'x-koha-query'} = $headers->{'x-koha-query'} if defined $headers->{'x-koha-query'}; |
| 65 |
$c->validation->output($output); |
| 66 |
my $biblios_set = Koha::Biblios->new; |
| 67 |
$c->stash("koha.embed", { |
| 68 |
"suggestions" => { |
| 69 |
children => { |
| 70 |
"suggester" => {} |
| 71 |
} |
| 72 |
} |
| 73 |
}); |
| 74 |
my $biblios = $c->objects->search($biblios_set); |
| 75 |
|
| 76 |
$c->render( status => 200, json => {count => scalar(@$biblios)} ); |
| 77 |
}; |
| 78 |
|
| 58 |
# The tests |
79 |
# The tests |
| 59 |
use Test::More tests => 4; |
80 |
use Test::More tests => 8; |
| 60 |
use Test::Mojo; |
81 |
use Test::Mojo; |
| 61 |
|
82 |
|
| 62 |
use t::lib::TestBuilder; |
83 |
use t::lib::TestBuilder; |
|
Lines 231-233
subtest 'objects.search helper, with path parameters and _match' => sub {
Link Here
|
| 231 |
|
252 |
|
| 232 |
$schema->storage->txn_rollback; |
253 |
$schema->storage->txn_rollback; |
| 233 |
}; |
254 |
}; |
| 234 |
- |
255 |
|
|
|
256 |
subtest 'object.search helper with query parameter' => sub { |
| 257 |
plan tests => 4; |
| 258 |
|
| 259 |
$schema->storage->txn_begin; |
| 260 |
|
| 261 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 262 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 263 |
my $biblio1 = $builder->build_sample_biblio; |
| 264 |
my $biblio2 = $builder->build_sample_biblio; |
| 265 |
my $biblio3 = $builder->build_sample_biblio; |
| 266 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
| 267 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
| 268 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
| 269 |
|
| 270 |
$t->get_ok('/biblios' => json => {"suggestions.suggester.patron_id" => $patron1->borrowernumber }) |
| 271 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
| 272 |
|
| 273 |
$t->get_ok('/biblios' => json => {"suggestions.suggester.patron_id" => $patron2->borrowernumber }) |
| 274 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
| 275 |
|
| 276 |
$schema->storage->txn_rollback; |
| 277 |
}; |
| 278 |
|
| 279 |
subtest 'object.search helper with q parameter' => sub { |
| 280 |
plan tests => 4; |
| 281 |
|
| 282 |
$schema->storage->txn_begin; |
| 283 |
|
| 284 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 285 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 286 |
my $biblio1 = $builder->build_sample_biblio; |
| 287 |
my $biblio2 = $builder->build_sample_biblio; |
| 288 |
my $biblio3 = $builder->build_sample_biblio; |
| 289 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
| 290 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
| 291 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
| 292 |
|
| 293 |
$t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}') |
| 294 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
| 295 |
|
| 296 |
$t->get_ok('/biblios?q={"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}') |
| 297 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
| 298 |
|
| 299 |
$schema->storage->txn_rollback; |
| 300 |
}; |
| 301 |
|
| 302 |
subtest 'object.search helper with x-koha-query header' => sub { |
| 303 |
plan tests => 4; |
| 304 |
|
| 305 |
$schema->storage->txn_begin; |
| 306 |
|
| 307 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 308 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" } ); |
| 309 |
my $biblio1 = $builder->build_sample_biblio; |
| 310 |
my $biblio2 = $builder->build_sample_biblio; |
| 311 |
my $biblio3 = $builder->build_sample_biblio; |
| 312 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
| 313 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
| 314 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
| 315 |
|
| 316 |
$t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron1->borrowernumber.'"}'}) |
| 317 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
| 318 |
|
| 319 |
$t->get_ok('/biblios' => {'x-koha-query' => '{"suggestions.suggester.patron_id": "'.$patron2->borrowernumber.'"}'}) |
| 320 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
| 321 |
|
| 322 |
$schema->storage->txn_rollback; |
| 323 |
}; |
| 324 |
|
| 325 |
subtest 'object.search helper with all query methods' => sub { |
| 326 |
plan tests => 6; |
| 327 |
|
| 328 |
$schema->storage->txn_begin; |
| 329 |
|
| 330 |
my $patron1 = $builder->build_object( { class => "Koha::Patrons" , value => {cardnumber => 'cardpatron1', firstname=>'patron1'} } ); |
| 331 |
my $patron2 = $builder->build_object( { class => "Koha::Patrons" , value => {cardnumber => 'cardpatron2', firstname=>'patron2'} } ); |
| 332 |
my $biblio1 = $builder->build_sample_biblio; |
| 333 |
my $biblio2 = $builder->build_sample_biblio; |
| 334 |
my $biblio3 = $builder->build_sample_biblio; |
| 335 |
my $suggestion1 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron1->borrowernumber, biblionumber => $biblio1->biblionumber} } ); |
| 336 |
my $suggestion2 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio2->biblionumber} } ); |
| 337 |
my $suggestion3 = $builder->build_object( { class => "Koha::Suggestions", value => { suggestedby => $patron2->borrowernumber, biblionumber => $biblio3->biblionumber} } ); |
| 338 |
|
| 339 |
$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}) |
| 340 |
->json_is('/count' => 1, 'there should be 1 biblio with suggestions of patron 1'); |
| 341 |
|
| 342 |
$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}) |
| 343 |
->json_is('/count' => 2, 'there should be 2 biblios with suggestions of patron 2'); |
| 344 |
|
| 345 |
$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}) |
| 346 |
->json_is('/count' => 0, 'there shouldn\'t be biblios where suggester has patron1 fistname and patron2 id'); |
| 347 |
|
| 348 |
$schema->storage->txn_rollback; |
| 349 |
}; |